textattack.transformations package


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.

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.


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