textattack.goal_functions package¶
Goal Functions¶
Goal Functions determine if an attack has been successful.
GoalFunction Class¶
-
class
textattack.goal_functions.goal_function.
GoalFunction
(model_wrapper, maximizable=False, use_cache=True, query_budget=inf, model_batch_size=32, model_cache_size=1048576)[source]¶ Bases:
textattack.shared.utils.strings.ReprMixin
,abc.ABC
Evaluates how well a perturbed attacked_text object is achieving a specified goal.
Parameters: - model_wrapper (
ModelWrapper
) – The victim model to attack. - maximizable (
bool
, optional, defaults toFalse
) – Whether the goal function is maximizable, as opposed to a boolean result of success or failure. - query_budget (
float
, optional, defaults tofloat("in")
) – The maximum number of model queries allowed. - model_cache_size (
int
, optional, defaults to2**20
) – The maximum number of items to keep in the model results cache at once.
-
get_output
(attacked_text)[source]¶ Returns output for display based on the result of calling the model.
-
get_result
(attacked_text, **kwargs)[source]¶ A helper method that queries
self.get_results
with a singleAttackedText
object.
-
get_results
(attacked_text_list, check_skip=False)[source]¶ For each attacked_text object in attacked_text_list, returns a result consisting of whether or not the goal has been achieved, the output for display purposes, and a score.
Additionally returns whether the search is over due to the query budget.
- model_wrapper (