Calls the ``SearchMethod`` to perturb the ``AttackedText`` stored in ``initial_result``. Args: initial_result: The initial ``GoalFunctionResult`` from which to perturb. Returns: A ``SuccessfulAttackResult``, ``FailedAttackResult``, or
(self, initial_result)
| 385 | return filtered_texts |
| 386 | |
| 387 | def _attack(self, initial_result): |
| 388 | """Calls the ``SearchMethod`` to perturb the ``AttackedText`` stored in |
| 389 | ``initial_result``. |
| 390 | |
| 391 | Args: |
| 392 | initial_result: The initial ``GoalFunctionResult`` from which to perturb. |
| 393 | |
| 394 | Returns: |
| 395 | A ``SuccessfulAttackResult``, ``FailedAttackResult``, |
| 396 | or ``MaximizedAttackResult``. |
| 397 | """ |
| 398 | final_result = self.search_method(initial_result) |
| 399 | self.clear_cache() |
| 400 | if final_result.goal_status == GoalFunctionResultStatus.SUCCEEDED: |
| 401 | result = SuccessfulAttackResult( |
| 402 | initial_result, |
| 403 | final_result, |
| 404 | ) |
| 405 | elif final_result.goal_status == GoalFunctionResultStatus.SEARCHING: |
| 406 | result = FailedAttackResult( |
| 407 | initial_result, |
| 408 | final_result, |
| 409 | ) |
| 410 | elif final_result.goal_status == GoalFunctionResultStatus.MAXIMIZING: |
| 411 | result = MaximizedAttackResult( |
| 412 | initial_result, |
| 413 | final_result, |
| 414 | ) |
| 415 | else: |
| 416 | raise ValueError(f"Unrecognized goal status {final_result.goal_status}") |
| 417 | return result |
| 418 | |
| 419 | def attack(self, example, ground_truth_output): |
| 420 | """Attack a single example. |
no test coverage detected