textattack.attack_results package

class textattack.attack_results.attack_result.AttackResult(original_result, perturbed_result)[source]

Bases: abc.ABC

Result of an Attack run on a single (output, text_input) pair.

Parameters
  • original_result (GoalFunctionResult) – Result of the goal function applied to the original text

  • perturbed_result (GoalFunctionResult) – Result of the goal function applied to the perturbed text. May or may not have been successful.

diff_color(color_method=None)[source]

Highlights the difference between two texts using color.

Has to account for deletions and insertions from original text to perturbed. Relies on the index map stored in self.original_result.attacked_text.attack_attrs["original_index_map"].

goal_function_result_str(color_method=None)[source]

Returns a string illustrating the results of the goal function.

original_text(color_method=None)[source]

Returns the text portion of self.original_result.

Helper method.

perturbed_text(color_method=None)[source]

Returns the text portion of self.perturbed_result.

Helper method.

str_lines(color_method=None)[source]

A list of the lines to be printed for this result’s string representation.

class textattack.attack_results.failed_attack_result.FailedAttackResult(original_result, perturbed_result=None)[source]

Bases: textattack.attack_results.attack_result.AttackResult

The result of a failed attack.

goal_function_result_str(color_method=None)[source]

Returns a string illustrating the results of the goal function.

str_lines(color_method=None)[source]

A list of the lines to be printed for this result’s string representation.

class textattack.attack_results.maximized_attack_result.MaximizedAttackResult(original_result, perturbed_result)[source]

Bases: textattack.attack_results.attack_result.AttackResult

The result of a successful attack.

class textattack.attack_results.skipped_attack_result.SkippedAttackResult(original_result)[source]

Bases: textattack.attack_results.attack_result.AttackResult

The result of a skipped attack.

goal_function_result_str(color_method=None)[source]

Returns a string illustrating the results of the goal function.

str_lines(color_method=None)[source]

A list of the lines to be printed for this result’s string representation.

class textattack.attack_results.successful_attack_result.SuccessfulAttackResult(original_result, perturbed_result)[source]

Bases: textattack.attack_results.attack_result.AttackResult

The result of a successful attack.