code: def parse_shap_values(
      shap_values: List[np.ndarray],
      confidences: List[float],
      feature_names: Optional[List[str]] = None,
      feature_values: Optional[List[Any]] = None,
  ) -> Dict[int, Dict]:
      """
      Parse SHAP values to fit XAI output format
  
      Args:
          shap_values (list): A list of shap values, a set for each class
          confidences (list): Confidences for each class
          feature_names (list): List of feature names
          feature_values (list): List of values corresponding to feature_names
  
      Returns:
          (dict) A mapping of class to explanations
  
      """
      assert len(shap_values) == len(confidences), (
          "Number of SHAP values should be equal to "
          "number of classes!"
      )
  
      dict_explanation = {}
  
      for label, confidence in enumerate(confidences):
          tmp = []
  
          shap_value_class = shap_values[label][0]
          for feature_idx, shap_value in enumerate(shap_value_class):
              # We ignore features which SHAP values are 0, which indicate that they had no
              # impact on the model's decision
              if shap_value != 0:
                  if feature_names and feature_values:
                      feature = "{} = {}".format(
                          feature_names[feature_idx],
                          feature_values[feature_idx],
                      )
                      tmp.append(
                          {
                              OUTPUT.FEATURE: feature,
                              OUTPUT.SCORE: shap_value,
                          }
                      )
                  else:
                      tmp.append(
                          {
                              OUTPUT.FEATURE: feature_idx,
                              OUTPUT.SCORE: shap_value,
                          }
                      )
  
          dict_explanation[label] = {
              OUTPUT.PREDICTION: confidence,
              OUTPUT.EXPLANATION: tmp,
          }
  
      return dict_explanation
  
imports: from typing import List, Dict, Optional, Any
  import numpy
  from lime.explanation import Explanation
  from xai.explainer.constants import MODE, OUTPUT
label_desc: Use image node_id 2 for calling a global function with example usage: parse_shap_values(shap_values, confidences, feature_names, feature_values) and returns: dict_explanation