class_docstr: Li, Zhang, Peng, Chen, Brockett, Sun, Dolan.
  
  "Contextualized Perturbation for Textual Adversarial Attack" (Li et
  al., 2020)
  
  https://arxiv.org/abs/2009.07502
  
  CLARE builds on a pre-trained masked language model and modifies the inputs in a contextaware manner.
  We propose three contextualized perturbations, Replace, Insert and Merge, allowing for generating outputs
  of varied lengths.
class_docstr_tok: ["Li",",","Zhang",",","Peng",",","Chen",",","Brockett",",","Sun",",","Dolan",".","``","Contextualized","Perturbation","for","Textual","Adversarial","Attack","''","(","Li","et","al.",",","2020",")","https",":","\/\/arxiv.org\/abs\/2009.07502","CLARE","builds","on","a","pre-trained","masked","language","model","and","modifies","the","inputs","in","a","contextaware","manner",".","We","propose","three","contextualized","perturbations",",","Replace",",","Insert","and","Merge",",","allowing","for","generating","outputs","of","varied","lengths","."]
code: def __init__(
      self,
      model="distilroberta-base",
      tokenizer="distilroberta-base",
      **kwargs,
  ):
      import transformers
  
      from textattack.transformations import (
          CompositeTransformation,
          WordInsertionMaskedLM,
          WordMergeMaskedLM,
          WordSwapMaskedLM,
      )
  
      shared_masked_lm = (
          transformers.AutoModelForCausalLM.from_pretrained(model)
      )
      shared_tokenizer = transformers.AutoTokenizer.from_pretrained(
          tokenizer
      )
  
      transformation = CompositeTransformation(
          [
              WordSwapMaskedLM(
                  method="bae",
                  masked_language_model=shared_masked_lm,
                  tokenizer=shared_tokenizer,
                  max_candidates=50,
                  min_confidence=5e-4,
              ),
              WordInsertionMaskedLM(
                  masked_language_model=shared_masked_lm,
                  tokenizer=shared_tokenizer,
                  max_candidates=50,
                  min_confidence=0.0,
              ),
              WordMergeMaskedLM(
                  masked_language_model=shared_masked_lm,
                  tokenizer=shared_tokenizer,
                  max_candidates=50,
                  min_confidence=5e-3,
              ),
          ]
      )
  
      use_constraint = UniversalSentenceEncoder(
          threshold=0.7,
          metric="cosine",
          compare_against_original=True,
          window_size=15,
          skip_text_shorter_than_window=True,
      )
  
      constraints = DEFAULT_CONSTRAINTS + [use_constraint]
  
      super().__init__(
          transformation, constraints=constraints, **kwargs
      )
  
imports: import random
  from textattack.constraints.pre_transformation import RepeatModification, StopwordModification
  from textattack.constraints.semantics.sentence_encoders import UniversalSentenceEncoder
  from .None import Augmenter
label_desc: Use image node_id 1 to create a new CLAREAugmenter object from inherited base classes: Augmenter with example: obj = CLAREAugmenter(model, tokenizer)