docstr: The function returns an `numpy` array of `num_samples` where randomly chosen features,
  except those in anchor, are replaced by words sampled according to the language
  model's predictions.
  
  Parameters
  ----------
  anchor:
      Indices represent the positions of the words to be kept unchanged.
  num_samples:
      Number of perturbed sentences to be returned.
  sample_proba:
      Probability of a token being replaced by a similar token.
  top_n:
      Used for top n sampling.
  batch_size_lm:
      Batch size used for language model.
  filling:
      Method to fill masked words. Either ``'parallel'`` or ``'autoregressive'``.
  **kwargs
      Other arguments to be passed to other methods.
  
  Returns
  -------
  raw
      Array containing `num_samples` elements. Each element is a perturbed sentence.
  data
      A `(num_samples, m)`-dimensional boolean array, where `m` is the number of tokens
      in the instance to be explained.
docstr_tok: ["The","function","returns","an","`","numpy","`","array","of","`","num_samples","`","where","randomly","chosen","features",",","except","those","in","anchor",",","are","replaced","by","words","sampled","according","to","the","language","model","'s","predictions",".","Parameters","--","--","--","--","--","anchor",":","Indices","represent","the","positions","of","the","words","to","be","kept","unchanged",".","num_samples",":","Number","of","perturbed","sentences","to","be","returned",".","sample_proba",":","Probability","of","a","token","being","replaced","by","a","similar","token",".","top_n",":","Used","for","top","n","sampling",".","batch_size_lm",":","Batch","size","used","for","language","model",".","filling",":","Method","to","fill","masked","words",".","Either","``","'parallel","'","``","or","``","'autoregressive","'","``",".","*","*","kwargs","Other","arguments","to","be","passed","to","other","methods",".","Returns","--","--","--","-","raw","Array","containing","`","num_samples","`","elements",".","Each","element","is","a","perturbed","sentence",".","data","A","`","(","num_samples",",","m",")","`","-dimensional","boolean","array",",","where","`","m","`","is","the","number","of","tokens","in","the","instance","to","be","explained","."]
code: def perturb_sentence(
      self,
      anchor: tuple,
      num_samples: int,
      sample_proba: float = 0.5,
      top_n: int = 100,
      batch_size_lm: int = 32,
      filling: str = "parallel",
      **kwargs,
  ) -> Tuple[np.ndarray, np.ndarray]:
      """
      The function returns an `numpy` array of `num_samples` where randomly chosen features,
      except those in anchor, are replaced by words sampled according to the language
      model's predictions.
  
      Parameters
      ----------
      anchor:
          Indices represent the positions of the words to be kept unchanged.
      num_samples:
          Number of perturbed sentences to be returned.
      sample_proba:
          Probability of a token being replaced by a similar token.
      top_n:
          Used for top n sampling.
      batch_size_lm:
          Batch size used for language model.
      filling:
          Method to fill masked words. Either ``'parallel'`` or ``'autoregressive'``.
      **kwargs
          Other arguments to be passed to other methods.
  
      Returns
      -------
      raw
          Array containing `num_samples` elements. Each element is a perturbed sentence.
      data
          A `(num_samples, m)`-dimensional boolean array, where `m` is the number of tokens
          in the instance to be explained.
      """
      # Create the mask
      raw, data = self.create_mask(
          anchor=anchor,
          num_samples=num_samples,
          sample_proba=sample_proba,
          filling=filling,
          **kwargs,
      )
  
      # If the anchor does not cover the entire sentence,
      # then fill in mask with language model
      if len(anchor) != len(self.ids_sample):
          raw, data = self.fill_mask(
              raw=raw,
              data=data,
              num_samples=num_samples,
              top_n=top_n,
              batch_size_lm=batch_size_lm,
              filling=filling,
              **kwargs,
          )
  
      # append tail if it exits
      raw = self._append_tail(raw) if self.tail else raw
      return raw, data
  
imports: import string
  from functools import partial
  from typing import Dict, List, Optional, Tuple
  import numpy
  import tensorflow
  from alibi.utils.lang_model import LanguageModel
  from alibi.explainers.anchors.text_samplers import AnchorTextSampler
label_desc: Use image node_id 5 for calling the LanguageModelSampler obj's underlying member method code with example usage: obj.perturb_sentence(anchor, num_samples, sample_proba, top_n, batch_size_lm, filling) and returns: raw,  data