Skip to main content

PromptCraft: A Prompt Perturbation Toolkit for Prompt Robustness Analysis

Project description

PromptCraft

A Prompt Perturbation Toolkit for Prompt Robustness Analysis

Code License License Python 3.9+

Table of Contents

Installation

pip install promptcraft

Character Editing

from promptcraft import character

sentence = "Natalia sold clips to 48 of her friends in April, and then she sold half as many clips in May."
level = 0.25  # Number of characters that will be edited

character_tool = character.CharacterPerturb(sentence=sentence, level=level)

Character Replacement

char_replace = character_tool.character_replacement()

Character Deletion

char_delete = character_tool.character_deletion()

Character Insertion

char_insert = character_tool.character_insertion()

Character Swap

char_swap = character_tool.character_swap()

Keyboard Typos

char_keyboard = character_tool.keyboard_typos()

Optical Character Recognition

char_ocr = character_tool.optical_character_recognition()

Word Manipulation

from promptcraft import word

sentence = "Natalia sold clips to 48 of her friends in April, and then she sold half as many clips in May."
level = 0.25  # Number of words that will be manipulated
word_tool = word.WordPerturb(sentence=sentence, level=level)

Synonym Replacement

word_synonym = word_tool.synonym_replacement()

Word Insertion

word_insert = word_tool.word_insertion()

Word Swap

word_swap = word_tool.word_swap()

Word Deletion

word_delete = word_tool.word_deletion()

Insert Punctuation

word_punctuation = word_tool.insert_punctuation()

Word Split

word_split = word_tool.word_split()

Sentence Paraphrasing

from promptcraft import sentence

sen = "Natalia sold clips to 48 of her friends in April, and then she sold half as many clips in May."
sentence_tool = sentence.SentencePerturb(sentence=sen)

Back Translation by Hugging Face

back_trans_hf = sentence_tool.back_translation_hugging_face()

Back Translation by Google Translator

back_trans_google = sentence_tool.back_translation_google()

Paraphrasing

sen_paraphrase = sentence_tool.paraphrase()

Formal Style

sen_formal = sentence_tool.formal()

Casual Style

sen_casual = sentence_tool.casual()

Passive Style

sen_passive = sentence_tool.passive()

Active Style

sen_active = sentence_tool.active()

Structure of the code

At the root of the project, you will see:

.
├── LICENSE
├── README.md
├── promptcraft
│   ├── __init__.py
│   ├── character.py
│   ├── parrot.py
│   ├── sentence.py
│   ├── styleformer.py
│   └── word.py
└── setup.py

Acknowledgement

This work was finished during my 2023 fall semester research rotation at the Dependable Computing Laboratory, Department of Electrical and Computer Engineering, Boston University, under the supervision of Prof. Wenchao Li.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

promptcraft-0.2.0.tar.gz (14.3 kB view details)

Uploaded Source

Built Distributions

promptcraft-0.2.0-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

promptcraft-0.2-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

Details for the file promptcraft-0.2.0.tar.gz.

File metadata

  • Download URL: promptcraft-0.2.0.tar.gz
  • Upload date:
  • Size: 14.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for promptcraft-0.2.0.tar.gz
Algorithm Hash digest
SHA256 7d806395fc9412d993880b5f6318d026342ceff057e9f043d6b82d022088a4fc
MD5 d605e9182ef0aa87971adabc9f231add
BLAKE2b-256 04604794f3def33b90735a38435a50d706bad8d85e9af096c5039e7a82575684

See more details on using hashes here.

File details

Details for the file promptcraft-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: promptcraft-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 14.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for promptcraft-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1f64677a33e84d0a92ea7f5b5c37cb911506b92e261aa18a3ec11a10290a4b06
MD5 6d5b4008297b978fe557bdc00ba6d643
BLAKE2b-256 808d723faa8d19f099327d9498d66f6702e9c6fdddfc3b8df37a320a0bf3d6ee

See more details on using hashes here.

File details

Details for the file promptcraft-0.2-py3-none-any.whl.

File metadata

  • Download URL: promptcraft-0.2-py3-none-any.whl
  • Upload date:
  • Size: 15.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for promptcraft-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 96c123a149d32bd93025a9093804592d02841dc0ea0f3d47584dc3de59ac345b
MD5 f10a12a4f2294d4263c1c6a6473dd372
BLAKE2b-256 581141687d9ccc2548068b9b40f2a6a71112ed3485b74542c55f72e7a472f0b7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page