code: def _topk_confusion_matrix(
      y_true: _NumbersT,
      y_pred: _NumbersT,
      *,
      k_list: Sequence[int],
      multioutput: bool,
      average: AverageType,
      vocab: dict[str, int] | None,
  ) -> _TopKConfusionMatrix:
      """Calculates a confusion matrix for multiclass(-multioutput) input.
  
      Args:
        y_true: ground truth classification labels. This has to be encoded in one of
          the `multiclass` or `multiclass-output`.
        y_pred: classification predictions. This has to be encoded in one of the
          `multiclass` or `multiclass-output`.
        k_list: a list of topk each of which slices y_pred by y_pred[:topk] assuming
          the predictions are sorted in descending order.
        multioutput: encoding types of the y_true and y_pred, if True, the input is
          a nested list of class identifiers.
        average: average type of the confusion matrix.
        vocab: an external vocabulary, if not provided, one is deduced within this
          input.
  
      Returns:
        Confusion matrices with k in k_list.
      """
      vocab = vocab or _get_vocab(
          itertools.chain(y_true, y_pred), multioutput
      )
      y_true_dense = _apply_vocab(y_true, vocab, multioutput)
      cms = []
      for k, y_pred_dense in _apply_vocab_at_k(
          y_pred, vocab, multioutput, k_list
      ):
          cm = _indicator_confusion_matrix(
              y_true_dense,
              y_pred_dense,
              average=average,
              multiclass=True,
              pos_label=True,
          )
          cms.append((k, cm.tp, cm.tn, cm.fp, cm.fn))
      return _TopKConfusionMatrix(*tuple(zip(*cms)))
  
imports: from collections.abc import Iterable, Sequence
  import dataclasses
  import enum
  import itertools
  from typing import Any
  import numpy
  from numpy import typing
  from tensorflow_model_analysis.experimental.lazytf import api
label_desc: Use image node_id 11 for calling a global function with example usage: _topk_confusion_matrix(y_true, y_pred) and returns: _TopKConfusionMatrix