-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #428 from QData/api-rework
API Rework
- Loading branch information
Showing
184 changed files
with
25,041 additions
and
11,874 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,9 @@ dist/ | |
# Weights & Biases outputs | ||
wandb/ | ||
|
||
# Tensorboard logs | ||
runs/ | ||
|
||
# checkpoints | ||
checkpoints/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
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](https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/)). | ||
|
||
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](https://arxiv.org/abs/1907.11932) 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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
Quick Tour | ||
========================== | ||
|
||
Let us have a quick look at how TextAttack can be used to carry out adversarial attack. | ||
|
||
Attacking a BERT model | ||
------------------------------ | ||
Let us attack a BERT model fine-tuned for sentimental classification task. We are going to use a model that has already been fine-tuned on IMDB dataset using the Transformers library. | ||
|
||
.. code-block:: | ||
>>> import transformers | ||
>>> model = transformers.AutoModelForSequenceClassification.from_pretrained("textattack/bert-base-uncased-imdb") | ||
>>> tokenizer = transformers.AutoTokenizer.from_pretrained("textattack/bert-base-uncased-imdb") | ||
TextAttack requires both the model and the tokenizer to be wrapped by a :class:`~transformers.models.wrapper.ModelWrapper` class that implements the forward pass operation given a list of input texts. For models provided by Transformers library, we can also simply use :class:`~transformers.models.wrapper.HuggingFaceModelWrapper` class which implements both the forward pass and tokenization. | ||
|
||
.. code-block:: | ||
>>> import textattack | ||
>>> model_wrapper = textattack.models.wrappers.HuggingFaceModelWrapper(model, tokenizer) | ||
Next, let's build the attack that we want to use. TextAttack provides prebuilt attacks in the form of :class:`~transformers.attack_recipes.AttackRecipe`. For this example, we will use :ref:TextFooler attack | ||
|
||
Let us also load the IMDB dataset using 🤗 Datasets library. TextAttack also requires that the dataset | ||
|
||
.. code-block:: | ||
>>> import datasets | ||
>>> dataset = datasets.load_dataset("imdb", split="test") | ||
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.