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
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
Multiple transformations can be used by providing a list of Transformation
to CompositeTransformation
- class textattack.transformations.composite_transformation.CompositeTransformation(transformations)[source]
Bases:
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
- class textattack.transformations.transformation.Transformation[source]
Bases:
ReprMixin
,ABC
An 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:
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:
Transformation
Transformation that randomly swaps the order of words in a sequence.
- property deterministic