code: def multi_class_confusion_matrices(
      thresholds: Optional[List[float]] = None,
      num_thresholds: Optional[int] = None,
      name: str = MULTI_CLASS_CONFUSION_MATRICES,
      extract_label_prediction_and_weight: Optional[
          Callable[
              ..., Iterator[Tuple[np.ndarray, np.ndarray, np.ndarray]]
          ]
      ] = metric_util.to_label_prediction_example_weight,
      eval_config: Optional[config_pb2.EvalConfig] = None,
      model_name: str = "",
      output_name: str = "",
      example_weighted: bool = False,
  ) -> metric_types.MetricComputations:
      """Returns computations for multi-class confusion matrices.
  
      Args:
        thresholds: A specific set of thresholds to use. The caller is responsible
          for marking the bondaires with +/-epsilon if desired. Only one of
          num_thresholds or thresholds should be used.
        num_thresholds: Number of thresholds to use. Thresholds will be calculated
          using linear interpolation between 0.0 and 1.0 with equidistant values and
          bondardaries at -epsilon and 1.0+epsilon. Values must be > 0. Only one of
          num_thresholds or thresholds should be used.
        name: Metric name.
        extract_label_prediction_and_weight: User-provided function argument that
          yields label, prediction, and example weights for use in calculations.
        eval_config: Eval config.
        model_name: Optional model name (if multi-model evaluation).
        output_name: Optional output name (if multi-output model type).
        example_weighted: True if example weights should be applied.
  
      Raises:
        ValueError: If both num_thresholds and thresholds are set at the same time.
      """
      if num_thresholds is not None and thresholds is not None:
          raise ValueError(
              "only one of thresholds or num_thresholds can be set at a time"
          )
      if num_thresholds is None and thresholds is None:
          thresholds = [0.0]
      if num_thresholds is not None:
          thresholds = [
              (i + 1) * 1.0 / (num_thresholds - 1)
              for i in range(num_thresholds - 2)
          ]
          thresholds = [-_EPSILON] + thresholds + [1.0 + _EPSILON]
  
      key = metric_types.MetricKey(
          name=name,
          model_name=model_name,
          output_name=output_name,
          example_weighted=example_weighted,
      )
      return [
          metric_types.MetricComputation(
              keys=[key],
              preprocessors=None,
              combiner=_MultiClassConfusionMatrixCombiner(
                  key=key,
                  eval_config=eval_config,
                  example_weighted=example_weighted,
                  thresholds=thresholds,
                  extract_label_prediction_and_weight=extract_label_prediction_and_weight,
              ),
          )
      ]
  
imports: from typing import Any, Callable, Dict, Iterable, Iterator, List, NamedTuple, Optional, Tuple
  import apache_beam
  import numpy
  from tensorflow_model_analysis.api import types
  from tensorflow_model_analysis.metrics import metric_types
  from tensorflow_model_analysis.metrics import metric_util
  from tensorflow_model_analysis.proto import config_pb2
  from tensorflow_model_analysis.proto import metrics_for_slice_pb2
label_desc: Use image node_id 2 for calling a global function with example usage: multi_class_confusion_matrices(thresholds, num_thresholds, name, extract_label_prediction_and_weight, eval_config, model_name, output_name, example_weighted) and returns: list