textattack.goal_functions.text package

Goal Function for Text to Text case

Goal Function for Attempts to minimize the BLEU score

class textattack.goal_functions.text.minimize_bleu.MinimizeBleu(*args, target_bleu=0.0, **kwargs)[source]

Bases: TextToTextGoalFunction

Attempts to minimize the BLEU score between the current output translation and the reference translation.

BLEU score was defined in (BLEU: a Method for Automatic Evaluation of Machine Translation).

ArxivURL

This goal function is defined in (It’s Morphin’ Time! Combating Linguistic Discrimination with Inflectional Perturbations).

ArxivURL2

clear_cache()[source]
extra_repr_keys()[source]

Extra fields to be included in the representation of a class.

EPS = 1e-10
textattack.goal_functions.text.minimize_bleu.get_bleu(a, b)[source]

Goal Function for seq2sick

class textattack.goal_functions.text.non_overlapping_output.NonOverlappingOutput(model_wrapper, maximizable=False, use_cache=True, query_budget=inf, model_batch_size=32, model_cache_size=1048576)[source]

Bases: TextToTextGoalFunction

Ensures that none of the words at a position are equal.

Defined in seq2sick (https://arxiv.org/pdf/1803.01128.pdf), equation (3).

clear_cache()[source]
textattack.goal_functions.text.non_overlapping_output.get_words_cached(s)[source]
textattack.goal_functions.text.non_overlapping_output.word_difference_score(s1, s2)[source]

Returns the number of words that are non-overlapping between s1 and s2.

Goal Function for TextToText

class textattack.goal_functions.text.text_to_text_goal_function.TextToTextGoalFunction(model_wrapper, maximizable=False, use_cache=True, query_budget=inf, model_batch_size=32, model_cache_size=1048576)[source]

Bases: GoalFunction

A goal function defined on a model that outputs text.

model: The PyTorch or TensorFlow model used for evaluation. original_output: the original output of the model