class_docstr: Generate potential insertion for a word using a masked language model.
  
  Based off of:
  CLARE: Contextualized Perturbation for Textual Adversarial Attack" (Li et al, 2020):
  https://arxiv.org/abs/2009.07502
  
  Args:
      masked_language_model (Union[str|transformers.AutoModelForMaskedLM]): Either the name of pretrained masked language model from `transformers` model hub
          or the actual model. Default is `bert-base-uncased`.
      tokenizer (obj): The tokenizer of the corresponding model. If you passed in name of a pretrained model for `masked_language_model`,
          you can skip this argument as the correct tokenizer can be infered from the name. However, if you're passing the actual model, you must
          provide a tokenizer.
      max_length (int): the max sequence length the masked language model is designed to work with. Default is 512.
      window_size (int): The number of surrounding words to include when making top word prediction.
          For each position to insert we take `window_size // 2` words to the left and `window_size // 2` words to the right and pass the text within the window
          to the masked language model. Default is `float("inf")`, which is equivalent to using the whole text.
      max_candidates (int): maximum number of candidates to consider inserting for each position. Replacements are
          ranked by model's confidence.
      min_confidence (float): minimum confidence threshold each new word must pass.
code: def __init__(
      self,
      masked_language_model="bert-base-uncased",
      tokenizer=None,
      max_length=512,
      window_size=float("inf"),
      max_candidates=50,
      min_confidence=5e-4,
      batch_size=16,
  ):
      super().__init__()
      self.max_length = max_length
      self.window_size = window_size
      self.max_candidates = max_candidates
      self.min_confidence = min_confidence
      self.batch_size = batch_size
  
      if isinstance(masked_language_model, str):
          self._language_model = AutoModelForMaskedLM.from_pretrained(
              masked_language_model
          )
          self._lm_tokenizer = AutoTokenizer.from_pretrained(
              masked_language_model, use_fast=True
          )
      else:
          self._language_model = masked_language_model
          if tokenizer is None:
              raise ValueError(
                  "`tokenizer` argument must be provided when passing an actual model as `masked_language_model`."
              )
          self._lm_tokenizer = tokenizer
      self._language_model.to(utils.device)
      self._language_model.eval()
      self.masked_lm_name = self._language_model.__class__.__name__
  
file_path: TextAttack/textattack/transformations/word_insertions/word_insertion_masked_lm.py
imports: import re
  import torch
  from transformers import AutoModelForMaskedLM, AutoTokenizer
  from textattack.shared import utils
  from .word_insertion import WordInsertion
label_desc: Use image node_id 1 to create a new WordInsertionMaskedLM object from inherited base classes: WordInsertion with example: obj = WordInsertionMaskedLM(masked_language_model, tokenizer, max_length, window_size, max_candidates, min_confidence, batch_size)