docstr: Initialize similarity sampler. This sampler replaces words with similar words.
  
  Parameters
  ----------
  nlp
      `spaCy` object.
  perturb_opts
      Perturbation options.
docstr_tok: ["Initialize","similarity","sampler",".","This","sampler","replaces","words","with","similar","words",".","Parameters","--","--","--","--","--","nlp","`","spaCy","`","object",".","perturb_opts","Perturbation","options","."]
code: def __init__(
      self, nlp: "spacy.language.Language", perturb_opts: Dict
  ):
      """
      Initialize similarity sampler. This sampler replaces words with similar words.
  
      Parameters
      ----------
      nlp
          `spaCy` object.
      perturb_opts
          Perturbation options.
  
      """
      super().__init__()
  
      # set nlp and perturbation options
      self.nlp = load_spacy_lexeme_prob(nlp)
      self.perturb_opts = perturb_opts
  
      # define synonym generator
      self._synonyms_generator = Neighbors(self.nlp)
  
      # dict containing an np.array of similar words with same part of speech and an np.array of similarities
      self.synonyms: Dict[str, Dict[str, np.ndarray]] = {}
      self.tokens: "spacy.tokens.Doc"
      self.words: List[str] = []
      self.positions: List[int] = []
      self.punctuation: List["spacy.tokens.Token"] = []
  
imports: import logging
  from abc import abstractmethod
  from typing import TYPE_CHECKING, Dict, List, Optional, Tuple, Union
  import numpy
  import spacy
label_desc: Use image node_id 1 to create a new SimilaritySampler object from inherited base classes: AnchorTextSampler with example: obj = SimilaritySampler(nlp, perturb_opts)