TextAttack is a Python framework for adversarial attacks and data augmentation in NLP.

NLP Attacks

TextAttack provides a framework for constructing and thinking about attacks via perturbation in NLP. TextAttack builds attacks from four components:

  • Goal Functions stipulate the goal of the attack, like to change the prediction score of a classification model, or to change all of the words in a translation output.
  • Constraints determine if a potential perturbation is valid with respect to the original input.
  • Transformations take a text input and transform it by inserting and deleting characters, words, and/or phrases.
  • Search Methods explore the space of possible transformations within the defined constraints and attempt to find a successful perturbation which satisfies the goal function.

TextAttack provides a set of Attack Recipes that assemble attacks from the literature from these four components.

Data Augmentation

Data augmentation is easy and extremely common in computer vision but harder and less common in NLP. We provide a Data Augmentation module using transformations and constraints.


TextAttack has some other features that make it a pleasure to use: