docstr: Perturb the text instance to be explained.
  
  Parameters
  ----------
  present
      Word index in the text for the words in the proposed anchor.
  n
      Number of samples used when sampling from the corpus.
  sample_proba
      Sample probability for a word if `use_proba=False`.
  forbidden
      Forbidden lemmas.
  forbidden_tags
      Forbidden POS tags.
  forbidden_words
      Forbidden words.
  pos
      POS that can be changed during perturbation.
  use_proba
      Bool whether to sample according to a similarity score with the corpus embeddings.
  temperature
      Sample weight hyper-parameter if ``use_proba=True``.
  **kwargs
      Other arguments. Not used.
  
  Returns
  -------
  raw
      Array of perturbed text instances.
  data
      Matrix with 1s and 0s indicating whether a word in the text has not been perturbed for each sample.
docstr_tok: ["Perturb","the","text","instance","to","be","explained",".","Parameters","--","--","--","--","--","present","Word","index","in","the","text","for","the","words","in","the","proposed","anchor",".","n","Number","of","samples","used","when","sampling","from","the","corpus",".","sample_proba","Sample","probability","for","a","word","if","`","use_proba=False","`",".","forbidden","Forbidden","lemmas",".","forbidden_tags","Forbidden","POS","tags",".","forbidden_words","Forbidden","words",".","pos","POS","that","can","be","changed","during","perturbation",".","use_proba","Bool","whether","to","sample","according","to","a","similarity","score","with","the","corpus","embeddings",".","temperature","Sample","weight","hyper-parameter","if","``","use_proba=True","``",".","*","*","kwargs","Other","arguments",".","Not","used",".","Returns","--","--","--","-","raw","Array","of","perturbed","text","instances",".","data","Matrix","with","1s","and","0s","indicating","whether","a","word","in","the","text","has","not","been","perturbed","for","each","sample","."]
code: def perturb_sentence_similarity(
      self,
      present: tuple,
      n: int,
      sample_proba: float = 0.5,
      forbidden: frozenset = frozenset(),
      forbidden_tags: frozenset = frozenset(["PRP$"]),
      forbidden_words: frozenset = frozenset(["be"]),
      temperature: float = 1.0,
      pos: frozenset = frozenset(
          ["NOUN", "VERB", "ADJ", "ADV", "ADP", "DET"]
      ),
      use_proba: bool = False,
      **kwargs,
  ) -> Tuple[np.ndarray, np.ndarray]:
      """
      Perturb the text instance to be explained.
  
      Parameters
      ----------
      present
          Word index in the text for the words in the proposed anchor.
      n
          Number of samples used when sampling from the corpus.
      sample_proba
          Sample probability for a word if `use_proba=False`.
      forbidden
          Forbidden lemmas.
      forbidden_tags
          Forbidden POS tags.
      forbidden_words
          Forbidden words.
      pos
          POS that can be changed during perturbation.
      use_proba
          Bool whether to sample according to a similarity score with the corpus embeddings.
      temperature
          Sample weight hyper-parameter if ``use_proba=True``.
      **kwargs
          Other arguments. Not used.
  
      Returns
      -------
      raw
          Array of perturbed text instances.
      data
          Matrix with 1s and 0s indicating whether a word in the text has not been perturbed for each sample.
      """
      # allocate memory for the binary mask and the perturbed instances
      raw = np.zeros((n, len(self.tokens)), self.dtype)
      data = np.ones((n, len(self.tokens)))
  
      # fill each row of the raw data matrix with the text to be explained
      raw[:] = [x.text for x in self.tokens]
  
      for i, t in enumerate(
          self.tokens
      ):  # apply sampling to each token
          # if the word is part of the anchor, move on to next token
          if i in present:
              continue
  
          # check that token does not fall in any forbidden category
          if (
              t.text not in forbidden_words
              and t.pos_ in pos
              and t.lemma_ not in forbidden
              and t.tag_ not in forbidden_tags
          ):
              t_neighbors = self.synonyms[t.text]["words"]
              # no neighbours with the same tag or word not in spaCy vocabulary
              if t_neighbors.size == 0:
                  continue
  
              n_changed = np.random.binomial(n, sample_proba)
              changed = np.random.choice(n, n_changed, replace=False)
  
              if (
                  use_proba
              ):  # use similarity scores to sample changed tokens
                  weights = self.synonyms[t.text]["similarities"]
                  weights = np.exp(
                      weights / temperature
                  )  # weighting by temperature (check previous implementation)
                  weights = weights / sum(weights)
              else:
                  weights = np.ones((t_neighbors.shape[0],))
                  weights /= t_neighbors.shape[0]
  
              raw[changed, i] = np.random.choice(
                  t_neighbors, n_changed, p=weights, replace=True
              )
              data[changed, i] = 0
  
      raw = np.apply_along_axis(
          self._joiner, axis=1, arr=raw, dtype=self.dtype
      )
      return raw, data
  
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 5 for calling the SimilaritySampler obj's underlying member method code with example usage: obj.perturb_sentence_similarity(present, n, sample_proba, forbidden, forbidden_tags, forbidden_words, temperature, pos, use_proba) and returns: raw,  data