class_docstr: An attack generates adversarial examples on text.
  
  This is an abstract class that contains main helper functionality for
  attacks. An attack is comprised of a search method, goal function,
  a transformation, and a set of one or more linguistic constraints that
  successful examples must meet.
class_docstr_tok: ["An","attack","generates","adversarial","examples","on","text",".","This","is","an","abstract","class","that","contains","main","helper","functionality","for","attacks",".","An","attack","is","comprised","of","a","search","method",",","goal","function",",","a","transformation",",","and","a","set","of","one","or","more","linguistic","constraints","that","successful","examples","must","meet","."]
docstr: Initialize an attack object. Attacks can be run multiple times.
  
  :param goal_function: A function for determining how well a perturbation
      is doing at achieving the attack's goal.
  :param constraints: A list of constraints to add to the attack, defining
      which perturbations are valid.
  :param transformation: The transformation applied at each step of the
      attack.
  :param search_method: A strategy for exploring the search space of
      possible perturbations
  :param transformation_cache_size: the number of items to keep in the
      transformations cache
  :param constraint_cache_size: the number of items to keep in the
      constraints cache
docstr_tok: ["Initialize","an","attack","object",".","Attacks","can","be","run","multiple","times",".",":","param","goal_function",":","A","function","for","determining","how","well","a","perturbation","is","doing","at","achieving","the","attack","'s","goal",".",":","param","constraints",":","A","list","of","constraints","to","add","to","the","attack",",","defining","which","perturbations","are","valid",".",":","param","transformation",":","The","transformation","applied","at","each","step","of","the","attack",".",":","param","search_method",":","A","strategy","for","exploring","the","search","space","of","possible","perturbations",":","param","transformation_cache_size",":","the","number","of","items","to","keep","in","the","transformations","cache",":","param","constraint_cache_size",":","the","number","of","items","to","keep","in","the","constraints","cache"]
code: def __init__(
      self,
      goal_function=None,
      constraints=[],
      transformation=None,
      search_method=None,
      transformation_cache_size=2**15,
      constraint_cache_size=2**15,
  ):
      """
      Initialize an attack object. Attacks can be run multiple times.
  
      :param goal_function: A function for determining how well a perturbation
          is doing at achieving the attack's goal.
      :param constraints: A list of constraints to add to the attack, defining
          which perturbations are valid.
      :param transformation: The transformation applied at each step of the
          attack.
      :param search_method: A strategy for exploring the search space of
          possible perturbations
      :param transformation_cache_size: the number of items to keep in the
          transformations cache
      :param constraint_cache_size: the number of items to keep in the
          constraints cache
      """
      self.goal_function = goal_function
      if not self.goal_function:
          raise NameError(
              "Cannot instantiate attack without self.goal_function for "
              "predictions"
          )
      self.search_method = search_method
      if not self.search_method:
          raise NameError(
              "Cannot instantiate attack without search method"
          )
      self.transformation = transformation
      if not self.transformation:
          raise NameError(
              "Cannot instantiate attack without transformation"
          )
      self.is_black_box = (
          getattr(transformation, "is_black_box", True)
          and search_method.is_black_box
      )
  
      if not self.search_method.check_transformation_compatibility(
          self.transformation
      ):
          raise ValueError(
              f"SearchMethod {self.search_method} incompatible with "
              f"transformation {self.transformation}"
          )
  
      self.constraints = []
      self.pre_transformation_constraints = []
      for constraint in constraints:
          if isinstance(
              constraint,
              textattack.constraints.PreTransformationConstraint,
          ):
              self.pre_transformation_constraints.append(constraint)
          else:
              self.constraints.append(constraint)
  
      # Check if we can use transformation cache for our transformation.
      if not self.transformation.deterministic:
          self.use_transformation_cache = False
      elif isinstance(self.transformation, CompositeTransformation):
          self.use_transformation_cache = True
          for t in self.transformation.transformations:
              if not t.deterministic:
                  self.use_transformation_cache = False
                  break
      else:
          self.use_transformation_cache = True
      self.transformation_cache_size = transformation_cache_size
      self.transformation_cache = lru.LRU(transformation_cache_size)
  
      self.constraint_cache_size = constraint_cache_size
      self.constraints_cache = lru.LRU(constraint_cache_size)
  
imports: import lru
  from collections import deque
  from ...common import logger
  from textattack.attack_results import FailedAttackResult, MaximizedAttackResult, SuccessfulAttackResult
  from textattack.goal_function_results import GoalFunctionResultStatus
  from textattack.shared import AttackedText, utils
  from textattack.transformations import CompositeTransformation
label_desc: Use image node_id 1 to create a new Attack object  with example: obj = Attack(goal_function, constraints, transformation, search_method, transformation_cache_size, constraint_cache_size)