textattack.goal_functions package
Goal Functions
Goal Functions determine if an attack has been successful.
Subpackages
- textattack.goal_functions.classification package
- Goal fucntion for Classification
- Submodules
- Determine for if an attack has been successful in Classification
ClassificationGoalFunction- Determine if an attack has been successful in Hard Label Classficiation.
HardLabelClassification- Determine if maintaining the same predicted label (input reduction)
InputReduction- Determine if an attack has been successful in targeted Classification
TargetedClassification- Determine successful in untargeted Classification
UntargetedClassification
- textattack.goal_functions.custom package
- textattack.goal_functions.text package
Submodules
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, allow_skip=True)[source]
Bases:
ReprMixin,ABCEvaluates 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_resultswith a singleAttackedTextobject.
- 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.