Skip to content

Commit 2ea2b64

Browse files
authored
Merge pull request #839 from qiyanjun/docs/content-accuracy-fixes
Fix outdated examples, broken links, and stale references across docs
2 parents 1050b1a + 00ef6c1 commit 2ea2b64

10 files changed

Lines changed: 115 additions & 20 deletions

docs/0_get_started/command_line_usage.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ Here are some models from transformers that have worked well for us:
102102
- `roberta-base`
103103
- `xlnet-base-cased`
104104

105-
## Evaluating Models with `textattack eval-model`
105+
## Evaluating Models with `textattack eval`
106106

107-
Any TextAttack-compatible model can be evaluated using `textattack eval-model`. TextAttack-trained models can be evaluated using `textattack eval --num-examples <num-examples> --model /path/to/trained/model/`
107+
Any TextAttack-compatible model can be evaluated using `textattack eval`. TextAttack-trained models can be evaluated using `textattack eval --num-examples <num-examples> --model /path/to/trained/model/`
108108

109109
## Other Commands
110110

docs/0_get_started/installation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Installation
22
==============
33

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

66
We recommend installing TextAttack in a virtual environment (check out this [guide](https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/)).
77

@@ -67,7 +67,7 @@ Besides, we highly recommend you to use virtual environment for textattack use,
6767
see [information here](https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#removing-an-environment). Here is one conda example:
6868

6969
```bash
70-
conda create -n textattackenv python=3.8
70+
conda create -n textattackenv python=3.9
7171
conda activate textattackenv
7272
conda env list
7373
```

docs/0_get_started/quick_api_tour.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ Let us attack a BERT model fine-tuned for sentimental classification task. We ar
1414
>>> tokenizer = transformers.AutoTokenizer.from_pretrained("textattack/bert-base-uncased-imdb")
1515
1616
17-
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.
17+
TextAttack requires both the model and the tokenizer to be wrapped by a :class:`~textattack.models.wrappers.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:`~textattack.models.wrappers.HuggingFaceModelWrapper` class which implements both the forward pass and tokenization.
1818

1919
.. code-block::
2020
2121
>>> import textattack
2222
>>> model_wrapper = textattack.models.wrappers.HuggingFaceModelWrapper(model, tokenizer)
2323
24-
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
24+
Next, let's build the attack that we want to use. TextAttack provides prebuilt attacks in the form of :class:`~textattack.attack_recipes.AttackRecipe`. For this example, we will use the TextFooler attack.
2525

2626

2727
.. code-block::

docs/1start/FAQ.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ The `attack_one` method in an `Attack` takes as input an `AttackedText`, and out
145145
We formulate an attack as consisting of four components: a **goal function** which determines if the attack has succeeded, **constraints** defining which perturbations are valid, a **transformation** that generates potential modifications given an input, and a **search method** which traverses through the search space of possible perturbations. The attack attempts to perturb an input text such that the model output fulfills the goal function (i.e., indicating whether the attack is successful) and the perturbation adheres to the set of constraints (e.g., grammar constraint, semantic similarity constraint). A search method is used to find a sequence of transformations that produce a successful adversarial example.
146146

147147

148-
This modular design unifies adversarial attack methods into one system, enables us to easily assemble attacks from the literature while re-using components that are shared across attacks. We provides clean, readable implementations of 16 adversarial attack recipes from the literature (see [our tool paper](https://arxiv.org/abs/2005.05909) and [our benchmark search paper](https://arxiv.org/abs/2009.06368)). For the first time, these attacks can be benchmarked, compared, and analyzed in a standardized setting.
148+
This modular design unifies adversarial attack methods into one system, enables us to easily assemble attacks from the literature while re-using components that are shared across attacks. We provides clean, readable implementations of 24 adversarial attack recipes from the literature (see [our tool paper](https://arxiv.org/abs/2005.05909) and [our benchmark search paper](https://arxiv.org/abs/2009.06368)). For the first time, these attacks can be benchmarked, compared, and analyzed in a standardized setting.
149149

150150

151151

docs/1start/attacks4Components.md

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
To unify adversarial attack methods into one system, We formulate an attack as consisting of four components: a **goal function** which determines if the attack has succeeded, **constraints** defining which perturbations are valid, a **transformation** that generates potential modifications given an input, and a **search method** which traverses through the search space of possible perturbations. The attack attempts to perturb an input text such that the model output fulfills the goal function (i.e., indicating whether the attack is successful) and the perturbation adheres to the set of constraints (e.g., grammar constraint, semantic similarity constraint). A search method is used to find a sequence of transformations that produce a successful adversarial example.
44

5-
This modular design enables us to easily assemble attacks from the literature while re-using components that are shared across attacks. TextAttack provides clean, readable implementations of 16 adversarial attacks from the literature. For the first time, these attacks can be benchmarked, compared, and analyzed in a standardized setting.
5+
This modular design enables us to easily assemble attacks from the literature while re-using components that are shared across attacks. TextAttack provides clean, readable implementations of 24 adversarial attacks from the literature. For the first time, these attacks can be benchmarked, compared, and analyzed in a standardized setting.
66

77
- Two examples showing four components of two SOTA attacks
88
![two-categorized-attacks](/_static/imgs/intro/01-categorized-attacks.png)
@@ -44,7 +44,7 @@ A `SearchMethod` takes as input an initial `GoalFunctionResult` and returns a fi
4444

4545
### Four components in Attack Recipes we have implemented
4646

47-
- TextAttack provides clean, readable implementations of 16 adversarial attacks from the literature.
47+
- TextAttack provides clean, readable implementations of 24 adversarial attacks from the literature.
4848

4949
- To run an attack recipe: `textattack attack --recipe [recipe_name]`
5050

@@ -62,6 +62,14 @@ A `SearchMethod` takes as input an initial `GoalFunctionResult` and returns a fi
6262
<tbody>
6363
<tr><td style="text-align: center;" colspan="6"><strong><br>Attacks on classification tasks, like sentiment classification and entailment:<br></strong></td></tr>
6464

65+
<tr class="odd">
66+
<td style="text-align: left;"><code>a2t</code> <span class="citation" data-cites="yoo2021a2t"></span></td>
67+
<td style="text-align: left;"><sub>Untargeted Classification</sub></td>
68+
<td style="text-align: left;"><sub>Part-of-speech match, Max modification rate, SBERT sentence encoding cosine similarity, Word embedding distance</sub></td>
69+
<td style="text-align: left;"><sub>Counter-fitted word embedding swap (or BERT Masked Token Prediction, in the `mlm` variant)</sub></td>
70+
<td style="text-align: left;"><sub>Greedy-WIR (gradient)</sub></td>
71+
<td ><sub>Attack tuned for use in adversarial training, from (["Towards Improving Adversarial Training of NLP Models" (Yoo et al., 2021)](https://arxiv.org/abs/2109.00544))</sub></td>
72+
</tr>
6573
<tr class="even">
6674
<td style="text-align: left;"><code>alzantot</code> <span class="citation" data-cites="Alzantot2018GeneratingNL Jia2019CertifiedRT"></span></td>
6775
<td style="text-align: left;"><sub>Untargeted {Classification, Entailment}</sub></td>
@@ -142,6 +150,14 @@ A `SearchMethod` takes as input an initial `GoalFunctionResult` and returns a fi
142150
<td style="text-align: left;"><sub>Greedy-WIR</sub></td>
143151
<td ><sub>Greedy attack with word importance ranking , Reducing the input while maintaining the prediction through word importance ranking (["Pathologies of Neural Models Make Interpretation Difficult" (Feng et al., 2018)](https://arxiv.org/pdf/1804.07781.pdf))</sub></td>
144152
</tr>
153+
<tr class="even">
154+
<td style="text-align: left;"><code>leap</code> <span class="citation" data-cites="ma2023leap"></span></td>
155+
<td style="text-align: left;"><sub>Untargeted Classification</sub></td>
156+
<td style="text-align: left;"><sub>Max modification rate, Stopword modification</sub></td>
157+
<td style="text-align: left;"><sub>WordNet-based synonym swap</sub></td>
158+
<td style="text-align: left;"><sub>Particle Swarm Optimization (Levy-flight/adaptive-inertia variant)</sub></td>
159+
<td ><sub>Levy-flight/adaptive-inertia variant of the `pso` search method, from (["LEAP: Efficient and Automated Test Method for NLP Software" (Ma et al., 2023)](https://arxiv.org/abs/2308.11284))</sub></td>
160+
</tr>
145161
<tr class="odd">
146162
<td style="text-align: left;"><code>kuleshov</code> <span class="citation" data-cites="Kuleshov2018AdversarialEF"></span></td>
147163
<td style="text-align: left;"><sub>Untargeted Classification</sub></td>
@@ -213,6 +229,7 @@ A `SearchMethod` takes as input an initial `GoalFunctionResult` and returns a fi
213229
</tr>
214230

215231
<tr><td style="text-align: center;" colspan="6"><strong><br>General: <br></strong></td></tr>
232+
<tr><td style="text-align: left;" colspan="6"><sub>Every other recipe here is locked to one task and one goal function, which is why the table splits into "classification" vs. "sequence-to-sequence" sections. <code>bad-characters</code> is different: its <code>build()</code> takes a <code>goal_function_type</code> argument and can be configured to attack classification models, NER models, or seq2seq/translation models. Since it spans both task types (and NER, which is neither), it doesn't fit either section above, so it's listed here under "General" instead.</sub></td></tr>
216233

217234
<tr class="odd">
218235
<td style="text-align: left;"><code>bad-characters</code> <span class="citation" data-cites=""></span></td>
@@ -223,6 +240,33 @@ A `SearchMethod` takes as input an initial `GoalFunctionResult` and returns a fi
223240
<td><sub>Uses imperceptible character-level perturbations including homoglyph substitutions, Unicode reordering, deletions, and invisibles. Based on (["Bad Characters: Imperceptible NLP Attacks" (Boucher et al., 2021)](https://arxiv.org/abs/2106.09898)).</sub></td>
224241
</tr>
225242

243+
<tr><td style="text-align: center;" colspan="6"><strong><br>Multi-lingual attacks on non-English classification models (Python API only, no CLI recipe name -- see <a href="https://github.com/QData/TextAttack/issues/423">#423</a>):<br></strong></td></tr>
244+
245+
<tr class="even">
246+
<td style="text-align: left;"><code>FrenchRecipe</code></td>
247+
<td style="text-align: left;"><sub>Untargeted Classification</sub></td>
248+
<td style="text-align: left;"><sub>Repeat modification, Stopword modification (French)</sub></td>
249+
<td style="text-align: left;"><sub>WordNet synonym swap, location swap, name swap (French)</sub></td>
250+
<td style="text-align: left;"><sub>Greedy-WIR</sub></td>
251+
<td ><sub>Contextualized-perturbation attack adapted for French NLP models.</sub></td>
252+
</tr>
253+
<tr class="odd">
254+
<td style="text-align: left;"><code>SpanishRecipe</code></td>
255+
<td style="text-align: left;"><sub>Untargeted Classification</sub></td>
256+
<td style="text-align: left;"><sub>Repeat modification, Stopword modification (Spanish)</sub></td>
257+
<td style="text-align: left;"><sub>WordNet synonym swap, location swap, name swap (Spanish)</sub></td>
258+
<td style="text-align: left;"><sub>Greedy-WIR</sub></td>
259+
<td ><sub>Contextualized-perturbation attack adapted for Spanish NLP models.</sub></td>
260+
</tr>
261+
<tr class="even">
262+
<td style="text-align: left;"><code>ChineseRecipe</code></td>
263+
<td style="text-align: left;"><sub>Untargeted Classification</sub></td>
264+
<td style="text-align: left;"><sub>Repeat modification, Stopword modification (Chinese)</sub></td>
265+
<td style="text-align: left;"><sub>HowNet word swap, Masked-LM word swap, Morphonym &amp; Homophone character swap</sub></td>
266+
<td style="text-align: left;"><sub>Greedy-WIR (weighted-saliency)</sub></td>
267+
<td ><sub>Contextualized-perturbation attack adapted for Chinese NLP models.</sub></td>
268+
</tr>
269+
226270
</tbody>
227271
</font>
228272
</table>

docs/1start/support.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ Follow these steps to start contributing:
189189
documentation for a new code file should just be two lines. Our docs will
190190
automatically generate from the comments you added to your code. If you're
191191
adding an attack recipe, add a reference in `attack_recipes.rst`.
192-
If you're adding a transformation, add a reference in `transformation.rst`, etc.
192+
If you're adding a transformation, add a reference in `docs/api/transformations.rst`, etc.
193193

194194
You can build the docs and view the updates using `make docs`. If you're
195195
adding a tutorial or something where you want to update the docs multiple

docs/1start/what_is_an_adversarial_attack.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Naturally, many have wondered about what adversarial examples for NLP models mig
5353

5454
![Two definitions of NLP adversarial examples](/_static/imgs/intro/mr_aes.png)
5555

56-
*Two different ideas of adversarial examples in NLP. These results were generated using TextAttack on an LSTM trained on the Rotten Tomatoes Movie Review sentiment classification dataset. These are *real* adversarial examples, generated using the DeepWordBug and TextFooler attacks. To generate them yourself, after installing TextAttack, run ‘textattack attack model lstm-mr num-examples 1 recipe RECIPE num-examples-offset 19’ where RECIPE is ‘deepwordbug’ or ‘textfooler’.*
56+
*Two different ideas of adversarial examples in NLP. These results were generated using TextAttack on an LSTM trained on the Rotten Tomatoes Movie Review sentiment classification dataset. These are *real* adversarial examples, generated using the DeepWordBug and TextFooler attacks. To generate them yourself, after installing TextAttack, run ‘textattack attack --model lstm-mr --num-examples 1 --recipe RECIPE --num-examples-offset 19’ where RECIPE is ‘deepwordbug’ or ‘textfooler’.*
5757

5858
Because two text sequences are never indistinguishable, researchers have proposed various alternative definitions for adversarial examples in NLP. We find it useful to group adversarial attacks based on their chosen definitions of adversarial examples.
5959

docs/3recipes/attack_recipes.rst

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ Attacks on classification models
149149
Attacks on sequence-to-sequence models
150150
############################################
151151

152-
17. MORPHEUS (It’s Morphin’ Time! Combating Linguistic Discrimination with Inflectional Perturbations)
153-
18. Seq2Sick (Seq2Sick: Evaluating the Robustness of Sequence-to-Sequence Models with Adversarial Examples)
152+
18. MORPHEUS (It’s Morphin’ Time! Combating Linguistic Discrimination with Inflectional Perturbations)
153+
19. Seq2Sick (Seq2Sick: Evaluating the Robustness of Sequence-to-Sequence Models with Adversarial Examples)
154154

155155

156156
.. automodule:: textattack.attack_recipes.morpheus_tan_2020
@@ -166,7 +166,14 @@ Attacks on sequence-to-sequence models
166166
General
167167
############################################
168168

169-
19. BadCharacters (Bad Characters: Imperceptible NLP Attacks)
169+
Unlike the recipes above, which are each locked to one task and one goal
170+
function, ``BadCharacters2021`` takes a ``goal_function_type`` argument and
171+
can be configured to attack classification models, NER models, or
172+
seq2seq/translation models. Since it spans both of the sections above (and
173+
NER, which is neither), it's listed here instead of being duplicated or
174+
assigned to one arbitrarily.
175+
176+
20. BadCharacters (Bad Characters: Imperceptible NLP Attacks)
170177

171178

172179
.. automodule:: textattack.attack_recipes.bad_characters_2021
@@ -181,9 +188,9 @@ TextAttack also includes recipes for non-English classification models, each a
181188
language-specific adaptation of a contextualized-perturbation attack (see
182189
https://github.com/QData/TextAttack/issues/423):
183190

184-
20. FrenchRecipe -- Attack French Recipe (Contextualized Perturbation for French NLP Adversarial Attack)
185-
21. SpanishRecipe -- Attack Spanish Recipe (Contextualized Perturbation for Spanish NLP Adversarial Attack)
186-
22. ChineseRecipe -- Attack Chinese Recipe (Contextualized Perturbation for Chinese NLP Adversarial Attack)
191+
21. FrenchRecipe -- Attack French Recipe (Contextualized Perturbation for French NLP Adversarial Attack)
192+
22. SpanishRecipe -- Attack Spanish Recipe (Contextualized Perturbation for Spanish NLP Adversarial Attack)
193+
23. ChineseRecipe -- Attack Chinese Recipe (Contextualized Perturbation for Chinese NLP Adversarial Attack)
187194

188195

189196
.. automodule:: textattack.attack_recipes.french_recipe

0 commit comments

Comments
 (0)