In machine learning, it is crucial to have a large amount of data in order to achieve strong model performance. Using a method known as data augmentation, you can create more data for your machine learning project. Data augmentation is a collection of techniques that manage the process of automatically generating high-quality data on top of existing data. In computer vision applications, augmenting approaches are extremely prevalent.If you are working on a computer vision project (e.g Image classification), for instance, you can apply dozens of techniques to each image: shift, modify color intensities, scale, rotate, crop, etc. If you have a tiny dataset for your ML project or wish to reduce overfitting in your machine learning models, it is recommended that you may apply data augmentation approaches. “We don’t have better algorithms. We just have more data.”- Peter Norvig In the field of Natural Language Processing (NLP),the tremendous level of complexity that language possesses, makes it difficult to augment text. The process of augmenting text data is more challenging and not as straightforward as some might expect. In this article, you will learn how to use a library called to improve data for natural language processing. TextAttack What is TextAttack? TextAttack is a Python framework that was built by the for the purpose of conducting adversarial attacks, adversarial training, and data augmentation in natural language processing. TextAttack has components that can be utilized independently for a variety of basic natural language processing tasks, including sentence encoding, grammar checking, and word substitution. QData team TextAttack excels in performing the following three functions: Adversarial attacks (Python: , Bash: ). textattack.Attack textattack attack Data augmentation (Python: , Bash: ). textattack.augmentation.Augmenter textattack augment Model training (Python: , Bash: ). textattack.Trainer textattack train For this article, we will focus on how to use TexAttack library for Data augmentation. Note: How to Install TexAttack To use this library make sure you have python 3.6 or above in your environment. Run the following command to install textAttack. pip install textattack Once you have installed TexAttack, you can run it via python module or via command-line. Note: Data Augmentation Techniques for Text Data TextAttack library has various augmentation techniques that you can use in your NLP project to add more text data.Here are some of the techniques that you can apply: It augments words by swapping characters out for other characters. 1.CharSwapAugmenter charswap_aug = CharSwapAugmenter() charswap_aug.augment(text) from textattack.augmentation import CharSwapAugmenter text = "I have enjoyed watching that movie, it was amazing." ['I have enjoyed watching that omvie, it was amazing.'] The Augmenter has swapped the word to . "movie" "omvie" It augments the text by deleting some parts of the text to make new text. 2.DeletionAugmenter deletion_aug = DeletionAugmenter() deletion_aug.augment(text) from textattack.augmentation import DeletionAugmenter text = "I have enjoyed watching that movie, it was amazing." ['I have watching that, it was amazing.'] This method has removed the word to create a new augmented text. "enjoyed" This augments the text with a combination of different methods, such as 3.EasyDataAugmenter Randomly swap the positions of the words in the sentence. Randomly remove words from the sentence. Randomly insert a random synonym of a random word at a random location. Randomly replace words with their synonyms. eda_aug = EasyDataAugmenter() eda_aug.augment(text) from textattack.augmentation import EasyDataAugmenter text = "I was billed twice for the service and this is the second time it has happened" ['I was billed twice for the service and this is the second time it has happen', 'I was billed twice for the one service and this is the second time it has happened', 'I billed twice for the service and this is the second time it has happened', 'I was billed twice for the this and service is the second time it has happened'] As you can see from the augmented texts, it show different results based on the methods applied.For example in the first augmented text, the last word has been modified from to . "happened" "happen" It can augment the text by replacing it with synonyms from the WordNet thesaurus. 4.WordNetAugmenter wordnet_aug = WordNetAugmenter() wordnet_aug.augment(text) from textattack.augmentation import WordNetAugmenter text = "I was billed twice for the service and this is the second time it has happened" ['I was billed twice for the service and this is the second time it has pass'] This method has changed the word to in order to create a new augmented text. "happened" "pass" Importing transformations and constraints from the and t allows you to build your own augmenter from the ground up. The following is an illustration of the use of the to produce augmentations of a string: 5.Create your Own Augmenter textattack.transformations extattack.constraints WordSwapRandomCharacterDeletion algorithm my_transformation = CompositeTransformation([WordSwapRandomCharacterDeletion()]) augmenter.augment(text) from textattack.transformations import WordSwapRandomCharacterDeletion from textattack.transformations import CompositeTransformation from textattack.augmentation import Augmenter augmenter = Augmenter(transformation=my_transformation, transformations_per_example= 3 ) text = 'Siri became confused when we reused to follow her directions.' ['Siri became cnfused when we reused to follow her directions.', 'Siri became confused when e reused to follow her directions.', 'Siri became confused when we reused to follow hr directions.'] The output show different augmented texts after implementing the method.For example, in the first augmented text, the method randomly removes a character in the word WordSwapRandomCharacterDeletion "o" "confused". Conclusion In this article, you have learned the significance of data augmentation for your Machine Learning project. In addition, you have learnt how to execute data augmentation for textual data using the TextAttack library. To the best of my knowledge, these techniques are the most effective approaches available to do the task for your NLP project.Hopefully, they'll be of use to you in your work. You can also try to use other available augmentation techniques from TextAttack library such as: EmbeddingAugmenter CheckListAugmenter CLAREAugmenter If you learned something new or enjoyed reading this article, please share it so that others can see it. Until then, see you in the next post! You can also find me on Twitter . @Davis_McDavid