Attack Result API Reference

AttackResult

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

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.

SuccessfulAttackResult

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

The result of a successful attack.

FailedAttackResult

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

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.

SkippedAttackResult

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

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.

MaximizedAttackResult

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

The result of a successful attack.