textattack.goal_function_results package

Goal Function Result:

Goal function results report the result of a goal function evaluation, indicating whether an attack succeeded for a given example.

classification_goal_function_result

class textattack.goal_function_results.classification_goal_function_result.ClassificationGoalFunctionResult(attacked_text, raw_output, output, goal_status, score, num_queries, ground_truth_output)[source]

Bases: textattack.goal_function_results.goal_function_result.GoalFunctionResult

Represents the result of a classification goal function.

get_colored_output(color_method=None)[source]

Returns a string representation of this result’s output, colored according to color_method.

get_text_color_input()[source]

A string representing the color this result’s changed portion should be if it represents the original input.

get_text_color_perturbed()[source]

A string representing the color this result’s changed portion should be if it represents the perturbed input.

goal function result class

class textattack.goal_function_results.goal_function_result.GoalFunctionResult(attacked_text, raw_output, output, goal_status, score, num_queries, ground_truth_output)[source]

Bases: abc.ABC

Represents the result of a goal function evaluating a AttackedText object.

Parameters
  • attacked_text – The sequence that was evaluated.

  • output – The display-friendly output.

  • goal_status – The GoalFunctionResultStatus representing the status of the achievement of the goal.

  • score – A score representing how close the model is to achieving its goal.

  • num_queries – How many model queries have been used

  • ground_truth_output – The ground truth output

abstract get_colored_output(color_method=None)[source]

Returns a string representation of this result’s output, colored according to color_method.

abstract get_text_color_input()[source]

A string representing the color this result’s changed portion should be if it represents the original input.

abstract get_text_color_perturbed()[source]

A string representing the color this result’s changed portion should be if it represents the perturbed input.

class textattack.goal_function_results.goal_function_result.GoalFunctionResultStatus[source]

Bases: object

MAXIMIZING = 2
SEARCHING = 1
SKIPPED = 3
SUCCEEDED = 0

text2text goal function Result

class textattack.goal_function_results.text_to_text_goal_function_result.TextToTextGoalFunctionResult(attacked_text, raw_output, output, goal_status, score, num_queries, ground_truth_output)[source]

Bases: textattack.goal_function_results.goal_function_result.GoalFunctionResult

Represents the result of a text-to-text goal function.

get_colored_output(color_method=None)[source]

Returns a string representation of this result’s output, colored according to color_method.

get_text_color_input()[source]

A string representing the color this result’s changed portion should be if it represents the original input.

get_text_color_perturbed()[source]

A string representing the color this result’s changed portion should be if it represents the perturbed input.