textattack.transformations package
Transformations
A transformation is a method which perturbs a text input through the insertion, deletion and substiution of words, characters, and phrases. All transformations take a TokenizedText as input and return a list of TokenizedText that contains possible transformations. Every transformation is a subclass of the abstract Transformation class.
Subpackages
- textattack.transformations.sentence_transformations package
- textattack.transformations.word_insertions package
- textattack.transformations.word_merges package
- textattack.transformations.word_swaps package
- word_swaps package
- Subpackages
- Submodules
- Word Swap
WordSwap- Word Swap by Changing Location
WordSwapChangeLocationidx_to_words()- Word Swap by Changing Name
WordSwapChangeName- Word Swap by Changing Number
WordSwapChangeNumberidx_to_words()- Word Swap by Contraction
WordSwapContract- Word Swap by Invisible Deletions
WordSwapDeletions- Word Swap for Differential Evolution
WordSwapDifferentialEvolution- Word Swap by Embedding
WordSwapEmbeddingrecover_word_case()- Word Swap by Extension
WordSwapExtend- Word Swap by Gradient
WordSwapGradientBased- Word Swap by Homoglyph
WordSwapHomoglyphSwap- Word Swap by OpenHowNet
WordSwapHowNetrecover_word_case()- Word Swap by inflections
WordSwapInflections- Word Swap by Invisible Characters
WordSwapInvisibleCharacters- Word Swap by BERT-Masked LM.
WordSwapMaskedLMrecover_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 Invisible Reorderings
WordSwapReorderings- Word Swap by swapping synonyms in WordNet
WordSwapWordNet
Submodules
Composite Transformation
Multiple transformations can be used by providing a list of Transformation to CompositeTransformation
- class textattack.transformations.composite_transformation.CompositeTransformation(transformations)[source]
Bases:
TransformationA transformation which applies each of a list of transformations, returning a set of all options.
- Parameters:
transformations – The list of
Transformationto apply.
Transformation Abstract Class
- class textattack.transformations.transformation.Transformation[source]
Bases:
ReprMixin,ABCAn abstract class for transforming a sequence of text to produce a potential adversarial example.
- property deterministic
word deletion Transformation
- class textattack.transformations.word_deletion.WordDeletion[source]
Bases:
TransformationAn abstract class that takes a sentence and transforms it by deleting a single word.
letters_to_insert (string): letters allowed for insertion into words
Word Swap Transformation by swapping the order of words
- class textattack.transformations.word_innerswap_random.WordInnerSwapRandom[source]
Bases:
TransformationTransformation that randomly swaps the order of words in a sequence.
- property deterministic