Source code for textattack.search_methods.beam_search

Beam Search

import numpy as np

from textattack.goal_function_results import GoalFunctionResultStatus
from textattack.search_methods import SearchMethod

[docs]class BeamSearch(SearchMethod): """An attack that maintains a beam of the `beam_width` highest scoring AttackedTexts, greedily updating the beam with the highest scoring transformations from the current beam. Args: goal_function: A function for determining how well a perturbation is doing at achieving the attack's goal. transformation: The type of transformation. beam_width (int): the number of candidates to retain at each step """ def __init__(self, beam_width=8): self.beam_width = beam_width @property def is_black_box(self): return True
[docs] def extra_repr_keys(self): return ["beam_width"]