class_docstr: An attack generates adversarial examples on text.
  
  An attack is comprised of a goal function, constraints, transformation, and a search method. Use :meth:`attack` method to attack one sample at a time.
  
  Args:
      goal_function (:class:`~textattack.goal_functions.GoalFunction`):
          A function for determining how well a perturbation is doing at achieving the attack's goal.
      constraints (list of :class:`~textattack.constraints.Constraint` or :class:`~textattack.constraints.PreTransformationConstraint`):
          A list of constraints to add to the attack, defining which perturbations are valid.
      transformation (:class:`~textattack.transformations.Transformation`):
          The transformation applied at each step of the attack.
      search_method (:class:`~textattack.search_methods.SearchMethod`):
          The method for exploring the search space of possible perturbations
      transformation_cache_size (:obj:`int`, `optional`, defaults to :obj:`2**15`):
          The number of items to keep in the transformations cache
      constraint_cache_size (:obj:`int`, `optional`, defaults to :obj:`2**15`):
          The number of items to keep in the constraints cache
  
  Example::
  
      >>> import textattack
      >>> import transformers
  
      >>> # Load model, tokenizer, and model_wrapper
      >>> model = transformers.AutoModelForSequenceClassification.from_pretrained("textattack/bert-base-uncased-imdb")
      >>> tokenizer = transformers.AutoTokenizer.from_pretrained("textattack/bert-base-uncased-imdb")
      >>> model_wrapper = textattack.models.wrappers.HuggingFaceModelWrapper(model, tokenizer)
  
      >>> # Construct our four components for `Attack`
      >>> from textattack.constraints.pre_transformation import RepeatModification, StopwordModification
      >>> from textattack.constraints.semantics import WordEmbeddingDistance
      >>> from textattack.transformations import WordSwapEmbedding
      >>> from textattack.search_methods import GreedyWordSwapWIR
  
      >>> goal_function = textattack.goal_functions.UntargetedClassification(model_wrapper)
      >>> constraints = [
      ...     RepeatModification(),
      ...     StopwordModification(),
      ...     WordEmbeddingDistance(min_cos_sim=0.9)
      ... ]
      >>> transformation = WordSwapEmbedding(max_candidates=50)
      >>> search_method = GreedyWordSwapWIR(wir_method="delete")
  
      >>> # Construct the actual attack
      >>> attack = textattack.Attack(goal_function, constraints, transformation, search_method)
  
      >>> input_text = "I really enjoyed the new movie that came out last month."
      >>> label = 1 #Positive
      >>> attack_result = attack.attack(input_text, label)
class_docstr_tok: ["An","attack","generates","adversarial","examples","on","text",".","An","attack","is","comprised","of","a","goal","function",",","constraints",",","transformation",",","and","a","search","method",".","Use",":","meth",":","`","attack","`","method","to","attack","one","sample","at","a","time",".","Args",":","goal_function","(",":","class",":","`","~textattack.goal_functions.GoalFunction","`",")",":","A","function","for","determining","how","well","a","perturbation","is","doing","at","achieving","the","attack","'s","goal",".","constraints","(","list","of",":","class",":","`","~textattack.constraints.Constraint","`","or",":","class",":","`","~textattack.constraints.PreTransformationConstraint","`",")",":","A","list","of","constraints","to","add","to","the","attack",",","defining","which","perturbations","are","valid",".","transformation","(",":","class",":","`","~textattack.transformations.Transformation","`",")",":","The","transformation","applied","at","each","step","of","the","attack",".","search_method","(",":","class",":","`","~textattack.search_methods.SearchMethod","`",")",":","The","method","for","exploring","the","search","space","of","possible","perturbations","transformation_cache_size","(",":","obj",":","`","int","`",",","`","optional","`",",","defaults","to",":","obj",":","`","2","*","*","15","`",")",":","The","number","of","items","to","keep","in","the","transformations","cache","constraint_cache_size","(",":","obj",":","`","int","`",",","`","optional","`",",","defaults","to",":","obj",":","`","2","*","*","15","`",")",":","The","number","of","items","to","keep","in","the","constraints","cache","Example",":",":",">",">",">","import","textattack",">",">",">","import","transformers",">",">",">","#","Load","model",",","tokenizer",",","and","model_wrapper",">",">",">","model","=","transformers.AutoModelForSequenceClassification.from_pretrained","(","``","textattack\/bert-base-uncased-imdb","''",")",">",">",">","tokenizer","=","transformers.AutoTokenizer.from_pretrained","(","``","textattack\/bert-base-uncased-imdb","''",")",">",">",">","model_wrapper","=","textattack.models.wrappers.HuggingFaceModelWrapper","(","model",",","tokenizer",")",">",">",">","#","Construct","our","four","components","for","`","Attack","`",">",">",">","from","textattack.constraints.pre_transformation","import","RepeatModification",",","StopwordModification",">",">",">","from","textattack.constraints.semantics","import","WordEmbeddingDistance",">",">",">","from","textattack.transformations","import","WordSwapEmbedding",">",">",">","from","textattack.search_methods","import","GreedyWordSwapWIR",">",">",">","goal_function","=","textattack.goal_functions.UntargetedClassification","(","model_wrapper",")",">",">",">","constraints","=","[","...","RepeatModification","(",")",",","...","StopwordModification","(",")",",","...","WordEmbeddingDistance","(","min_cos_sim=0.9",")","...","]",">",">",">","transformation","=","WordSwapEmbedding","(","max_candidates=50",")",">",">",">","search_method","=","GreedyWordSwapWIR","(","wir_method=","''","delete","''",")",">",">",">","#","Construct","the","actual","attack",">",">",">","attack","=","textattack.Attack","(","goal_function",",","constraints",",","transformation",",","search_method",")",">",">",">","input_text","=","``","I","really","enjoyed","the","new","movie","that","came","out","last","month",".","''",">",">",">","label","=","1","#","Positive",">",">",">","attack_result","=","attack.attack","(","input_text",",","label",")"]
docstr: Attack a single example.
  
  Args:
      example (:obj:`str`, :obj:`OrderedDict[str, str]` or :class:`~textattack.shared.AttackedText`):
          Example to attack. It can be a single string or an `OrderedDict` where
          keys represent the input fields (e.g. "premise", "hypothesis") and the values are the actual input textx.
          Also accepts :class:`~textattack.shared.AttackedText` that wraps around the input.
      ground_truth_output(:obj:`int`, :obj:`float` or :obj:`str`):
          Ground truth output of `example`.
          For classification tasks, it should be an integer representing the ground truth label.
          For regression tasks (e.g. STS), it should be the target value.
          For seq2seq tasks (e.g. translation), it should be the target string.
  Returns:
      :class:`~textattack.attack_results.AttackResult` that represents the result of the attack.
