class_docstr: Introspective Rationale Explainer
      
class_docstr_tok: ["Introspective","Rationale","Explainer"]
docstr: Create a local explanation for a given text
  :param X: String to be explained.
  :type X: str
  :param y: The ground truth label for the sentence
  :type y: string
  :param name: a name for saving the explanation, currently ignored
  :type str
  :return: local explanation object
  :rtype: DynamicLocalExplanation
code: def explain_local(self, X, y=None, name=None) -> LocalExplanation:
      """Create a local explanation for a given text
      :param X: String to be explained.
      :type X: str
      :param y: The ground truth label for the sentence
      :type y: string
      :param name: a name for saving the explanation, currently ignored
      :type str
      :return: local explanation object
      :rtype: DynamicLocalExplanation
      """
      X = _validate_X(X)
  
      model_args = self.model_config
      df_dummy_label = pd.DataFrame.from_dict({"labels": [0]})
      df_sentence = pd.concat(
          [df_dummy_label, self.preprocessor.preprocess([X.lower()])],
          axis=1,
      )
      batch_dict = generate_data(df_sentence, self.model_config.cuda)
      x = batch_dict["x"]
      m = batch_dict["m"]
      predict_dict = self.predict(df_sentence)
      zs = predict_dict["rationale"]
  
      prediction = predict_dict["predict"]
      prediction_idx = prediction[0].max(0)[1]
      prediction = model_args.labels[prediction_idx]
      zs = np.array(zs.cpu())
  
      # The not hard_importance condition was implied, ids is undefined otherwise
      float_zs = self.model.get_z_scores(df_sentence)
      float_zs = float_zs[:, :, 1].detach()
      float_zs = np.array(float_zs.cpu())
      # set importances all words not selected as part of the rationale
      # to zero
      zs = zs * float_zs
      # generate human-readable tokens (individual words)
      seq_len = int(m.sum().item())
      ids = x[:seq_len][0]
  
      tokens = self.preprocessor.decode_single(ids)
  
      local_importance_values = zs.flatten()
      # post-processing for BERT to remove SEP and CLS tokens
      # TODO: might we want to add a "post-process" method to the preprocessor?
      tokens_to_remove = [BertTokens.SEP, BertTokens.CLS]
      token_indexes = [
          idx
          for idx, token in enumerate(tokens)
          if token in tokens_to_remove
      ]
      if token_indexes:
          local_importance_values = np.delete(
              local_importance_values, token_indexes
          )
          for token_index in sorted(token_indexes, reverse=True):
              del tokens[token_index]
      local_explanation = _create_local_explanation(
          classification=True,
          text_explanation=True,
          local_importance_values=local_importance_values,
          method=str(type(self.model)),
          model_task="classification",
          features=tokens,
          classes=model_args.labels,
          predicted_label=prediction,
      )
      return local_explanation
  
imports: from typing import Iterable, Any, Optional, Union, Dict
  import numpy
  import pandas
  import torch
  from interpret_text.experimental.common.base_explainer import BaseTextExplainer, _validate_X
  from interpret_text.experimental.common.constants import BertTokens
  from interpret_text.experimental.common.model_config.introspective_rationale_model_config import IntrospectiveRationaleModelConfig
  from interpret_text.experimental.common.model_config.model_config_constants import get_bert_default_config, get_rnn_default_config, get_bert_rnn_default_config
  from interpret_text.experimental.common.preprocessor.bert_preprocessor import BertPreprocessor
  from interpret_text.experimental.common.preprocessor.glove_preprocessor import GlovePreprocessor
  from interpret_text.experimental.common.utils_classical import plot_local_imp
  from interpret_text.experimental.common.utils_introspective_rationale import generate_data
  from interpret_text.experimental.explanation import _create_local_explanation, LocalExplanation
  from interpret_text.experimental.introspective_rationale.components import ClassifierWrapper, ClassifierModule, IntrospectionGeneratorModule
  from interpret_text.experimental.introspective_rationale.model import IntrospectiveRationaleModel
  from transformers import BertForSequenceClassification
label_desc: Use image node_id 15 for calling the IntrospectiveRationaleExplainer obj's underlying member method code with example usage: obj.explain_local(X, y, name) and returns: local_explanation