docstr: Generate perturbed samples while maintaining features in positions specified in
  anchor unchanged.
  
  Parameters
  ----------
  anchor
       - ``int`` - the position of the anchor in the input batch.
  
       - ``tuple`` - the anchor itself, a list of words to be kept unchanged.
  
  num_samples
      Number of generated perturbed samples.
  compute_labels
      If ``True``, an array of comparisons between predictions on perturbed samples and
      instance to be explained is returned.
  
  Returns
  -------
  If ``compute_labels=True``, a list containing the following is returned
  
   - `covered_true` - perturbed examples where the anchor applies and the model prediction          on perturbation is the same as the instance prediction.
  
   - `covered_false` - perturbed examples where the anchor applies and the model prediction          is NOT the same as the instance prediction.
  
   - `labels` - num_samples ints indicating whether the prediction on the perturbed sample          matches (1) the label of the instance to be explained or not (0).
  
   - `data` - Matrix with 1s and 0s indicating whether a word in the text has been perturbed for each sample.
  
   - `-1.0` - indicates exact coverage is not computed for this algorithm.
  
   - `anchor[0]` - position of anchor in the batch request.
  
  Otherwise, a list containing the data matrix only is returned.
docstr_tok: ["Generate","perturbed","samples","while","maintaining","features","in","positions","specified","in","anchor","unchanged",".","Parameters","--","--","--","--","--","anchor","-","``","int","``","-","the","position","of","the","anchor","in","the","input","batch",".","-","``","tuple","``","-","the","anchor","itself",",","a","list","of","words","to","be","kept","unchanged",".","num_samples","Number","of","generated","perturbed","samples",".","compute_labels","If","``","True","``",",","an","array","of","comparisons","between","predictions","on","perturbed","samples","and","instance","to","be","explained","is","returned",".","Returns","--","--","--","-","If","``","compute_labels=True","``",",","a","list","containing","the","following","is","returned","-","`","covered_true","`","-","perturbed","examples","where","the","anchor","applies","and","the","model","prediction","on","perturbation","is","the","same","as","the","instance","prediction",".","-","`","covered_false","`","-","perturbed","examples","where","the","anchor","applies","and","the","model","prediction","is","NOT","the","same","as","the","instance","prediction",".","-","`","labels","`","-","num_samples","ints","indicating","whether","the","prediction","on","the","perturbed","sample","matches","(","1",")","the","label","of","the","instance","to","be","explained","or","not","(","0",")",".","-","`","data","`","-","Matrix","with","1s","and","0s","indicating","whether","a","word","in","the","text","has","been","perturbed","for","each","sample",".","-","`","-1.0","`","-","indicates","exact","coverage","is","not","computed","for","this","algorithm",".","-","`","anchor","[","0","]","`","-","position","of","anchor","in","the","batch","request",".","Otherwise",",","a","list","containing","the","data","matrix","only","is","returned","."]
code: def sampler(
      self,
      anchor: Tuple[int, tuple],
      num_samples: int,
      compute_labels: bool = True,
  ) -> Union[
      List[
          Union[
              np.ndarray, np.ndarray, np.ndarray, np.ndarray, float, int
          ]
      ],
      List[np.ndarray],
  ]:
      """
          Generate perturbed samples while maintaining features in positions specified in
          anchor unchanged.
  
          Parameters
          ----------
          anchor
               - ``int`` - the position of the anchor in the input batch.
  
               - ``tuple`` - the anchor itself, a list of words to be kept unchanged.
  
          num_samples
              Number of generated perturbed samples.
          compute_labels
              If ``True``, an array of comparisons between predictions on perturbed samples and
              instance to be explained is returned.
  
          Returns
          -------
          If ``compute_labels=True``, a list containing the following is returned
  
           - `covered_true` - perturbed examples where the anchor applies and the model prediction \
           on perturbation is the same as the instance prediction.
  
           - `covered_false` - perturbed examples where the anchor applies and the model prediction \
           is NOT the same as the instance prediction.
  
           - `labels` - num_samples ints indicating whether the prediction on the perturbed sample \
           matches (1) the label of the instance to be explained or not (0).
  
           - `data` - Matrix with 1s and 0s indicating whether a word in the text has been perturbed for each sample.
  
           - `-1.0` - indicates exact coverage is not computed for this algorithm.
  
           - `anchor[0]` - position of anchor in the batch request.
  
          Otherwise, a list containing the data matrix only is returned.
          """
  
      raw_data, data = self.perturbation(anchor[1], num_samples)
  
      # create labels using model predictions as true labels
      if compute_labels:
          labels = self.compare_labels(raw_data)
          covered_true = raw_data[labels][: self.n_covered_ex]
          covered_false = raw_data[np.logical_not(labels)][
              : self.n_covered_ex
          ]
  
          # coverage set to -1.0 as we can't compute 'true' coverage for this model
          return [
              covered_true,
              covered_false,
              labels.astype(int),
              data,
              -1.0,
              anchor[0],
          ]
      else:
          return [data]
  
imports: import copy
  import logging
  import string
  from copy import deepcopy
  from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Tuple, Union
  import numpy
  import spacy
  from alibi.utils.missing_optional_dependency import import_optional
  from alibi.api.defaults import DEFAULT_DATA_ANCHOR, DEFAULT_META_ANCHOR
  from alibi.api.interfaces import Explainer, Explanation
  from alibi.exceptions import PredictorCallError, PredictorReturnTypeError
  from alibi.utils.wrappers import ArgmaxTransformer
  from .anchor_base import AnchorBaseBeam
  from .anchor_explanation import AnchorExplanation
  from .text_samplers import UnknownSampler, SimilaritySampler, load_spacy_lexeme_prob
label_desc: Use image node_id 3 for calling the AnchorText obj's underlying member method code with example usage: obj.sampler(anchor, num_samples, compute_labels) and returns: list, list