class_docstr: Explains text classifiers.
  Currently, we are using an exponential kernel on cosine distance, and
  restricting explanations to words that are present in documents.
docstr: Generates explanations for a prediction.
  
  First, we generate neighborhood data by randomly hiding features from
  the instance (see __data_labels_distance_mapping). We then learn
  locally weighted linear models on this neighborhood data to explain
  each of the classes in an interpretable way (see lime_base.py).
  
  Args:
      text_instance: raw text string to be explained.
      classifier_fn: classifier prediction probability function, which
          takes a list of d strings and outputs a (d, k) numpy array with
          prediction probabilities, where k is the number of classes.
          For ScikitClassifiers , this is classifier.predict_proba.
      labels: iterable with labels to be explained.
      top_labels: if not None, ignore labels and produce explanations for
          the K labels with highest prediction probabilities, where K is
          this parameter.
      num_features: maximum number of features present in explanation
      num_samples: size of the neighborhood to learn the linear model
      distance_metric: the distance metric to use for sample weighting,
          defaults to cosine similarity
      model_regressor: sklearn regressor to use in explanation. Defaults
      to Ridge regression in LimeBase. Must have model_regressor.coef_
      and 'sample_weight' as a parameter to model_regressor.fit()
  Returns:
      An Explanation object (see explanation.py) with the corresponding
      explanations.
code: def explain_instance(
      self,
      text_instance,
      classifier_fn,
      labels=(1,),
      top_labels=None,
      num_features=10,
      num_samples=5000,
      distance_metric="cosine",
      model_regressor=None,
  ):
      """Generates explanations for a prediction.
  
      First, we generate neighborhood data by randomly hiding features from
      the instance (see __data_labels_distance_mapping). We then learn
      locally weighted linear models on this neighborhood data to explain
      each of the classes in an interpretable way (see lime_base.py).
  
      Args:
          text_instance: raw text string to be explained.
          classifier_fn: classifier prediction probability function, which
              takes a list of d strings and outputs a (d, k) numpy array with
              prediction probabilities, where k is the number of classes.
              For ScikitClassifiers , this is classifier.predict_proba.
          labels: iterable with labels to be explained.
          top_labels: if not None, ignore labels and produce explanations for
              the K labels with highest prediction probabilities, where K is
              this parameter.
          num_features: maximum number of features present in explanation
          num_samples: size of the neighborhood to learn the linear model
          distance_metric: the distance metric to use for sample weighting,
              defaults to cosine similarity
          model_regressor: sklearn regressor to use in explanation. Defaults
          to Ridge regression in LimeBase. Must have model_regressor.coef_
          and 'sample_weight' as a parameter to model_regressor.fit()
      Returns:
          An Explanation object (see explanation.py) with the corresponding
          explanations.
      """
  
      indexed_string = (
          IndexedCharacters(
              text_instance, bow=self.bow, mask_string=self.mask_string
          )
          if self.char_level
          else IndexedString(
              text_instance,
              bow=self.bow,
              split_expression=self.split_expression,
              mask_string=self.mask_string,
          )
      )
      domain_mapper = TextDomainMapper(indexed_string)
      data, yss, distances = self.__data_labels_distances(
          indexed_string,
          classifier_fn,
          num_samples,
          distance_metric=distance_metric,
      )
      if self.class_names is None:
          self.class_names = [str(x) for x in range(yss[0].shape[0])]
      ret_exp = explanation.Explanation(
          domain_mapper=domain_mapper,
          class_names=self.class_names,
          random_state=self.random_state,
      )
      ret_exp.predict_proba = yss[0]
      if top_labels:
          labels = np.argsort(yss[0])[-top_labels:]
          ret_exp.top_labels = list(labels)
          ret_exp.top_labels.reverse()
      for label in labels:
          (
              ret_exp.intercept[label],
              ret_exp.local_exp[label],
              ret_exp.score[label],
              ret_exp.local_pred[label],
          ) = self.base.explain_instance_with_data(
              data,
              yss,
              distances,
              label,
              num_features,
              model_regressor=model_regressor,
              feature_selection=self.feature_selection,
          )
      return ret_exp
  
imports: from functools import partial
  import itertools
  import json
  import re
  import numpy
  import scipy
  import sklearn
  from sklearn.utils import check_random_state
  from .None import explanation
  from .None import lime_base
label_desc: Use image node_id 2 for calling the LimeTextExplainer obj's underlying member method code with example usage: obj.explain_instance(text_instance, classifier_fn, labels, top_labels, num_features, num_samples, distance_metric, model_regressor) and returns: ret_exp