docstr: Create mask for words to be perturbed.
  
  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 word being replaced.
  filling:
      Method to fill masked words. Either ``'parallel'`` or ``'autoregressive'``.
  frac_mask_templates
      Fraction of mask templates from the number of requested samples.
  **kwargs
      Other arguments to be passed to other methods.
  
  Returns
  -------
  raw
      Array with masked instances.
  data
      A `(num_samples, m)`-dimensional boolean array, where `m` is the number of tokens
      in the instance to be explained.
docstr_tok: ["Create","mask","for","words","to","be","perturbed",".","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","word","being","replaced",".","filling",":","Method","to","fill","masked","words",".","Either","``","'parallel","'","``","or","``","'autoregressive","'","``",".","frac_mask_templates","Fraction","of","mask","templates","from","the","number","of","requested","samples",".","*","*","kwargs","Other","arguments","to","be","passed","to","other","methods",".","Returns","--","--","--","-","raw","Array","with","masked","instances",".","data","A","`","(","num_samples",",","m",")","`","-dimensional","boolean","array",",","where","`","m","`","is","the","number","of","tokens","in","the","instance","to","be","explained","."]
code: def create_mask(
      self,
      anchor: tuple,
      num_samples: int,
      sample_proba: float = 1.0,
      filling: str = "parallel",
      frac_mask_templates: float = 0.1,
      **kwargs,
  ) -> Tuple[np.ndarray, np.ndarray]:
      """
      Create mask for words to be perturbed.
  
      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 word being replaced.
      filling:
          Method to fill masked words. Either ``'parallel'`` or ``'autoregressive'``.
      frac_mask_templates
          Fraction of mask templates from the number of requested samples.
      **kwargs
          Other arguments to be passed to other methods.
  
      Returns
      -------
      raw
          Array with masked instances.
      data
          A `(num_samples, m)`-dimensional boolean array, where `m` is the number of tokens
          in the instance to be explained.
      """
      # make sure that frac_mask_templates is in [0, 1]
      frac_mask_templates = np.clip(frac_mask_templates, 0, 1).item()
  
      # compute indices allowed be masked
      all_indices = range(len(self.ids_sample))
      allowed_indices = list(set(all_indices) - set(anchor))
  
      if (
          len(allowed_indices) == 0
          or filling == self.FILLING_AUTOREGRESSIVE
      ):
          # If the anchor covers all the words that can be perturbed (it can happen)
          # then the number of mask_templates should be equal to the number of sampled requested.
          # If the filling is autoregressive, just generate from the start a `num_sample`
          # masks, cause the computation performance is pretty similar.
          mask_templates = num_samples
      else:
          # If the probability of sampling a word is 1, then all words will be masked.
          # Thus there is no point in generating more than one mask.
          # Otherwise compute the number of masking templates according to the fraction
          # passed as argument and make sure that at least one mask template is generated
          mask_templates = (
              1
              if np.isclose(sample_proba, 1)
              else max(1, int(num_samples * frac_mask_templates))
          )
  
      # allocate memory
      data = np.ones(
          (mask_templates, len(self.ids_sample)), dtype=np.int32
      )
      raw = np.zeros(
          (mask_templates, len(self.head_tokens)),
          dtype=self.dtype_token,
      )
  
      # fill each row of the raw data matrix with the text instance to be explained
      raw[:] = self.head_tokens
  
      # create mask
      if len(allowed_indices):
          for i in range(mask_templates):
              # Here the sampling of the indices of the word to be masked is done by rows
              # and not by columns as in the other sampling methods. The reason is that
              # is much easier to ensure that at least one word in the sentence is masked.
              # If the sampling is performed over the columns it might be the case
              # that no word in a sentence will be masked.
              n_changed = max(
                  1,
                  np.random.binomial(
                      len(allowed_indices), sample_proba
                  ),
              )
              changed = np.random.choice(
                  allowed_indices, n_changed, replace=False
              )
  
              # mark the entrance as maks
              data[i, changed] = 0
  
              # Mask the corresponding words. This requires a mapping from indices
              # to the actual position of the words in the text
              changed_mapping = [self.ids_mapping[j] for j in changed]
              raw[i, changed_mapping] = self.model.mask
  
              # Have to remove the subwords of the masked word, which has to be done iteratively
              for j in changed_mapping:
                  self._remove_subwords(raw=raw, row=i, col=j, **kwargs)
  
      # join words
      raw = np.apply_along_axis(
          self._joiner, axis=1, arr=raw, dtype=self.dtype_sent
      )
      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 6 for calling the LanguageModelSampler obj's underlying member method code with example usage: obj.create_mask(anchor, num_samples, sample_proba, filling, frac_mask_templates) and returns: raw,  data