QData/TextAttack

TextAttack 🐙 is a Python framework for adversarial attacks, data augmentation, and model training in NLP https://textattack.readthedocs.io/en/master/

What it solves

TextAttack provides a framework to test the robustness of NLP models by generating adversarial examples—inputs specifically designed to trick a model into making a mistake. It also allows users to augment datasets to improve model generalization and train models to be more resilient to these attacks.

How it works

TextAttack uses a modular system comprising four main components to create adversarial examples:

  1. Goal Function: Defines what constitutes a successful attack (e.g., changing the model's prediction).
  2. Constraints: Ensure the adversarial example remains realistic or similar to the original text (e.g., limiting the number of words changed or maintaining part-of-speech consistency).
  3. Transformation: The method used to modify the text (e.g., swapping words with synonyms or using BERT for masked token prediction).
  4. Search Method: The strategy used to find the best modification (e.g., greedy search, beam search, or genetic algorithms).

Who it’s for

It is designed for NLP researchers and developers who want to understand their models' vulnerabilities, develop new adversarial attack methods, or increase the robustness of their datasets through augmentation.

Highlights

  • Attack Recipes: Includes a library of pre-implemented attacks from academic literature (e.g., TextFooler, DeepWordBug, and BERT-Attack).
  • Data Augmentation: Built-in tools to expand datasets using techniques like WordNet synonyms, back-translation, and character swaps.
  • Command-Line Interface: Allows users to run complex attacks or augmentations with simple commands without writing extensive code.
  • Broad Model Support: Compatible with various NLP models, including BERT, DistilBERT, and T5.

Related

  • Project
  • Project
  • Project
  • Project
  • Project