Package: augmentex
Augmentex — a library for augmenting texts with errorsAugmentex introduces rule-based and common statistic (empowered byKartaSlovproject)
approach to insert errors in text. It is fully described again in thePaperand in this 🗣️Talk.ContentsAugmentex — a library for augmenting texts with errorsContentsInstallationImplemented functionalityUsageWord levelCharacter levelBatch processingCompute your own statisticsGoogle Colab exampleContributingIssuePull requestReferencesAuthorsInstallationpip install augmentexImplemented functionalityWe collected statistics from different languages and from different input sources. This table shows what functionality the library currently supports.RussianEnglishPC keyboard✅✅Mobile kb✅❌In the future, it is planned to scale the functionality to new languages and various input sources.Usage🖇️ Augmentex allows you to operate on two levels of granularity when it comes to text corruption and offers you sets of
specific methods suited for particular level:Word level:replace- replace a random word with its incorrect counterpart;delete- delete random word;swap- swap two random words;stopword- add random words from stop-list;split- add spaces between letters to the word;reverse- change a case of the first letter of a random word;text2emoji- change the word to the corresponding emoji.Character level:shift- randomly swaps upper / lower case in a string;orfo- substitute correct characters with their common incorrect counterparts;typo- substitute correct characters as if they are mistyped on a keyboard;delete- delete random character;insert- insert random character;multiply- multiply random character;swap- swap two adjacent characters.Word levelfromaugmenteximportWordAugword_aug=WordAug(unit_prob=0.4,# Percentage of the phrase to which augmentations will be appliedmin_aug=1,# Minimum number of augmentationsmax_aug=5,# Maximum number of augmentationslang="eng",# supports: "rus", "eng"platform="pc",# supports: "pc", "mobile"random_seed=42,)Replace a random word with its incorrect counterpart;text="Screw you guys, I am going home. (c)"word_aug.augment(text=text,action="replace")# Screw to guys, I to going com. (c)Delete random word;text="Screw you guys, I am going home. (c)"word_aug.augment(text=text,action="delete")# you I am home. (c)Swap two random words;text="Screw you guys, I am going home. (c)"word_aug.augment(text=text,action="swap")# Screw I guys, am home. going you (c)Add random words from stop-list;text="Screw you guys, I am going home. (c)"word_aug.augment(text=text,action="stopword")# like Screw you guys, I am going completely home. by the way (c)Adds spaces between letters to the word;text="Screw you guys, I am going home. (c)"word_aug.augment(text=text,action="split")# Screw y o u guys, I am going h o m e . (c)Change a case of the first letter of a random word;text="Screw you guys, I am going home. (c)"word_aug.augment(text=text,action="reverse")# Screw You guys, i Am going home. (c)Changes the word to the corresponding emoji.text="Screw you guys, I am going home. (c)"word_aug.augment(text=text,action="text2emoji")# Screw you guys, I am going home. (c)Replaces ngram in a word with erroneous ones.text="Screw you guys, I am going home. (c)"word_aug.augment(text=text,action="ngram")# Scren you guys, I am going home. (c)Character levelfromaugmenteximportCharAugchar_aug=CharAug(unit_prob=0.3,# Percentage of the phrase to which augmentations will be appliedmin_aug=1,# Minimum number of augmentationsmax_aug=5,# Maximum number of augmentationsmult_num=3,# Maximum number of repetitions of characters (only for the multiply method)lang="eng",# supports: "rus", "eng"platform="pc",# supports: "pc", "mobile"random_seed=42,)Randomly swaps upper / lower case in a string;text="Screw you guys, I am going home. (c)"char_aug.augment(text=text,action="shift")# Screw YoU guys, I am going Home. (C)Substitute correct characters with their common incorrect counterparts;text="Screw you guys, I am going home. (c)"char_aug.augment(text=text,action="orfo")# Sedew you guya, I am going home. (c)Substitute correct characters as if they are mistyped on a keyboard;text="Screw you guys, I am going home. (c)"char_aug.augment(text=text,action="typo")# Sxrew you gugs, I am going home. (x)Delete random character;text="Screw you guys, I am going home. (c)"char_aug.augment(text=text,action="delete")# crew you guys Iam goinghme. (c)Insert random character;text="Screw you guys, I am going home. (c)"char_aug.augment(text=text,action="insert")# Screw you ughuys, I vam gcoing hxome. (c)Multiply random character;text="Screw you guys, I am going home. (c)"char_aug.augment(text=text,action="multiply")# Screw yyou guyss, I am ggoinng home. (c)Swap two adjacent characters.text="Screw you guys, I am going home. (c)"char_aug.augment(text=text,action="swap")# Srcewy ou guys,I  am oging hmoe. (c)Batch processing📁 For batch text processing, you need to call theaug_batchmethod instead of theaugmentmethod and pass a list of strings to it.fromaugmenteximportWordAugword_aug=WordAug(unit_prob=0.4,# Percentage of the phrase to which augmentations will be appliedmin_aug=1,# Minimum number of augmentationsmax_aug=5,# Maximum number of augmentationslang="eng",# supports: "rus", "eng"platform="pc",# supports: "pc", "mobile"random_seed=42,)text_list=["Screw you guys, I am going home. (c)"]*10word_aug.aug_batch(text_list,batch_prob=0.5)# without actiontext_list=["Screw you guys, I am going home. (c)"]*10word_aug.aug_batch(text_list,batch_prob=0.5,action="replace")# with actionCompute your own statistics📊 If you want to use your own statistics for thereplaceandorfomethods, then you will need to specify two paths to parallel corpora with texts without errors and with errors.Example of txt files:texts_without_errors.txttexts_with_errors.txtsome text without errors 1some text without errors 2some text without errors 3...some text with errors 1some text with errors 2some text with errors 3...fromaugmenteximportWordAugword_aug=WordAug(unit_prob=0.4,# Percentage of the phrase to which augmentations will be appliedmin_aug=1,# Minimum number of augmentationsmax_aug=5,# Maximum number of augmentationslang="eng",# supports: "rus", "eng"platform="pc",# supports: "pc", "mobile"random_seed=42,correct_texts_path="correct_texts.txt",error_texts_path="error_texts.txt",)Google Colab exampleYou can familiarize yourself with the usage in the exampleContributingIssueIf you see an open issue and are willing to do it, add yourself to the performers and write about how much time it will take to fix it. See the pull request module below.If you want to add something new or if you find a bug, you should start by creating a new issue and describing the problem/feature. Don't forget to include the appropriate labels.Pull requestHow to make a pull request.Clone the repository;Create a new branch, for examplegit checkout -b issue-id-short-name;Make changes to the code (make sure you are definitely working in the new branch);git push;Create a pull request to thedevelopbranch;Add a brief description of the work done;Expect comments from the authors.ReferencesSAGE— superlib, developed jointly with our friends by the AGI NLP team, which provides advanced spelling corruptions and spell checking techniques, including using Augmentex.AuthorsAleksandr Abramov— Source code and algorithm author;Mark Baushenko— Source code lead developer.