class_docstr: Defines the ExplainerManager for explaining a text-based model.
class_docstr_tok: ["Defines","the","ExplainerManager","for","explaining","a","text-based","model","."]
docstr: Creates an explanation by running the explainer on the model.
docstr_tok: ["Creates","an","explanation","by","running","the","explainer","on","the","model","."]
code: def compute(self):
      """Creates an explanation by running the explainer on the model."""
      if not self._is_added:
          return
      if self._is_run:
          return
      if self._is_classification_task:
          if hasattr(self._model, "predict_proba"):
              # use model-agnostic simple tokenizer
              masker = shap.maskers.Text()
              explainer = shap.Explainer(
                  self._model.predict_proba, masker
              )
          else:
              explainer = shap.Explainer(self._model)
          eval_examples = self._evaluation_examples.iloc[:, 0].tolist()
          self._explanation = explainer(eval_examples)
      elif self._task_type == ModelTask.QUESTION_ANSWERING:
          qa_predictor = QAPredictor(self._model)
          qa_start = qa_predictor.predict_qa_start
          qa_output_names_func = qa_predictor.output_names
          qa_start.__func__.output_names = qa_output_names_func
          explainer_start = shap.Explainer(
              qa_start, self._model.tokenizer
          )
          qa_end = qa_predictor.predict_qa_end
          qa_end.__func__.output_names = qa_output_names_func
          explainer_end = shap.Explainer(qa_end, self._model.tokenizer)
          context = self._evaluation_examples[CONTEXT]
          questions = self._evaluation_examples[QUESTIONS]
          eval_examples = []
          for context, question in zip(context, questions):
              eval_examples.append(question + SEP + context)
          self._explanation = [
              explainer_start(eval_examples),
              explainer_end(eval_examples),
          ]
      else:
          raise ValueError(
              "Unknown task type: {}".format(self._task_type)
          )
  
      self._is_run = True
  
imports: import json
  import pickle
  import warnings
  from pathlib import Path
  from typing import Any, List, Optional
  import numpy
  import pandas
  import shap
  from raiutils.data_processing import convert_to_list
  from responsibleai._interfaces import FeatureImportance, ModelExplanationData, PrecomputedExplanations, TextFeatureImportance
  from responsibleai._internal.constants import ExplainerManagerKeys
  from responsibleai._internal.constants import ListProperties, ManagerNames, Metadata
  from responsibleai._tools.shared.state_directory_management import DirectoryManager
  from responsibleai.exceptions import UserConfigValidationException
  from responsibleai.managers.base_manager import BaseManager
  from responsibleai_text.common.constants import ModelTask, QuestionAnsweringFields, Tokens
  from responsibleai_text.utils.question_answering import QAPredictor
label_desc: Use image node_id 3 for calling the ExplainerManager obj's underlying member method code with example usage: obj.compute() without return types