Installation

To use TextAttack, you must be running Python 3.6 or above. A CUDA-compatible GPU is optional but will greatly improve speed.

We recommend installing TextAttack in a virtual environment (check out this guide).

There are two ways to install TextAttack. If you want to simply use as it is, install via pip. If you want to make any changes and play around, install it from source.

Install with pip

Simply run

pip install textattack 

Install from Source

To install TextAttack from source, first clone the repo by running

git clone https://github.com/QData/TextAttack.git
cd TextAttack

Then, install it using pip.

pip install -e . 

To install TextAttack for further development, please run this instead.

pip install -e .[dev]

This installs additional dependencies required for development.

Optional Dependencies

For quick installation, TextAttack only installs esssential packages as dependencies (e.g. Transformers, PyTorch). However, you might need to install additional packages to run certain attacks or features. For example, Tensorflow and Tensorflow Hub are required to use the TextFooler attack, which was proposed in Is BERT Really Robust? A Strong Baseline for Natural Language Attack on Text Classification and Entailment by Di Jin, Zhijing Jin, Joey Tianyi Zhou, and Peter Szolov.

If you attempting to use a feature that requires additional dependencies, TextAttack will let you know which ones you need to install.

However, during installation step, you can also install them together with TextAttack. You can install Tensorflow and its related packages by running

pip install textattack[tensorflow]

You can also install other miscallenous optional dependencies by running

pip install textattack[optional]

To install both groups of packages, run

pip install textattack[tensorflow, optional]