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: Filters a list of potential transformed texts based on
  ``self.constraints``
  
  Args:
      transformed_texts: A list of candidate transformed ``AttackedText`` to filter.
      current_text: The current ``AttackedText`` on which the transformation was applied.
      original_text: The original ``AttackedText`` from which the attack started.
docstr_tok: ["Filters","a","list","of","potential","transformed","texts","based","on","``","self.constraints","``","Args",":","transformed_texts",":","A","list","of","candidate","transformed","``","AttackedText","``","to","filter",".","current_text",":","The","current","``","AttackedText","``","on","which","the","transformation","was","applied",".","original_text",":","The","original","``","AttackedText","``","from","which","the","attack","started","."]
code: def _filter_transformations_uncached(
      self, transformed_texts, current_text, original_text=None
  ):
      """Filters a list of potential transformed texts based on
      ``self.constraints``
  
      Args:
          transformed_texts: A list of candidate transformed ``AttackedText`` to filter.
          current_text: The current ``AttackedText`` on which the transformation was applied.
          original_text: The original ``AttackedText`` from which the attack started.
      """
      filtered_texts = transformed_texts[:]
      for C in self.constraints:
          if len(filtered_texts) == 0:
              break
          if C.compare_against_original:
              if not original_text:
                  raise ValueError(
                      f"Missing `original_text` argument when constraint {type(C)} is set to compare against `original_text`"
                  )
  
              filtered_texts = C.call_many(
                  filtered_texts, original_text
              )
          else:
              filtered_texts = C.call_many(filtered_texts, current_text)
      # Default to false for all original transformations.
      for original_transformed_text in transformed_texts:
          self.constraints_cache[
              (current_text, original_transformed_text)
          ] = False
      # Set unfiltered transformations to True in the cache.
      for filtered_text in filtered_texts:
          self.constraints_cache[(current_text, filtered_text)] = True
      return filtered_texts
  
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 8 for calling the Attack obj's underlying member method code with example usage: obj._filter_transformations_uncached(transformed_texts, current_text, original_text) and returns: filtered_texts