Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
210 commits
Select commit Hold shift + click to select a range
b8d94ca
option to test on entire dataset
ArshdeepSekhon Oct 22, 2020
c863095
eval on entire dataset, checks
ArshdeepSekhon Oct 22, 2020
13bc18a
fix failed checks
ArshdeepSekhon Oct 22, 2020
8c726d1
Update 0_End_to_End.ipynb
tk-dev11 Oct 23, 2020
beac247
Merge pull request #314 from tahmid-kazi/patch-1
qiyanjun Oct 24, 2020
74bc5c0
add sphinx autodoc generated
qiyanjun Oct 24, 2020
0c95966
Update conf.py
qiyanjun Oct 24, 2020
dfe26b6
Update conf.py
qiyanjun Oct 24, 2020
e91a652
Two versions of API references now
qiyanjun Oct 24, 2020
d326796
Merge pull request #315 from QData/new_doc
qiyanjun Oct 24, 2020
688d997
Update conf.py
qiyanjun Oct 25, 2020
1e36c63
add in "sphinx.ext.autosummary"
qiyanjun Oct 25, 2020
821c350
move the mergign of api and source two version docs to branch new_doc
qiyanjun Oct 25, 2020
fc7d529
move documents from semi-automated rst files to correct code positions
qiyanjun Oct 25, 2020
2ea690b
a major shift to rst files generated by sphinx-apidoc
qiyanjun Oct 26, 2020
00c80ee
Update transformation.rst
qiyanjun Oct 26, 2020
95603fb
Merge branch 'master' into new_doc
qiyanjun Oct 26, 2020
23d0de6
clean up the docstring of each module and module content section
qiyanjun Oct 26, 2020
c41a13e
Update textattack.rst
qiyanjun Oct 26, 2020
c78aa66
fix all flake8 found whitespacing trailing issues
qiyanjun Oct 26, 2020
a4bd404
remove submodule lines from autodoc rsts
qiyanjun Oct 26, 2020
69a415f
correct two formatting with black
qiyanjun Oct 26, 2020
b998e0f
correct docstring style erors
qiyanjun Oct 26, 2020
887dca1
Update minimize_bleu.py
qiyanjun Oct 26, 2020
36dfce6
Merge pull request #316 from QData/new_doc
qiyanjun Oct 26, 2020
77ff8f3
Installation link fix
dheerajrav Oct 26, 2020
4c69e86
Merge pull request #317 from dheerajrav/patch-1
qiyanjun Oct 27, 2020
96a0360
remove the old API docs
qiyanjun Oct 29, 2020
6d83b2c
isort format of attack_camembert
qiyanjun Oct 29, 2020
230e39b
solve flake8 warning
qiyanjun Oct 29, 2020
f794639
Temporary Fix of Flair Testing Error
Hanyu-Liu-123 Oct 29, 2020
2509a14
Fix Format Error
Hanyu-Liu-123 Oct 29, 2020
58f522b
Update test_misc.py
Hanyu-Liu-123 Oct 29, 2020
af029bf
Specify torch version
Hanyu-Liu-123 Oct 29, 2020
41e7472
Merge pull request #322 from QData/new_docs
qiyanjun Oct 29, 2020
7dcf27d
add lazy loading
jinyongyoo Oct 28, 2020
8d64e89
formatting
jinyongyoo Oct 28, 2020
4478ad9
remove unncessary future statements
jinyongyoo Oct 29, 2020
3458a2b
rebase and formatting
jinyongyoo Oct 30, 2020
e6786b6
revert changes and fix circular imports
jinyongyoo Oct 30, 2020
7a89aba
make some dependencies optional
jinyongyoo Oct 30, 2020
dcce7b3
undo edits
jinyongyoo Oct 30, 2020
46ef3bc
fix github flow and import issues
jinyongyoo Oct 31, 2020
3c65e9d
remove 3.9 from testing
jinyongyoo Oct 31, 2020
4f16bb0
fix tqdm version conflict with datasets
jinyongyoo Oct 31, 2020
e2dd750
add install of stanza resource when package is present
jinyongyoo Oct 31, 2020
2149646
add embedding layer retrieval to models
jinyongyoo Oct 5, 2020
3ffd776
add get_grad method
jinyongyoo Oct 5, 2020
6273b19
make WordSwapGradientBased work with get_grad
jinyongyoo Oct 5, 2020
bdbeae8
add gradient-based white-box search
jinyongyoo Oct 5, 2020
79f3f4f
add new test for gradient-based greedy-word-wir
jinyongyoo Oct 5, 2020
4893d47
add consistent is_black_box attributes
jinyongyoo Oct 6, 2020
dcf408b
fix wrong test output
jinyongyoo Oct 17, 2020
84c1681
update gradient test to be device invariant
jinyongyoo Oct 17, 2020
866301b
fix bugs and revise word to token matching scheme
jinyongyoo Nov 1, 2020
8dad54a
fix test outputs and bugs
jinyongyoo Nov 1, 2020
a0e9479
WordSwapChangeName transformation now accounts
dheerajrav Nov 6, 2020
07abaf5
Merge pull request #319 from dheerajrav/word_swap_change_fix
jinyongyoo Nov 6, 2020
d9ae5f6
added table with attack recipes
tk-dev11 Nov 6, 2020
5325ef6
allow * and _ and @ in a word when tokenizing
tsinggggg Nov 6, 2020
e6f07eb
add comments
tsinggggg Nov 6, 2020
740c333
Merge pull request #327 from tsinggggg/allow-words-connected-by-addit…
jinyongyoo Nov 6, 2020
c04f8f4
Merge pull request #292 from QData/gradient-support
jxmorris12 Nov 6, 2020
6ccfaea
turn unknown goal function error into a logger warning
Nov 7, 2020
16c3b0d
update package versions
jinyongyoo Nov 8, 2020
acbc6c0
update compatibility check with current modules
jinyongyoo Nov 8, 2020
03e85b3
Merge pull request #330 from QData/update-package-version
jinyongyoo Nov 8, 2020
fb6088f
Merge pull request #329 from a1noack/new_goal_fcns
jxmorris12 Nov 9, 2020
16986b4
Merge pull request #326 from tahmid-kazi/patch-2
qiyanjun Nov 10, 2020
f950128
add a single doc page expaining our benchmarking results on search me…
qiyanjun Nov 10, 2020
de0b5b8
add in the docstring for textattack_cli main func
qiyanjun Nov 10, 2020
0f0649e
Merge pull request #331 from QData/new_docs
qiyanjun Nov 10, 2020
2328b7f
Merge branch 'master' into lazy-loading
jinyongyoo Nov 11, 2020
b148bd2
fix bugs
jinyongyoo Nov 11, 2020
ad68251
Merge pull request #323 from QData/lazy-loading
jinyongyoo Nov 11, 2020
f44947d
Update word_swap_embedding.py
qiyanjun Nov 11, 2020
2df8833
fix training code bug
jinyongyoo Nov 11, 2020
a9ab5d4
Merge pull request #332 from QData/fix-training-bug
jxmorris12 Nov 11, 2020
7caab13
support custom embeddings through gensim; incorporate WordEmbedding c…
tsinggggg Nov 12, 2020
170e45b
fix inflection generation and enlarge pos to upos mapping
Nov 12, 2020
e04c377
Fix for tut0
Oct 15, 2020
f0e27d1
Change model to Huggingface
Oct 25, 2020
3e9cbcb
Remove extras
Nov 12, 2020
be6cd88
remove duplicate keys from and fix formatting pos mapping dict
Nov 12, 2020
24669a9
fix formatting
a1noack Nov 12, 2020
b21bdc9
Remove model wrapping from pytorch wrapper module
Nov 12, 2020
305eb48
isort imports
a1noack Nov 12, 2020
6838209
run isort v5
a1noack Nov 12, 2020
4dc804a
Update requirements.txt
jinyongyoo Nov 13, 2020
e33bfc2
Merge pull request #334 from a1noack/fix_morpheus
jinyongyoo Nov 13, 2020
b0892ce
Remove model wrapping module
Nov 13, 2020
a03cbb1
Merge pull request #335 from QData/update-requirements.txt
jxmorris12 Nov 13, 2020
5f04781
Merge pull request #303 from sanchit97/tut0-fix
qiyanjun Nov 13, 2020
e583188
separate different types of word embeddings into differetn classes
jinyongyoo Nov 13, 2020
d810489
Fix ReadMe Minor Mistakes
Hanyu-Liu-123 Nov 13, 2020
155dd49
Merge pull request #336 from QData/Hanyu-Liu-123-patch-1
qiyanjun Nov 13, 2020
6bf376f
v0.2.12
jxmorris12 Nov 13, 2020
0401591
Update word_swap_embedding.py
qiyanjun Nov 11, 2020
a0193ba
Merge branch 'new_docs' of https://github.com/QData/TextAttack into n…
qiyanjun Nov 13, 2020
9bacdfc
add in overview diagram and models.md into doc
qiyanjun Nov 13, 2020
5c1579e
revise table of recipe-args in Readme.md
qiyanjun Nov 13, 2020
152a8d8
Update README.md
qiyanjun Nov 13, 2020
c0a60b3
share word embedding across components
jinyongyoo Nov 13, 2020
bbd5a7e
Update README.md
qiyanjun Nov 13, 2020
8bf85fd
Update README.md
qiyanjun Nov 13, 2020
aeacb55
combine with Sanchit's notebbook udpate
qiyanjun Nov 13, 2020
56d5bc5
add Glossary index
qiyanjun Nov 13, 2020
cff1d2d
Update README.md
qiyanjun Nov 14, 2020
18ecc5d
Update README.md
qiyanjun Nov 14, 2020
c8047d6
Update README.md
qiyanjun Nov 14, 2020
783213f
Update README.md
qiyanjun Nov 14, 2020
ea191ca
Update README.md
qiyanjun Nov 14, 2020
3abaae4
Update README.md
qiyanjun Nov 14, 2020
84ab6bc
Update README.md
qiyanjun Nov 14, 2020
c2924a4
disable parallel tests
jinyongyoo Nov 14, 2020
7a27040
Update README.md
qiyanjun Nov 14, 2020
e7484d7
Update README.md
qiyanjun Nov 14, 2020
9ee0ba1
Update README.md
qiyanjun Nov 14, 2020
0ee2f68
Update README.md
qiyanjun Nov 14, 2020
bb4539a
get rid of glossary index... not quite useful
qiyanjun Nov 14, 2020
48d89d6
Merge pull request #338 from QData/new_docs
qiyanjun Nov 14, 2020
0fad7f1
fix readthedocs module load
jinyongyoo Nov 14, 2020
a7ffdd2
local check pull 339, every doc builds well. besides add the attacks4…
qiyanjun Nov 14, 2020
5214d3b
Merge pull request #339 from QData/fix-google-dep
qiyanjun Nov 14, 2020
f1c3221
Update attacks4Components.md
qiyanjun Nov 14, 2020
b14f753
Merge pull request #340 from QData/fix-google-dep
qiyanjun Nov 14, 2020
7f2621b
move model-zoo.md into the index intro section
qiyanjun Nov 14, 2020
a1781a0
resolve the double indexing issues in the attack_recipes.rst
qiyanjun Nov 14, 2020
1295e8f
Correct URL issues in the Table of Four Components for 16 Attack Recipes
qiyanjun Nov 16, 2020
0adaa2b
add FAQ.md / fix docstring error / add links to two other textAttack …
qiyanjun Nov 17, 2020
b9e0c1d
Merge pull request #343 from QData/new_docs
qiyanjun Nov 17, 2020
04e98ba
update the textAttack paper abstract to the most-recent-version
qiyanjun Nov 17, 2020
c214210
Merge pull request #344 from QData/new_docs
qiyanjun Nov 17, 2020
1e65a93
correct the URL RST format used in references.md
qiyanjun Nov 17, 2020
c77f266
correct the URL RST format used in references.md
qiyanjun Nov 17, 2020
2215c56
Merge branch 'new_docs' of https://github.com/QData/TextAttack into n…
qiyanjun Nov 17, 2020
f375f87
Merge pull request #345 from QData/new_docs
qiyanjun Nov 17, 2020
061bbd9
add in the categorized-attacks.png and try to complete the documentation
qiyanjun Nov 17, 2020
d320b8d
Image Link errors (minor)
qiyanjun Nov 17, 2020
9ead853
Merge pull request #346 from QData/docs
qiyanjun Nov 17, 2020
5cd97aa
Update textattack_ecosystem.png
qiyanjun Nov 17, 2020
61b4d56
v0.2.13
jxmorris12 Nov 18, 2020
3bdd0a8
roll back transformers versions
jxmorris12 Nov 18, 2020
71185a0
v0.2.14
jxmorris12 Nov 18, 2020
e00253e
Create 3_Augmentations.ipynb
Hanyu-Liu-123 Nov 18, 2020
168aeda
add in "model card" information in the modles.md documentation.
qiyanjun Nov 18, 2020
02c653d
Merge branch 'master' of https://github.com/QData/TextAttack
qiyanjun Nov 18, 2020
993d49e
connect Readme.md in model folder to https://textattack.readthedocs.i…
qiyanjun Nov 18, 2020
ef3c2e2
update pos tagging in AttackedText
jinyongyoo Nov 19, 2020
ede35d4
fix query count when no candidate result score values are better than…
Nov 19, 2020
a53aec9
Update index.rst
Hanyu-Liu-123 Nov 20, 2020
1096541
Merge pull request #349 from QData/update-pos-tagging
jinyongyoo Nov 20, 2020
2719e20
Merge pull request #347 from QData/notebook
qiyanjun Nov 20, 2020
fe5aa5c
fix query count for GoalFunctionResult returned by SearchMethod._perf…
Nov 21, 2020
d37c5ab
remove duplicate line
Opdoop Nov 21, 2020
ec26dbf
make sure contents in the readme.md and readthedoc consistent
qiyanjun Nov 21, 2020
695d00a
Merge pull request #353 from Opdoop/patch-2
qiyanjun Nov 21, 2020
9d7c9ba
Update README.md
qiyanjun Nov 21, 2020
2fa6544
add structure in the FAQ
qiyanjun Nov 21, 2020
46ab64f
emphasize the point on constraint hold constant for Benchmarking Atta…
qiyanjun Nov 21, 2020
545687d
fix search behavior and update test
jinyongyoo Nov 22, 2020
278bb33
Merge pull request #350 from a1noack/fix_query_count
jinyongyoo Nov 22, 2020
eb0b837
Add chinese readme document
Opdoop Nov 19, 2020
9b1898f
Add the chinese version of readme
Opdoop Nov 20, 2020
8195194
Modified minor format of chinese version readme
Opdoop Nov 20, 2020
a7759a0
Modified table format of chinese version readme
Opdoop Nov 20, 2020
0f8abe7
Modified table format of chinese version readme
Opdoop Nov 20, 2020
45a1375
Modified table format of chinese version readme
Opdoop Nov 20, 2020
b71461b
Modified table format of chinese version readme
Opdoop Nov 20, 2020
b3b4896
Delete html table inline style
Opdoop Nov 20, 2020
e10efaf
Add DIV block to table title
Opdoop Nov 20, 2020
9098f89
test markdown colspan and breakline
Opdoop Nov 20, 2020
d0a6abf
test markdown colspan and breakline
Opdoop Nov 20, 2020
5a345e6
test markdown colspan and breakline
Opdoop Nov 20, 2020
c9451e3
test markdown colspan and breakline
Opdoop Nov 20, 2020
5b7ddc2
format html table width by adding slash
Opdoop Nov 20, 2020
d8b2c9d
Delete markdowntable_test.md
Opdoop Nov 20, 2020
987a0a2
made minor grammar modifications to the chinese readme
MintForever Nov 22, 2020
28601eb
Add chinese readme document
Opdoop Nov 19, 2020
8f403d4
Add the chinese version of readme
Opdoop Nov 20, 2020
d89c81c
Modified minor format of chinese version readme
Opdoop Nov 20, 2020
3f3b390
Modified table format of chinese version readme
Opdoop Nov 20, 2020
8580d0e
Modified table format of chinese version readme
Opdoop Nov 20, 2020
f503eb1
Modified table format of chinese version readme
Opdoop Nov 20, 2020
5dcd2a0
Modified table format of chinese version readme
Opdoop Nov 20, 2020
3997933
Delete html table inline style
Opdoop Nov 20, 2020
167e0bc
Add DIV block to table title
Opdoop Nov 20, 2020
0a22412
test markdown colspan and breakline
Opdoop Nov 20, 2020
ba44ea9
test markdown colspan and breakline
Opdoop Nov 20, 2020
2266394
test markdown colspan and breakline
Opdoop Nov 20, 2020
30a2bc9
test markdown colspan and breakline
Opdoop Nov 20, 2020
f819d8a
format html table width by adding slash
Opdoop Nov 20, 2020
c5139c2
Delete markdowntable_test.md
Opdoop Nov 20, 2020
318d7ab
Remote html style and class
Opdoop Nov 23, 2020
8c8b68f
Remote html style and class
Opdoop Nov 23, 2020
f617feb
Remote class
Opdoop Nov 23, 2020
8dc04ac
Merge remote-tracking branch 'TextAttack/review_readme_zh' into readm…
Opdoop Nov 24, 2020
8cfb885
Change the minor formation of html table
Opdoop Nov 24, 2020
fdfaf6c
Update readme_zh design section
Opdoop Nov 25, 2020
6f12980
add in README_ZH.md into the main README
qiyanjun Nov 25, 2020
6a383bf
Merge pull request #352 from Opdoop/readme_zh
qiyanjun Nov 25, 2020
e195181
rename classes
jinyongyoo Nov 27, 2020
43e7577
Merge pull request #333 from tsinggggg/custom-word-embedding
jinyongyoo Nov 27, 2020
4195868
option to test on entire dataset
ArshdeepSekhon Oct 22, 2020
754e06a
eval on entire dataset, checks
ArshdeepSekhon Oct 22, 2020
54e01ff
fix failed checks
ArshdeepSekhon Oct 22, 2020
b29a09a
evaluate on entire dataset
ArshdeepSekhon Nov 27, 2020
50baac6
evaluate on entire dataset
ArshdeepSekhon Nov 27, 2020
c55dd28
remove unused test-on-entire-dataset option
ArshdeepSekhon Nov 27, 2020
7635c7b
modify attack accordingly for entire dataset
ArshdeepSekhon Nov 27, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/check-formatting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
python -m pip install --upgrade pip setuptools wheel
pip install black flake8 isort # Testing packages
python setup.py install_egg_info # Workaround https://github.com/pypa/pip/issues/4537
pip install -e .
pip install -e .[dev]
- name: Check code format with black and isort
run: |
make lint
4 changes: 2 additions & 2 deletions .github/workflows/run-pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ jobs:
pip install pytest pytest-xdist # Testing packages
pip uninstall textattack --yes # Remove TA if it's already installed
python setup.py install_egg_info # Workaround https://github.com/pypa/pip/issues/4537
pip install .
pip install -e .[dev]
pip freeze
- name: Test with pytest
run: |
pytest tests -vx --dist=loadfile -n auto
pytest tests -v

