You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+11-7Lines changed: 11 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -71,7 +71,11 @@ or a specific command using, for example,
71
71
textattack attack --help
72
72
```
73
73
74
-
The [`examples/`](examples/) folder includes scripts showing common TextAttack usage for training models, running attacks, and augmenting a CSV file. The [documentation website](https://textattack.readthedocs.io/en/latest) contains walkthroughs explaining basic usage of TextAttack, including building a custom transformation and a custom constraint..
74
+
The [`examples/`](examples/) folder includes scripts showing common TextAttack usage for training models, running attacks, and augmenting a CSV file.
75
+
76
+
77
+
The [documentation website](https://textattack.readthedocs.io/en/latest) contains walkthroughs explaining basic usage of TextAttack, including building a custom transformation and a custom constraint..
will augment the `text` column by altering 10% of each example's words, generating twice as many augmentations as original inputs, and exclude the original inputs from the
328
334
output CSV. (All of this will be saved to `augment.csv` by default.)
329
335
@@ -453,7 +459,7 @@ create a short file that loads them as variables `model` and `tokenizer`. The `
453
459
be able to transform string inputs to lists or tensors of IDs using a method called `encode()`. The
454
460
model must take inputs via the `__call__` method.
455
461
456
-
##### Model from a file
462
+
##### Custom Model from a file
457
463
To experiment with a model you've trained, you could create the following file
458
464
and name it `my_model.py`:
459
465
@@ -488,14 +494,12 @@ which maintains both a list of tokens and the original text, with punctuation. W
488
494
489
495
490
496
491
-
#### Dataset via Data Frames (*coming soon*)
497
+
#### Dataset loading via other mechanism, see: [here](https://textattack.readthedocs.io/en/latest/api/datasets.html)
492
498
493
499
494
500
495
501
### Attacks and how to design a new attack
496
502
497
-
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.
498
-
499
503
500
504
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.
will augment the `text` column with 10% of words edited per augmentation, twice as many augmentations as original inputs, and exclude the original inputs from the
## Textattack Supports Multiple Model Types besides huggingface models and our textattack models:
7
+
8
+
- Example attacking TensorFlow models @ [https://textattack.readthedocs.io/en/latest/2notebook/Example_0_tensorflow.html](https://textattack.readthedocs.io/en/latest/2notebook/Example_0_tensorflow.html)
9
+
- Example attacking scikit-learn models @ [https://textattack.readthedocs.io/en/latest/2notebook/Example_1_sklearn.html](https://textattack.readthedocs.io/en/latest/2notebook/Example_1_sklearn.html)
10
+
- Example attacking AllenNLP models @ [https://textattack.readthedocs.io/en/latest/2notebook/Example_2_allennlp.html](https://textattack.readthedocs.io/en/latest/2notebook/Example_2_allennlp.html)
11
+
- Example attacking Kera models @ [https://textattack.readthedocs.io/en/latest/2notebook/Example_3_Keras.html](https://textattack.readthedocs.io/en/latest/2notebook/Example_3_Keras.html)
12
+
13
+
6
14
## Multilingual Supports
7
15
8
-
- see example code: [https://github.com/QData/TextAttack/blob/master/examples/attack/attack_camembert.py](https://github.com/QData/TextAttack/blob/master/examples/attack/attack_camembert.py) for using our framework to attack French-BERT.
9
16
10
-
- see tutorial notebook: [https://textattack.readthedocs.io/en/latest/2notebook/Example_4_CamemBERT.html](https://textattack.readthedocs.io/en/latest/2notebook/Example_4_CamemBERT.html) for using our framework to attack French-BERT.
17
+
- see tutorial notebook for using our framework to attack French-BERT.: [https://textattack.readthedocs.io/en/latest/2notebook/Example_4_CamemBERT.html](https://textattack.readthedocs.io/en/latest/2notebook/Example_4_CamemBERT.html)
18
+
19
+
- see example code for using our framework to attack French-BERT: [https://github.com/QData/TextAttack/blob/master/examples/attack/attack_camembert.py](https://github.com/QData/TextAttack/blob/master/examples/attack/attack_camembert.py) .
20
+
21
+
22
+
23
+
## User defined custom inputs and models
24
+
25
+
26
+
### Custom Datasets: Dataset from a file
27
+
28
+
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.
29
+
The following example would load a sentiment classification dataset from file `my_dataset.py`:
30
+
31
+
```python
32
+
dataset = [('Today was....', 1), ('This movie is...', 0), ...]
33
+
```
34
+
35
+
You can then run attacks on samples from this dataset by adding the argument `--dataset-from-file my_dataset.py`.
36
+
37
+
38
+
#### Custom Model: from a file
39
+
To experiment with a model you've trained, you could create the following file
40
+
and name it `my_model.py`:
41
+
42
+
```python
43
+
model = load_your_model_with_custom_code() # replace this line with your model loading code
44
+
tokenizer = load_your_tokenizer_with_custom_code() # replace this line with your tokenizer loading code
45
+
```
46
+
47
+
Then, run an attack with the argument `--model-from-file my_model.py`. The model and tokenizer will be loaded automatically.
48
+
49
+
50
+
51
+
## User defined Custom attack components
52
+
53
+
The [documentation website](https://textattack.readthedocs.io/en/latest) contains walkthroughs explaining basic usage of TextAttack, including building a custom transformation and a custom constraint..
54
+
55
+
- custom transformation example @ [https://textattack.readthedocs.io/en/latest/2notebook/1_Introduction_and_Transformations.html](https://textattack.readthedocs.io/en/latest/2notebook/1_Introduction_and_Transformations.html)
56
+
57
+
- custome constraint example @[https://textattack.readthedocs.io/en/latest/2notebook/2_Constraints.html#A-custom-constraint](https://textattack.readthedocs.io/en/latest/2notebook/2_Constraints.html#A-custom-constraint)
58
+
59
+
60
+
61
+
62
+
## Visulizing TextAttack generated Examples;
11
63
12
64
65
+
- You can visualize the generated adversarial examples vs. see examples, following visualization ways we provided here: [https://textattack.readthedocs.io/en/latest/2notebook/2_Constraints.html](https://textattack.readthedocs.io/en/latest/2notebook/2_Constraints.html)
13
66
14
-
## We have built a new WebDemo For Visulizing TextAttackgenerated Examples;
67
+
- If you have webapp, we have also built a new WebDemo [TextAttack-WebDemo Github](https://github.com/QData/TextAttack-WebDemo) for visualizing generated adversarial examples from textattack..
will augment the `text` column by altering 10% of each example's words, generating twice as many augmentations as original inputs, and exclude the original inputs from the
43
46
output CSV. (All of this will be saved to `augment.csv` by default.)
0 commit comments