TextAttack
CLAUDE.md3.5k starsChanged 6 years agoMITView on GitHub
TextAttack (v0.3.10) is a Python framework for adversarial attacks, data augmentation, and model training in NLP. It provides a modular system where attacks are composed of four pluggable components: goal functions, constraints, transformations, and search methods. The project is maintained by UVA QData Lab. An Attack is composed of exactly four components: 1. GoalFunction (textattack/goal_functions/) - Determines if an attack succeeded. Categories: classification/ (untargeted, targeted), text/ (BLEU, translation overlap), custom/. 2. Constraints (textattack/constraints/) - Filter invalid perturbations. Categories: semantics/ (sentence…
- Installs packages
Files
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
TextAttack (v0.3.10) is a Python framework for adversarial attacks, data augmentation, and model training in NLP. It provides a modular system where attacks are composed of four pluggable components: goal functions, constraints, transformations, and search methods. The project is maintained by UVA QData Lab.
Common Commands
Installation (dev mode)
pip install -e .[dev]Testing
make test # Run full test suite (pytest --dist=loadfile -n auto)
pytest tests -v # Verbose test run
pytest tests/test_augment_api.py # Run a single test file
pytest --lf # Re-run only last failed testsFormatting & Linting
make format # Auto-format with black, isort, docformatter
make lint # Check formatting (black --check, isort --check-only, flake8)Building Docs
make docs # Build HTML docs with Sphinx
make docs-auto # Hot-reload docs server on port 8765CLI Usage
textattack attack --recipe textfooler --model bert-base-uncased-mr --num-examples 100
textattack augment --input-csv examples.csv --output-csv output.csv --input-column text --recipe embedding
textattack train --model-name-or-path lstm --dataset yelp_polarity --epochs 50
textattack list attack-recipes
textattack peek-dataset --dataset-from-huggingface snliArchitecture
Core Attack Pipeline (textattack/attack.py, textattack/attacker.py)
An Attack is composed of exactly four components:
- GoalFunction (
textattack/goal_functions/) - Determines if an attack succeeded. Categories:classification/(untargeted, targeted),text/(BLEU, translation overlap),custom/. - Constraints (
textattack/constraints/) - Filter invalid perturbations. Categories:semantics/(sentence encoders, word embeddings),grammaticality/(POS, language models, grammar tools),overlap/(edit distance, BLEU),pre_transformation/(restrict search space before transforming). - Transformation (
textattack/transformations/) - Generate candidate perturbations. Types:word_swaps/(embedding, gradient, homoglyph, WordNet),word_insertions/,word_merges/,sentence_transformations/,WordDeletion,CompositeTransformation. - SearchMethod (
textattack/search_methods/) - Traverse the perturbation space. Includes:BeamSearch,GreedySearch,GreedyWordSwapWIR,GeneticAlgorithm,ParticleSwarmOptimization,DifferentialEvolution.
The Attacker class orchestrates running attacks on datasets with parallel processing, checkpointing, and logging.
Attack Recipes (textattack/attack_recipes/)
Pre-built attack configurations from the literature (e.g., TextFooler, DeepWordBug, BAE, BERT-Attack, CLARE, CheckList, etc.). Each recipe subclasses AttackRecipe and implements a build(model_wrapper) classmethod that returns a configured Attack object. Includes multi-lingual recipes for French, Spanish, and Chinese.
Key Abstractions
AttackedText(textattack/shared/attacked_text.py) - Central text representation that maintains both token list and original text with punctuation. Used throughout the pipeline instead of raw strings.ModelWrapper(textattack/models/wrappers/) - Abstract interface for models. Implementations for PyTorch, HuggingFace, TensorFlow, sklearn. Models must accept string input and return predictions.Dataset(textattack/datasets/) - Iterable of(input, output)pairs. Supports HuggingFace datasets and custom files.Augmenter(textattack/augmentation/) - Uses transformations and constraints for data augmentation (not adversarial attacks). Built-in recipes: wordnet, embedding, charswap, eda, checklist, clare, back_trans.PromptAugmentationPipeline(textattack/prompt_augmentation/) - Augments prompts and generates LLM responses.- LLM Wrappers (
textattack/llms/) - Wrappers for using LLMs (HuggingFace, ChatGPT) with prompt augmentation.
CLI Commands (textattack/commands/)
Entry point: textattack/commands/textattack_cli.py. Each command (attack, augment, train, eval-model, list, peek-dataset, benchmark-recipe, attack-resume) is a subclass of TextAttackCommand with register_subcommand() and run() methods.
Configuration
- Version tracked in
docs/conf.py(imported bysetup.py) - Cache directory:
~/.cache/textattack/(override withTA_CACHE_DIRenv var) - Formatting: black (line length 88), isort (skip
__init__.py), flake8 (ignores: E203, E266, E501, W503, D203)
CI Workflows (.github/workflows/)
check-formatting.yml- Runsmake linton Python 3.9run-pytest.yml- Sets up Python 3.8/3.9 (pytest currently skipped in CI)publish-to-pypi.yml- PyPI publishingmake-docs.yml- Documentation buildcodeql-analysis.yml- Security analysis
Test Structure
Tests are in tests/ organized by feature:
test_command_line/- CLI command integration tests (attack, augment, train, eval, list, loggers)test_constraints/- Constraint unit teststest_augment_api.py,test_transformations.py,test_attacked_text.py,test_tokenizers.py,test_word_embedding.py,test_metric_api.py,test_prompt_augmentation.pytest_command_line/update_test_outputs.py- Script to regenerate expected test outputs
Adding New Components
- Attack recipe: Subclass
AttackRecipeintextattack/attack_recipes/, implementbuild(model_wrapper), add import to__init__.py, add doc reference indocs/attack_recipes.rst. - Transformation: Subclass
Transformationin appropriate subfolder undertextattack/transformations/. - Constraint: Subclass
ConstraintorPreTransformationConstraintin appropriate subfolder undertextattack/constraints/. - Search method: Subclass
SearchMethodintextattack/search_methods/.
Trending
Quiet since August.about the whole repository
Who's talking about QData/TextAttack
- bigscience-workshop/promptsource“[Epic] Data Augmentation Issue Overview and Discussions”GitHub · Jun 3, 2021 · 1 reactions
- llnl/mada-tools“Benchmarking Tests: Data Augmentation for Sentences”GitHub · Aug 5, 2026
- Adit-Jain-srm/NightmareNet“[Research]: Integrate TextFooler + BertAttack evaluation via TextAttack”GitHub · Jul 9, 2026
- PyTorchKR/landscape“[Add] TextAttack (QData/TextAttack)”GitHub · Jun 2, 2026
- NVIDIA/garak“probe: textattack”GitHub · Mar 12, 2024
The biggest 5 of 18 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 18
Talked about on GitHub (18 times).
On GitHub · 18
- Jun 3, 2021[Epic] Data Augmentation Issue Overview and Discussions — bigscience-workshop/promptsource1 reaction · 2 comments
- Aug 5, 2026Benchmarking Tests: Data Augmentation for Sentences — llnl/mada-toolssays it tested it0 reactions
- Jul 9, 2026[Research]: Integrate TextFooler + BertAttack evaluation via TextAttack — Adit-Jain-srm/NightmareNet0 reactions · 3 comments
- Jun 2, 2026[Add] TextAttack (QData/TextAttack) — PyTorchKR/landscape0 reactions
- Mar 12, 2024probe: textattack — NVIDIA/garak0 reactions · 1 comment
13 more on GitHub
- Jan 30, 2024Fix colab badges — theochem/grid0 reactions · 1 comment
- Jan 18, 2023How to properly cite armory? — twosixlabs/armory0 reactions · 4 comments
- Jan 12, 2023create tutorial about `TextAttack` for explainability — argilla-io/argilla0 reactions · 1 comment
- Aug 18, 2022Fix "Open in Colab" button in notebooks — intel/ipex-llm0 reactions
- Oct 17, 2021Implement the PWWS Attack — Adversarial-Deep-Learning/code-soup0 reactions
- Oct 16, 2021Wrapper for PyTorch models — Adversarial-Deep-Learning/code-soup0 reactions
- Oct 16, 2021Wrapper for Hugging Face models — Adversarial-Deep-Learning/code-soup0 reactions
- Aug 3, 2021implement data augmentation option — br-pki/detectLanguage0 reactions
- Jul 14, 2021TextAttack load fails on Windows — Azure/counterfit0 reactions · 1 comment
- May 18, 2021I think the issue has been fixed so I'll close this issue! — QData/deep2Read0 reactions · 1 comment
- Oct 1, 2020Link Checker Report — JackMcKew/awesome-python-bytes0 reactions
- Aug 1, 2020Link Checker Report — JackMcKew/awesome-python-bytes0 reactions
- May 13, 2020TextAttack: A Framework for Adversarial Attacks in Natural Language Processing — upura/papers0 reactions
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