2 changes: 2 additions & 0 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ python:
- requirements: requirements.txt
- method: pip
path: .
extra_requirements:
- docs
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test: FORCE ## Run tests using pytest
python -m pytest --dist=loadfile -n auto

docs: FORCE ## Build docs using Sphinx.
sphinx-build -b html docs docs/_build/html
sphinx-build -b html docs docs/_build/html

docs-check: FORCE ## Builds docs using Sphinx. If there is an error, exit with an error code (instead of warning & continuing).
sphinx-build -b html docs docs/_build/html -W
Expand Down
287 changes: 242 additions & 45 deletions README.md

Large diffs are not rendered by default.

517 changes: 517 additions & 0 deletions README_ZH.md

Large diffs are not rendered by default.

123 changes: 123 additions & 0 deletions docs/1start/FAQ.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
Frequently Asked Questions
========================================

## Via Slack: Where to Ask Questions:

For help and realtime updates related to TextAttack, please [join the TextAttack Slack](https://join.slack.com/t/textattack/shared_invite/zt-huomtd9z-KqdHBPPu2rOP~Z8q3~urgg)!


## Via CLI: `--help`

+ Easiest self help: `textattack --help`
+ More concrete self help:
- `textattack attack --help`
- `textattack augment --help`
- `textattack train --help`
- `textattack peek-dataset --help`
- `textattack list`, e.g., `textattack list search-methods`


## Via our papers: More details on results
+ [references](https://textattack.readthedocs.io/en/latest/1start/references.html)


## Via readthedocs: More details on APIs
+ [complete API reference on TextAttack](https://textattack.readthedocs.io/en/latest/apidoc/textattack.html)


## More Concrete Questions:


### 1. How to Train

For example, you can *Train our default LSTM for 50 epochs on the Yelp Polarity dataset:*
```bash
textattack train --model lstm --dataset yelp_polarity --batch-size 64 --epochs 50 --learning-rate 1e-5
```

The training process has data augmentation built-in:
```bash
textattack train --model lstm --dataset rotten_tomatoes --augment eda --pct-words-to-swap .1 --transformations-per-example 4
```
This uses the `EasyDataAugmenter` recipe to augment the `rotten_tomatoes` dataset before training.

*Fine-Tune `bert-base` on the `CoLA` dataset for 5 epochs**:
```bash
textattack train --model bert-base-uncased --dataset glue^cola --batch-size 32 --epochs 5
```




### 2. Use Custom Models

TextAttack is model-agnostic! You can use `TextAttack` to analyze any model that outputs IDs, tensors, or strings. To help users, TextAttack includes pre-trained models for different common NLP tasks. This makes it easier for
users to get started with TextAttack. It also enables a more fair comparison of attacks from the literature. A list of available pretrained models and their validation accuracies is available at [HERE](https://textattack.readthedocs.io/en/latest/3recipes/models.html).


You can easily try out an attack on a local model you prefer. To attack a pre-trained model, create a short file that loads them as variables `model` and `tokenizer`. The `tokenizer` must
be able to transform string inputs to lists or tensors of IDs using a method called `encode()`. The
model must take inputs via the `__call__` method.

##### Model from a file
To experiment with a model you've trained, you could create the following file
and name it `my_model.py`:

```python
model = load_your_model_with_custom_code() # replace this line with your model loading code
tokenizer = load_your_tokenizer_with_custom_code() # replace this line with your tokenizer loading code
```

Then, run an attack with the argument `--model-from-file my_model.py`. The model and tokenizer will be loaded automatically.

TextAttack is model-agnostic - meaning it can run attacks on models implemented in any deep learning framework. Model objects must be able to take a string (or list of strings) and return an output that can be processed by the goal function. For example, machine translation models take a list of strings as input and produce a list of strings as output. Classification and entailment models return an array of scores. As long as the user's model meets this specification, the model is fit to use with TextAttack.


### 3. Use Custom Datasets


#### From a file

Loading a dataset from a file is very similar to loading a model from a file. A 'dataset' is any iterable of `(input, output)` pairs.
The following example would load a sentiment classification dataset from file `my_dataset.py`:

```python
dataset = [('Today was....', 1), ('This movie is...', 0), ...]
```

You can then run attacks on samples from this dataset by adding the argument `--dataset-from-file my_dataset.py`.



#### Custom Dataset via AttackedText class

To allow for word replacement after a sequence has been tokenized, we include an `AttackedText` object
which maintains both a list of tokens and the original text, with punctuation. We use this object in favor of a list of words or just raw text.


#### Custome Dataset via Data Frames or other python data objects (*coming soon*)


### 4. Benchmarking Attacks

- See our analysis paper: Searching for a Search Method: Benchmarking Search Algorithms for Generating NLP Adversarial Examples at [EMNLP BlackNLP](https://arxiv.org/abs/2009.06368).

- As we emphasized in the above paper, we don't recommend to directly compare Attack Recipes out of the box.

- This comment is due to that attack recipes in the recent literature used different ways or thresholds in setting up their constraints. Without the constraint space held constant, an increase in attack success rate could from an improved search or transformation method or a less restrictive search space.


### 5. Create Custom or New Attacks

The `attack_one` method in an `Attack` takes as input an `AttackedText`, and outputs either a `SuccessfulAttackResult` if it succeeds or a `FailedAttackResult` if it fails.

- [Here is an example of using TextAttack to create a new attack method](https://github.com/jxmorris12/second-order-adversarial-examples)


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.


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.



12 changes: 11 additions & 1 deletion docs/1start/api-design-tips.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ One of the challenges for building such tools is that the tool should be flexibl

We provide the following broad advice to help other future developers create user-friendly NLP libraries in Python:
- To become model-agnostic, implement a model wrapper class: a model is anything that takes string input(s) and returns a prediction.
- To become model-agnostic, implement a model wrapper class.
- To become data-agnostic, take dataset inputs as (input, output) pairs, where each model input is represented as an OrderedDict.
- Do not plan for inputs (tensors, lists, etc.) to be a certain size or shape unless explicitly necessary.
- Centralize common text operations, like parsing and string-level operations, in one class.
Expand All @@ -29,6 +28,17 @@ We provide the following broad advice to help other future developers create use
Our modular and extendable design allows us to reuse many components to offer 15+ different adversarial attack methods proposed by literature. Our model-agnostic and dataset-agnostic design allows users to easily run adversarial attacks against their own models built using any deep learning framework. We hope that our lessons from developing TextAttack will help others create user-friendly open-source NLP libraries.


## TextAttack flowchart

![TextAttack flowchart](/_static/imgs/intro/textattack_components.png)


+ Here is a summary diagram of TextAttack Ecosystem

![diagram](/_static/imgs/intro/textattack_ecosystem.png)



## More Details in Reference

```
Expand Down
Loading