docstr_tok: ["Attack","a","single","example",".","Args",":","example","(",":","obj",":","`","str","`",",",":","obj",":","`","OrderedDict","[","str",",","str","]","`","or",":","class",":","`","~textattack.shared.AttackedText","`",")",":","Example","to","attack",".","It","can","be","a","single","string","or","an","`","OrderedDict","`","where","keys","represent","the","input","fields","(","e.g",".","``","premise","''",",","``","hypothesis","''",")","and","the","values","are","the","actual","input","textx",".","Also","accepts",":","class",":","`","~textattack.shared.AttackedText","`","that","wraps","around","the","input",".","ground_truth_output","(",":","obj",":","`","int","`",",",":","obj",":","`","float","`","or",":","obj",":","`","str","`",")",":","Ground","truth","output","of","`","example","`",".","For","classification","tasks",",","it","should","be","an","integer","representing","the","ground","truth","label",".","For","regression","tasks","(","e.g",".","STS",")",",","it","should","be","the","target","value",".","For","seq2seq","tasks","(","e.g",".","translation",")",",","it","should","be","the","target","string",".","Returns",":",":","class",":","`","~textattack.attack_results.AttackResult","`","that","represents","the","result","of","the","attack","."]
code: def attack(self, example, ground_truth_output):
      """Attack a single example.
  
      Args:
          example (:obj:`str`, :obj:`OrderedDict[str, str]` or :class:`~textattack.shared.AttackedText`):
              Example to attack. It can be a single string or an `OrderedDict` where
              keys represent the input fields (e.g. "premise", "hypothesis") and the values are the actual input textx.
              Also accepts :class:`~textattack.shared.AttackedText` that wraps around the input.
          ground_truth_output(:obj:`int`, :obj:`float` or :obj:`str`):
              Ground truth output of `example`.
              For classification tasks, it should be an integer representing the ground truth label.
              For regression tasks (e.g. STS), it should be the target value.
              For seq2seq tasks (e.g. translation), it should be the target string.
      Returns:
          :class:`~textattack.attack_results.AttackResult` that represents the result of the attack.
      """
      assert isinstance(
          example, (str, OrderedDict, AttackedText)
      ), "`example` must either be `str`, `collections.OrderedDict`, `textattack.shared.AttackedText`."
      if isinstance(example, (str, OrderedDict)):
          example = AttackedText(example)
  
      assert isinstance(
          ground_truth_output, (int, str)
      ), "`ground_truth_output` must either be `str` or `int`."
      goal_function_result, _ = self.goal_function.init_attack_example(
          example, ground_truth_output
      )
      if (
          goal_function_result.goal_status
          == GoalFunctionResultStatus.SKIPPED
      ):
          return SkippedAttackResult(goal_function_result)
      else:
          result = self._attack(goal_function_result)
          return result
  
imports: from collections import OrderedDict
  from typing import List, Union
  import lru
  import torch
  import textattack
  from textattack.attack_results import FailedAttackResult, MaximizedAttackResult, SkippedAttackResult, SuccessfulAttackResult
  from textattack.constraints import Constraint, PreTransformationConstraint
  from textattack.goal_function_results import GoalFunctionResultStatus
  from textattack.goal_functions import GoalFunction
  from textattack.models.wrappers import ModelWrapper
  from textattack.search_methods import SearchMethod
  from textattack.shared import AttackedText, utils
  from textattack.transformations import CompositeTransformation, Transformation
label_desc: Use image node_id 11 for calling the Attack obj's underlying member method code with example usage: obj.attack(example, ground_truth_output) and returns: SkippedAttackResult, result