docstr: Initialize anchor text explainer.
  
  Parameters
  ----------
  predictor
      A callable that takes a list of text strings representing `N` data points as inputs and returns `N` outputs.
  sampling_strategy
      Perturbation distribution method:
  
       - ``'unknown'`` - replaces words with UNKs.
  
       - ``'similarity'`` - samples according to a similarity score with the corpus embeddings.
  
       - ``'language_model'`` - samples according the language model's output distributions.
  
  nlp
      `spaCy` object when sampling method is ``'unknown'`` or ``'similarity'``.
  language_model
      Transformers masked language model. This is a model that it adheres to the
      `LanguageModel` interface we define in :py:class:`alibi.utils.lang_model.LanguageModel`.
  seed
      If set, ensure identical random streams.
  kwargs
      Sampling arguments can be passed as `kwargs` depending on the `sampling_strategy`.
      Check default arguments defined in:
  
          - :py:data:`alibi.explainers.anchor_text.DEFAULT_SAMPLING_UNKNOWN`
  
          - :py:data:`alibi.explainers.anchor_text.DEFAULT_SAMPLING_SIMILARITY`
  
          - :py:data:`alibi.explainers.anchor_text.DEFAULT_SAMPLING_LANGUAGE_MODEL`
  
  Raises
  ------
  :py:class:`alibi.exceptions.PredictorCallError`
      If calling `predictor` fails at runtime.
  :py:class:`alibi.exceptions.PredictorReturnTypeError`
      If the return type of `predictor` is not `np.ndarray`.
docstr_tok: ["Initialize","anchor","text","explainer",".","Parameters","--","--","--","--","--","predictor","A","callable","that","takes","a","list","of","text","strings","representing","`","N","`","data","points","as","inputs","and","returns","`","N","`","outputs",".","sampling_strategy","Perturbation","distribution","method",":","-","``","'unknown","'","``","-","replaces","words","with","UNKs",".","-","``","'similarity","'","``","-","samples","according","to","a","similarity","score","with","the","corpus","embeddings",".","-","``","'language_model","'","``","-","samples","according","the","language","model","'s","output","distributions",".","nlp","`","spaCy","`","object","when","sampling","method","is","``","'unknown","'","``","or","``","'similarity","'","``",".","language_model","Transformers","masked","language","model",".","This","is","a","model","that","it","adheres","to","the","`","LanguageModel","`","interface","we","define","in",":","py",":","class",":","`","alibi.utils.lang_model.LanguageModel","`",".","seed","If","set",",","ensure","identical","random","streams",".","kwargs","Sampling","arguments","can","be","passed","as","`","kwargs","`","depending","on","the","`","sampling_strategy","`",".","Check","default","arguments","defined","in",":","-",":","py",":","data",":","`","alibi.explainers.anchor_text.DEFAULT_SAMPLING_UNKNOWN","`","-",":","py",":","data",":","`","alibi.explainers.anchor_text.DEFAULT_SAMPLING_SIMILARITY","`","-",":","py",":","data",":","`","alibi.explainers.anchor_text.DEFAULT_SAMPLING_LANGUAGE_MODEL","`","Raises","--","--","--",":","py",":","class",":","`","alibi.exceptions.PredictorCallError","`","If","calling","`","predictor","`","fails","at","runtime",".",":","py",":","class",":","`","alibi.exceptions.PredictorReturnTypeError","`","If","the","return","type","of","`","predictor","`","is","not","`","np.ndarray","`","."]
code: def __init__(
      self,
      predictor: Callable[[List[str]], np.ndarray],
      sampling_strategy: str = "unknown",
      nlp: Optional["spacy.language.Language"] = None,
      language_model: Union["LanguageModel", None] = None,
      seed: int = 0,
      **kwargs: Any,
  ) -> None:
      """
      Initialize anchor text explainer.
  
      Parameters
      ----------
      predictor
          A callable that takes a list of text strings representing `N` data points as inputs and returns `N` outputs.
      sampling_strategy
          Perturbation distribution method:
  
           - ``'unknown'`` - replaces words with UNKs.
  
           - ``'similarity'`` - samples according to a similarity score with the corpus embeddings.
  
           - ``'language_model'`` - samples according the language model's output distributions.
  
      nlp
          `spaCy` object when sampling method is ``'unknown'`` or ``'similarity'``.
      language_model
          Transformers masked language model. This is a model that it adheres to the
          `LanguageModel` interface we define in :py:class:`alibi.utils.lang_model.LanguageModel`.
      seed
          If set, ensure identical random streams.
      kwargs
          Sampling arguments can be passed as `kwargs` depending on the `sampling_strategy`.
          Check default arguments defined in:
  
              - :py:data:`alibi.explainers.anchor_text.DEFAULT_SAMPLING_UNKNOWN`
  
              - :py:data:`alibi.explainers.anchor_text.DEFAULT_SAMPLING_SIMILARITY`
  
              - :py:data:`alibi.explainers.anchor_text.DEFAULT_SAMPLING_LANGUAGE_MODEL`
  
      Raises
      ------
      :py:class:`alibi.exceptions.PredictorCallError`
          If calling `predictor` fails at runtime.
      :py:class:`alibi.exceptions.PredictorReturnTypeError`
          If the return type of `predictor` is not `np.ndarray`.
      """
      super().__init__(meta=copy.deepcopy(DEFAULT_META_ANCHOR))
      self._seed(seed)
  
      # set the predictor
      self.predictor = self._transform_predictor(predictor)
  
      # define model which can be either spacy object or LanguageModel
      # the initialization of the model happens in _validate_kwargs
      self.model: Union[
          "spacy.language.Language", LanguageModel
      ]  #: Language model to be used.
  
      # validate kwargs
      self.perturb_opts, all_opts = self._validate_kwargs(
          sampling_strategy=sampling_strategy,
          nlp=nlp,
          language_model=language_model,
          **kwargs,
      )
  
      # set perturbation
      self.perturbation: Any = self.CLASS_SAMPLER[
          self.sampling_strategy
      ](
          self.model, self.perturb_opts
      )  #: Perturbation method.
  
      # update metadata
      self.meta["params"].update(seed=seed)
      self.meta["params"].update(**all_opts)
  
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 1 to create a new AnchorText object from inherited base classes: Explainer with example: obj = AnchorText(predictor, sampling_strategy, nlp, language_model, seed)