<h1 align="center">TextAttack ð</h1>
<p align="center">Generating adversarial examples for NLP models</p>
<p align="center">
<a href="https://textattack.readthedocs.io/">[TextAttack Documentation on ReadTheDocs]</a>
<br> <br>
<a href="#about">About</a> â¢
<a href="#setup">Setup</a> â¢
<a href="#usage">Usage</a> â¢
<a href="#design">Design</a>
<br> <br>
<a target="_blank">
<img src="https://github.com/QData/TextAttack/workflows/Github%20PyTest/badge.svg" alt="Github Runner Covergae Status">
</a>
<a href="https://badge.fury.io/py/textattack">
<img src="https://badge.fury.io/py/textattack.svg" alt="PyPI version" height="18">
</a>
</p>
<img src="http://jackxmorris.com/files/textattack.gif" alt="TextAttack Demo GIF" style="display: block; margin: 0 auto;" />
## About
TextAttack is a Python framework for adversarial attacks, data augmentation, and model training in NLP.
> If you're looking for information about TextAttack's menagerie of pre-trained models, you might want the [TextAttack Model Zoo](textattack/models/README.md) readme.
## Slack Channel
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)!
### *Why TextAttack?*
There are lots of reasons to use TextAttack:
1. **Understand NLP models better** by running different adversarial attacks on them and examining the output
2. **Research and develop different NLP adversarial attacks** using the TextAttack framework and library of components
3. **Augment your dataset** to increase model generalization and robustness downstream
3. **Train NLP models** using just a single command (all downloads included!)
## Setup
### Installation
You should be running Python 3.6+ to use this package. A CUDA-compatible GPU is optional but will greatly improve code speed. TextAttack is available through pip:
```bash
pip install textattack
```
Once TextAttack is installed, you can run it via command-line (`textattack ...`)
or via python module (`python -m textattack ...`).
> **Tip**: TextAttack downloads files to `~/.cache/textattack/` by default. This includes pretrained models,
> dataset samples, and the configuration file `config.yaml`. To change the cache path, set the
> environment variable `TA_CACHE_DIR`. (for example: `TA_CACHE_DIR=/tmp/ textattack attack ...`).
## Usage: `textattack --help`
TextAttack's main features can all be accessed via the `textattack` command. Two very
common commands are `textattack attack <args>`, and `textattack augment <args>`. You can see more
information about all commands using
```bash
textattack --help
```
or a specific command using, for example,
```bash
textattack attack --help
```
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..
### Running Attacks: `textattack attack --help`
The easiest way to try out an attack is via the command-line interface, `textattack attack`.
> **Tip:** If your machine has multiple GPUs, you can distribute the attack across them using the `--parallel` option. For some attacks, this can really help performance.
Here are some concrete examples:
*TextFooler on BERT trained on the MR sentiment classification dataset*:
```bash
textattack attack --recipe textfooler --model bert-base-uncased-mr --num-examples 100
```
*DeepWordBug on DistilBERT trained on the Quora Question Pairs paraphrase identification dataset*:
```bash
textattack attack --model distilbert-base-uncased-qqp --recipe deepwordbug --num-examples 100
```
*Beam search with beam width 4 and word embedding transformation and untargeted goal function on an LSTM*:
```bash
textattack attack --model lstm-mr --num-examples 20 \
--search-method beam-search^beam_width=4 --transformation word-swap-embedding \
--constraints repeat stopword max-words-perturbed^max_num_words=2 embedding^min_cos_sim=0.8 part-of-speech \
--goal-function untargeted-classification
```
> **Tip:** Instead of specifying a dataset and number of examples, you can pass `--interactive` to attack samples inputted by the user.
### Attacks and Papers Implemented ("Attack Recipes"): `textattack attack --recipe [recipe_name]`
We include attack recipes which implement attacks from the literature. You can list attack recipes using `textattack list attack-recipes`.
To run an attack recipe: `textattack attack --recipe [recipe_name]`
<table style="width:100%" border="1">
<thead>
<tr class="header">
<th style="text-align: left;"><strong>Attack Recipe Name</strong></th>
<th style="text-align: left;"><strong>Goal Function</strong></th>
<th style="text-align: left; width:130px" ><strong>Constraints-Enforced</strong></th>
<th style="text-align: left;"><strong>Transformation</strong></th>
<th style="text-align: left;"><strong>Search Method</strong></th>
<th style="text-align: left;"><strong>Main Idea</strong></th>
</tr>
</thead>
<tbody>
<tr><td style="text-align: center;" colspan="6"><strong><br>Attacks on classification tasks, like sentiment classification and entailment:<br></strong></td></tr>
<tr class="even">
<td style="text-align: left;"><code>alzantot</code> <span class="citation" data-cites="Alzantot2018GeneratingNL Jia2019CertifiedRT"></span></td>
<td style="text-align: left;"><sub>Untargeted {Classification, Entailment}</sub></td>
<td style="text-align: left;"><sub>Percentage of words perturbed, Language Model perplexity, Word embedding distance</sub></td>
<td style="text-align: left;"><sub>Counter-fitted word embedding swap</sub></td>
<td style="text-align: left;"><sub>Genetic Algorithm</sub></td>
<td ><sub>from (["Generating Natural Language Adversarial Examples" (Alzantot et al., 2018)](https://arxiv.org/abs/1804.07998))</sub></td>
</tr>
<tr class="odd">
<td style="text-align: left;"><code>bae</code> <span class="citation" data-cites="garg2020bae"></span></td>
<td style="text-align: left;"><sub>Untargeted Classification</sub></td>
<td style="text-align: left;"><sub>USE sentence encoding cosine similarity</sub></td>
<td style="text-align: left;"><sub>BERT Masked Token Prediction</sub></td>
<td style="text-align: left;"><sub>Greedy-WIR</sub></td>
<td ><sub>BERT masked language model transformation attack from (["BAE: BERT-based Adversarial Examples for Text Classification" (Garg & Ramakrishnan, 2019)](https://arxiv.org/abs/2004.01970)). </td>
</tr>
<tr class="even">
<td style="text-align: left;"><code>bert-attack</code> <span class="citation" data-cites="li2020bertattack"></span></td>
<td style="text-align: left;"><sub>Untargeted Classification</td>
<td style="text-align: left;"><sub>USE sentence encoding cosine similarity, Maximum number of words perturbed</td>
<td style="text-align: left;"><sub>BERT Masked Token Prediction (with subword expansion)</td>
<td style="text-align: left;"><sub>Greedy-WIR</sub></td>
<td ><sub> (["BERT-ATTACK: Adversarial Attack Against BERT Using BERT" (Li et al., 2020)](https://arxiv.org/abs/2004.09984))</sub></td>
</tr>
<tr class="odd">
<td style="text-align: left;"><code>checklist</code> <span class="citation" data-cites="Gao2018BlackBoxGO"></span></td>
<td style="text-align: left;"><sub>{Untargeted, Targeted} Classification</sub></td>
<td style="text-align: left;"><sub>checklist distance</sub></td>
<td style="text-align: left;"><sub>contract, extend, and substitutes name entities</sub></td>
<td style="text-align: left;"><sub>Greedy-WIR</sub></td>
<td ><sub>Invariance testing implemented in CheckList . (["Beyond Accuracy: Behavioral Testing of NLP models with CheckList" (Ribeiro et al., 2020)](https://arxiv.org/abs/2005.04118))</sub></td>
</tr>
<tr class="even">
<td style="text-align: left;"> <code>clare (*coming s
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
共198个文件
py:189个
txt:5个
pkg-info:2个
资源分类:Python库 所属语言:Python 资源全名:textattack-0.2.13.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源推荐
资源详情
资源评论
收起资源包目录
Python库 | textattack-0.2.13.tar.gz (198个子文件)
setup.cfg 499B
README.md 32KB
PKG-INFO 37KB
PKG-INFO 37KB
data.py 253KB
run_training.py 23KB
attacked_text.py 22KB
attack_args_helpers.py 21KB
attack.py 16KB
attack_args.py 14KB
particle_swarm_optimization.py 14KB
genetic_algorithm.py 12KB
word_swap_masked_lm.py 10KB
lm_data_utils.py 10KB
infer_sent_model.py 9KB
augment.py 9KB
sentence_encoder.py 8KB
train_args_helpers.py 8KB
goal_function.py 7KB
attack_command.py 7KB
checkpoint.py 7KB
greedy_word_swap_wir.py 7KB
word_embedding_distance.py 7KB
run_attack_parallel.py 7KB
train_model_command.py 7KB
recipes.py 6KB
augmenter.py 6KB
strings.py 6KB
attack_log_manager.py 6KB
alzantot_genetic_algorithm.py 6KB
faster_genetic_algorithm_jia_2019.py 6KB
part_of_speech.py 6KB
bae_garg_2019.py 6KB
glove_tokenizer.py 6KB
textfooler_jin_2019.py 6KB
improved_genetic_algorithm.py 6KB
install.py 5KB
run_attack_single_threaded.py 5KB
huggingface_dataset.py 5KB
constraint.py 5KB
attack_result.py 5KB
validators.py 5KB
language_model_helpers.py 5KB
word_swap_gradient_based.py 5KB
huggingface_model_wrapper.py 4KB
eval_model_command.py 4KB
word_swap_change_number.py 4KB
textbugger_li_2018.py 4KB
bert_attack_li_2020.py 4KB
google_language_model.py 4KB
word_embedding.py 4KB
auto_tokenizer.py 4KB
adaptive_softmax.py 4KB
misc.py 4KB
visdom_logger.py 4KB
alzantot_goog_lm.py 3KB
word_swap_qwerty.py 3KB
pytorch_model_wrapper.py 3KB
cola.py 3KB
word_swap_inflections.py 3KB
word_swap_embedding.py 3KB
glove_embedding_layer.py 3KB
rnn_model.py 3KB
list_things.py 3KB
word_swap_change_location.py 3KB
word_swap_hownet.py 3KB
population_based_search.py 3KB
classification_goal_function.py 3KB
peek_dataset.py 3KB
pruthi_2019.py 3KB
genetic_algorithm_alzantot_2018.py 3KB
deepwordbug_gao_2018.py 3KB
bert_score.py 3KB
attack_resume_command.py 3KB
word_swap_change_name.py 3KB
t5_tokenizer.py 3KB
word_cnn_for_classification.py 2KB
lstm_for_classification.py 2KB
pso_zang_2020.py 2KB
transformation.py 2KB
kuleshov_2017.py 2KB
hotflip_ebrahimi_2017.py 2KB
dataset.py 2KB
pre_transformation_constraint.py 2KB
weights_and_biases_logger.py 2KB
word_swap_homoglyph_swap.py 2KB
lm_utils.py 2KB
model_wrapper.py 2KB
max_words_perturbed.py 2KB
classification_goal_function_result.py 2KB
goal_function_result.py 2KB
t5_for_text_to_text.py 2KB
search_method.py 2KB
beam_search.py 2KB
iga_wang_2019.py 2KB
language_model_constraint.py 2KB
word_swap_neighboring_character_swap.py 2KB
gpt2.py 2KB
learning_to_write.py 2KB
setup.py 2KB
共 198 条
- 1
- 2
资源评论
挣扎的蓝藻
- 粉丝: 13w+
- 资源: 15万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功