TextAttack Documentation
- Basic-Introduction
- Installation
- Command-Line Usage
- Quick API Usage
- FAQ
- Via Slack: Where to Ask Questions:
- Via CLI:
--help
- Via our papers: More details on results
- Via readthedocs: More details on APIs
- More Concrete Questions:
- Attack Recipes CommandLine Use
- Attack Recipes API
- Attacks on classification models
- A2T (A2T: Attack for Adversarial Training Recipe)
- Alzantot Genetic Algorithm
- Faster Alzantot Genetic Algorithm
- BAE (BAE: BERT-Based Adversarial Examples)
- BERT-Attack:
- CheckList:
- DeepWordBug
- HotFlip
- Improved Genetic Algorithm
- Input Reduction
- Kuleshov2017
- Particle Swarm Optimization
- PWWS
- TextFooler (Is BERT Really Robust?)
- TextBugger
- CLARE Recipe
- Pruthi2019: Combating with Robust Word Recognition
- Attacks on sequence-to-sequence models
- Attacks on classification models
- Augmenter Recipes CommandLine Use
- Augmenter Recipes API
- TextAttack Model Zoo
- Available Models
- Evaluation Results of Available Models
- How we have trained the TextAttack Models
- Training details for each TextAttack Model
- More details on TextAttack fine-tuned NLP models (details on target NLP task, input type, output type, SOTA results on paperswithcode; model card on huggingface):
- What is an adversarial attack in NLP?
- How to Cite TextAttack
- Main Paper: TextAttack: A Framework for Adversarial Attacks, Data Augmentation, and Adversarial Training in NLP
- Our Analysis paper: Reevaluating Adversarial Examples in Natural Language
- Our Analysis paper: Searching for a Search Method: Benchmarking Search Algorithms for Generating NLP Adversarial Examples
- Our defense paper: Title: “Towards Improving Adversarial Training of NLP Models”
- Our extended use case paper: “Expanding Scope: Adapting English Adversarial Attacks to Chinese”
- Four Components of TextAttack Attacks
- Benchmarking Search Algorithms for Generating NLP Adversarial Examples
- On Quality of Generated Adversarial Examples and How to Set Attack Contraints
- Title: Reevaluating Adversarial Examples in Natural Language
- Our Github on Reevaluation: Reevaluating-NLP-Adversarial-Examples Github
- Some of our evaluation results on quality of two SOTA attack recipes
- Some of our evaluation results on how to set constraints to evaluate NLP model’s adversarial robustness
- Making Vanilla Adversarial Training of NLP Models Feasible!
- Lessons learned in designing TextAttack
- TextAttack Extended Functions (Multilingual)
- How can I contribute to TextAttack?
- Tutorial 0: TextAttack End-To-End (Train, Eval, Attack)
- Tutorial 1: Transformations
- Tutorial 2: Constraints
- Tutorial 3: Augmentation
- Tutorial 4: Custom Word Embeddings
- Tutorial 5: Attacking TensorFlow models
- Tutorial 6: Attacking scikit-learn models
- Tutorial 7: Attacking AllenNLP models
- Tutorial 8: Attacking Keras models
- Tutorial 9: Attacking multilingual models
- Tutorial10: Explaining Attacking BERT model using Captum
- Tutorial11: Attacking multilingual - Chinese NLP model using Textattack
- Attack
- Attacker
- AttackResult
- Trainer
- Datasets
- GoalFunction
- Constraints
- Transformations
- SearchMethod
- textattack package
- textattack.attack_recipes package
- Attack Recipes Package:
- A2T (A2T: Attack for Adversarial Training Recipe)
A2TYoo2021
- Attack Recipe Class
AttackRecipe
- BAE (BAE: BERT-Based Adversarial Examples)
BAEGarg2019
- BERT-Attack:
BERTAttackLi2020
- CheckList:
CheckList2020
- CLARE Recipe
CLARE2020
- DeepWordBug
DeepWordBugGao2018
- Faster Alzantot Genetic Algorithm
FasterGeneticAlgorithmJia2019
- Alzantot Genetic Algorithm
GeneticAlgorithmAlzantot2018
- HotFlip
HotFlipEbrahimi2017
- Improved Genetic Algorithm
IGAWang2019
- Input Reduction
InputReductionFeng2018
- Kuleshov2017
Kuleshov2017
- MORPHEUS2020
MorpheusTan2020
- Pruthi2019: Combating with Robust Word Recognition
Pruthi2019
- Particle Swarm Optimization
PSOZang2020
- PWWS
PWWSRen2019
- Seq2Sick
Seq2SickCheng2018BlackBox
- TextBugger
TextBuggerLi2018
- TextFooler (Is BERT Really Robust?)
TextFoolerJin2019
- textattack.attack_results package
- textattack.augmentation package
- TextAttack augmentation package:
- Augmenter Class
AugmentationResult
Augmenter
- Augmenter Recipes:
BackTranscriptionAugmenter
BackTranslationAugmenter
CLAREAugmenter
CharSwapAugmenter
CheckListAugmenter
DeletionAugmenter
EasyDataAugmenter
EmbeddingAugmenter
SwapAugmenter
SynonymInsertionAugmenter
WordNetAugmenter
- textattack.commands package
- TextAttack commands Package
- AttackCommand class
AttackCommand
- AttackResumeCommand class
AttackResumeCommand
- AugmentCommand class
AugmentCommand
- BenchmarkRecipeCommand class
BenchmarkRecipeCommand
- EvalModelCommand class
EvalModelCommand
ModelEvalArgs
- ListThingsCommand class
ListThingsCommand
- PeekDatasetCommand class
PeekDatasetCommand
- TextAttack CLI main class
main()
TextAttackCommand
- TrainModelCommand class
TrainModelCommand
- textattack.constraints package
- Constraints
- textattack.constraints.grammaticality package
- Grammaticality:
- textattack.constraints.grammaticality.language_models package
- non-pre Language Models:
- textattack.constraints.grammaticality.language_models.google_language_model package
- textattack.constraints.grammaticality.language_models.learning_to_write package
- GPT2 Language Models:
GPT2
- Language Models Constraint
LanguageModelConstraint
- CoLA for Grammaticality
COLA
- LanguageTool Grammar Checker
LanguageTool
- Part of Speech Constraint
PartOfSpeech
- textattack.constraints.overlap package
- textattack.constraints.pre_transformation package
- Pre-Transformation:
- Input Column Modification
InputColumnModification
- Max Modification Rate
MaxModificationRate
- Max Word Index Modification
MaxWordIndexModification
- Min Word Lenth
MinWordLength
- Repeat Modification
RepeatModification
- Stopword Modification
StopwordModification
UnmodifiableIndices
UnmodifablePhrases
- textattack.constraints.semantics package
- Semantic Constraints
- textattack.constraints.semantics.sentence_encoders package
- Sentence Encoder Constraint
- textattack.constraints.semantics.sentence_encoders.bert package
- textattack.constraints.semantics.sentence_encoders.infer_sent package
- infer sent
- infer sent for sentence similarity
InferSent
- Infer sent model
InferSentModel
InferSentModel.build_vocab()
InferSentModel.build_vocab_k_words()
InferSentModel.encode()
InferSentModel.forward()
InferSentModel.get_batch()
InferSentModel.get_w2v()
InferSentModel.get_w2v_k()
InferSentModel.get_word_dict()
InferSentModel.is_cuda()
InferSentModel.prepare_samples()
InferSentModel.set_w2v_path()
InferSentModel.tokenize()
InferSentModel.update_vocab()
InferSentModel.training
- textattack.constraints.semantics.sentence_encoders.universal_sentence_encoder package
- Sentence Encoder Class
SentenceEncoder
get_angular_sim()
get_neg_euclidean_dist()
- Thought Vector Class
ThoughtVector
- BERT Score
BERTScore
- Word Embedding Distance
WordEmbeddingDistance
- TextAttack Constraint Class
Constraint
- Pre-Transformation Constraint Class
PreTransformationConstraint
- textattack.datasets package
- textattack.goal_function_results package
- textattack.goal_functions package
- Goal Functions
- textattack.goal_functions.classification package
- Goal fucntion for Classification
- Determine for if an attack has been successful in Classification
ClassificationGoalFunction
- Determine if maintaining the same predicted label (input reduction)
InputReduction
- Determine if an attack has been successful in targeted Classification
TargetedClassification
- Determine successful in untargeted Classification
UntargetedClassification
- textattack.goal_functions.text package
- GoalFunction Class
GoalFunction
- textattack.llms package
- textattack.loggers package
- Misc Loggers: Loggers track, visualize, and export attack results.
- Managing Attack Logs.
AttackLogManager
AttackLogManager.add_output_csv()
AttackLogManager.add_output_file()
AttackLogManager.add_output_summary_json()
AttackLogManager.disable_color()
AttackLogManager.enable_stdout()
AttackLogManager.enable_visdom()
AttackLogManager.enable_wandb()
AttackLogManager.flush()
AttackLogManager.log_attack_details()
AttackLogManager.log_result()
AttackLogManager.log_results()
AttackLogManager.log_sep()
AttackLogManager.log_summary()
AttackLogManager.log_summary_rows()
AttackLogManager.metrics
- Attack Logs to CSV
CSVLogger
- Attack Logs to file
FileLogger
- Attack Logger Wrapper
Logger
- Attack Logs to Visdom
VisdomLogger
port_is_open()
- Attack Logs to WandB
WeightsAndBiasesLogger
- textattack.metrics package
- metrics package: to calculate advanced metrics for evaluting attacks and augmented text
- textattack.metrics.attack_metrics package
- textattack.metrics.quality_metrics package
- Metric Class
Metric
- textattack.models package
- Models
- textattack.models.helpers package
- textattack.models.tokenizers package
- textattack.models.wrappers package
- textattack.prompt_augmentation package
- textattack.search_methods package
- Search Methods
- Reimplementation of search method from Generating Natural Language Adversarial Examples
AlzantotGeneticAlgorithm
- Beam Search
BeamSearch
- Genetic Algorithm Word Swap
GeneticAlgorithm
- Greedy Search
GreedySearch
- Greedy Word Swap with Word Importance Ranking
GreedyWordSwapWIR
- Reimplementation of search method from Xiaosen Wang, Hao Jin, Kun He (2019).
ImprovedGeneticAlgorithm
- Particle Swarm Optimization
ParticleSwarmOptimization
normalize()
- Population based Search abstract class
PopulationBasedSearch
PopulationMember
- Search Method Abstract Class
SearchMethod
- textattack.shared package
- Shared TextAttack Functions
- textattack.shared.utils package
LazyLoader
load_module_from_file()
download_from_s3()
download_from_url()
http_get()
path_in_cache()
s3_url()
set_cache_dir()
unzip_file()
get_textattack_model_num_labels()
hashable()
html_style_from_dict()
html_table_from_rows()
load_textattack_model_from_path()
set_seed()
sigmoid()
ANSI_ESCAPE_CODES
ANSI_ESCAPE_CODES.BOLD
ANSI_ESCAPE_CODES.BROWN
ANSI_ESCAPE_CODES.CYAN
ANSI_ESCAPE_CODES.FAIL
ANSI_ESCAPE_CODES.GRAY
ANSI_ESCAPE_CODES.HEADER
ANSI_ESCAPE_CODES.OKBLUE
ANSI_ESCAPE_CODES.OKGREEN
ANSI_ESCAPE_CODES.ORANGE
ANSI_ESCAPE_CODES.PINK
ANSI_ESCAPE_CODES.PURPLE
ANSI_ESCAPE_CODES.STOP
ANSI_ESCAPE_CODES.UNDERLINE
ANSI_ESCAPE_CODES.WARNING
ANSI_ESCAPE_CODES.YELLOW
ReprMixin
TextAttackFlairTokenizer
add_indent()
check_if_punctuations()
check_if_subword()
color_from_label()
color_from_output()
color_text()
default_class_repr()
flair_tag()
has_letter()
is_one_word()
process_label_name()
strip_BPE_artifacts()
words_from_text()
zip_flair_result()
zip_stanza_result()
batch_model_predict()
- Attacked Text Class
AttackedText
AttackedText.align_with_model_tokens()
AttackedText.all_words_diff()
AttackedText.convert_from_original_idxs()
AttackedText.delete_word_at_index()
AttackedText.first_word_diff()
AttackedText.first_word_diff_index()
AttackedText.free_memory()
AttackedText.generate_new_attacked_text()
AttackedText.get_deletion_indices()
AttackedText.insert_text_after_word_index()
AttackedText.insert_text_before_word_index()
AttackedText.ith_word_diff()
AttackedText.ner_of_word_index()
AttackedText.pos_of_word_index()
AttackedText.printable_text()
AttackedText.replace_word_at_index()
AttackedText.replace_words_at_indices()
AttackedText.text_after_word_index()
AttackedText.text_until_word_index()
AttackedText.text_window_around_index()
AttackedText.words_diff_num()
AttackedText.words_diff_ratio()
AttackedText.SPLIT_TOKEN
AttackedText.column_labels
AttackedText.newly_swapped_words
AttackedText.num_words
AttackedText.text
AttackedText.tokenizer_input
AttackedText.words
AttackedText.words_per_input
- Misc Checkpoints
AttackCheckpoint
AttackCheckpoint.load()
AttackCheckpoint.save()
AttackCheckpoint.dataset_offset
AttackCheckpoint.datetime
AttackCheckpoint.num_failed_attacks
AttackCheckpoint.num_maximized_attacks
AttackCheckpoint.num_remaining_attacks
AttackCheckpoint.num_skipped_attacks
AttackCheckpoint.num_successful_attacks
AttackCheckpoint.results_count
- Shared data fields
- Misc Validators
transformation_consists_of()
transformation_consists_of_word_swaps()
transformation_consists_of_word_swaps_and_deletions()
validate_model_goal_function_compatibility()
validate_model_gradient_word_swap_compatibility()
- Shared loads word embeddings and related distances
AbstractWordEmbedding
GensimWordEmbedding
WordEmbedding
- textattack.transformations package
- Transformations
- textattack.transformations.sentence_transformations package
- textattack.transformations.word_insertions package
- textattack.transformations.word_merges package
- textattack.transformations.word_swaps package
- word_swaps package
- Word Swap
WordSwap
- Word Swap by Changing Location
WordSwapChangeLocation
idx_to_words()
- Word Swap by Changing Name
WordSwapChangeName
- Word Swap by Changing Number
WordSwapChangeNumber
idx_to_words()
- Word Swap by Contraction
WordSwapContract
- Word Swap by Embedding
WordSwapEmbedding
recover_word_case()
- Word Swap by Extension
WordSwapExtend
- Word Swap by Gradient
WordSwapGradientBased
- Word Swap by Homoglyph
WordSwapHomoglyphSwap
- Word Swap by OpenHowNet
WordSwapHowNet
recover_word_case()
- Word Swap by inflections
WordSwapInflections
- Word Swap by BERT-Masked LM.
WordSwapMaskedLM
recover_word_case()
- Word Swap by Neighboring Character Swap
WordSwapNeighboringCharacterSwap
- Word Swap by swaps characters with QWERTY adjacent keys
WordSwapQWERTY
- Word Swap by Random Character Deletion
WordSwapRandomCharacterDeletion
- Word Swap by Random Character Insertion
WordSwapRandomCharacterInsertion
- Word Swap by Random Character Substitution
WordSwapRandomCharacterSubstitution
- Word Swap by swapping synonyms in WordNet
WordSwapWordNet
- Composite Transformation
CompositeTransformation
- Transformation Abstract Class
Transformation
- word deletion Transformation
WordDeletion
- Word Swap Transformation by swapping the order of words
WordInnerSwapRandom
- Attack Class
Attack
- AttackArgs Class
AttackArgs
AttackArgs.create_loggers_from_args()
AttackArgs.attack_n
AttackArgs.checkpoint_dir
AttackArgs.checkpoint_interval
AttackArgs.csv_coloring_style
AttackArgs.disable_stdout
AttackArgs.enable_advance_metrics
AttackArgs.log_summary_to_json
AttackArgs.log_to_csv
AttackArgs.log_to_txt
AttackArgs.log_to_visdom
AttackArgs.log_to_wandb
AttackArgs.metrics
AttackArgs.num_examples
AttackArgs.num_examples_offset
AttackArgs.num_successful_examples
AttackArgs.num_workers_per_device
AttackArgs.parallel
AttackArgs.query_budget
AttackArgs.random_seed
AttackArgs.shuffle
AttackArgs.silent
CommandLineAttackArgs
- Attacker Class
Attacker
attack_from_queue()
pytorch_multiprocessing_workaround()
set_env_variables()
- AugmenterArgs Class
AugmenterArgs
AugmenterArgs.enable_advanced_metrics
AugmenterArgs.exclude_original
AugmenterArgs.fast_augment
AugmenterArgs.high_yield
AugmenterArgs.input_column
AugmenterArgs.input_csv
AugmenterArgs.interactive
AugmenterArgs.output_csv
AugmenterArgs.overwrite
AugmenterArgs.pct_words_to_swap
AugmenterArgs.random_seed
AugmenterArgs.recipe
AugmenterArgs.transformations_per_example
- DatasetArgs Class
DatasetArgs
- ModelArgs Class
ModelArgs
- Trainer Class
Trainer
- TrainingArgs Class
CommandLineTrainingArgs
TrainingArgs
TrainingArgs.alpha
TrainingArgs.attack_epoch_interval
TrainingArgs.attack_num_workers_per_device
TrainingArgs.checkpoint_interval_epochs
TrainingArgs.checkpoint_interval_steps
TrainingArgs.early_stopping_epochs
TrainingArgs.gradient_accumulation_steps
TrainingArgs.learning_rate
TrainingArgs.load_best_model_at_end
TrainingArgs.log_to_tb
TrainingArgs.log_to_wandb
TrainingArgs.logging_interval_step
TrainingArgs.num_clean_epochs
TrainingArgs.num_epochs
TrainingArgs.num_train_adv_examples
TrainingArgs.num_warmup_steps
TrainingArgs.output_dir
TrainingArgs.parallel
TrainingArgs.per_device_eval_batch_size
TrainingArgs.per_device_train_batch_size
TrainingArgs.query_budget_train
TrainingArgs.random_seed
TrainingArgs.save_last
TrainingArgs.tb_log_dir
TrainingArgs.wandb_project
TrainingArgs.weight_decay
default_output_dir()
- textattack.attack_recipes package