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.
- 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
- Word Swap by Changing Location
- Word Swap by Changing Name
- Word Swap by Changing Number
- Word Swap by Contraction
- Word Swap by Embedding
- Word Swap by Extension
- Word Swap by Gradient
- Word Swap by Homoglyph
- Word Swap by OpenHowNet
- Word Swap by inflections
- Word Swap by BERT-Masked LM.
- Word Swap by Neighboring Character Swap
- Word Swap by swaps characters with QWERTY adjacent keys
- Word Swap by Random Character Deletion
- Word Swap by Random Character Insertion
- Word Swap by Random Character Substitution
- Word Swap by swapping synonyms in WordNet
Composite Transformation
Multiple transformations can be used by providing a list of Transformation
to CompositeTransformation
- class textattack.transformations.composite_transformation.CompositeTransformation(transformations)[source]
Bases:
textattack.transformations.transformation.Transformation
A transformation which applies each of a list of transformations, returning a set of all optoins.
- Parameters
transformations – The list of
Transformation
to apply.
Transformation Abstract Class
word deletion Transformation
- class textattack.transformations.word_deletion.WordDeletion[source]
Bases:
textattack.transformations.transformation.Transformation
An 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:
textattack.transformations.transformation.Transformation
Transformation that randomly swaps the order of words in a sequence.
- property deterministic