PromptCraft: A Prompt Perturbation Toolkit for Prompt Robustness Analysis
Project description
PromptCraft
A Prompt Perturbation Toolkit for Prompt Robustness Analysis
Table of Contents
- Installation
- Character Editing
- Word Manipulation
- Sentence Paraphrasing
- Structure of the code
- Acknowledgement
Installation
pip install promptcraft
Character Editing
from promptcraft import CharacterPerturb
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 = 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 WordPerturb
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 = 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 SentencePerturb
sentence = "Natalia sold clips to 48 of her friends in April, and then she sold half as many clips in May."
sentence_tool = SentencePerturb(sentence=sentence)
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
├── __init__.py
├── character.py
├── parrot.py
├── sentence.py
├── setup.py
├── styleformer.py
└── word.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
Release history Release notifications | RSS feed
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.1.2.tar.gz
(3.8 kB
view details)
Built Distribution
File details
Details for the file promptcraft-0.1.2.tar.gz
.
File metadata
- Download URL: promptcraft-0.1.2.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7fe6b64e709329a2090342a91a7c596236ec87c24b3fb73a2787c88a6199a8f4 |
|
MD5 | cb2e1db4a1d9306cacbb6ae2db3d8f5e |
|
BLAKE2b-256 | e1ebf5ce635a978a4ceeb8a5282f81985a8afe6f940c89dda4cd1093098c5867 |
File details
Details for the file promptcraft-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: promptcraft-0.1.2-py3-none-any.whl
- Upload date:
- Size: 3.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc5f4ce212299a9abcd80c143ab12a0c491dde299784c4a1401b22ddee3e069a |
|
MD5 | 9f52cf089b5f47cad096d0204297c41a |
|
BLAKE2b-256 | 1328f5561dc95df2136802bf54ec37fcc33cfbb55df00280c4f8373c0e3debd1 |