code: def _verify_sparse_labels(
      labels: np.ndarray,
      predictions: np.ndarray,
      sparse_labels: bool = None,
  ) -> bool:
      """Checks if labels are sparse or not.
  
      Args:
        labels: Numpy array of labels.
        predictions: Numpy array of predictions.
        sparse_labels: True if sparse labels should be used. If None then the
          sparseness will be inferred from the shapes of the labels and predictions
          (i.e. if the shapes are different then the labels will be assumed to be
          sparse).
  
      Returns:
        True if sparse.
  
      Raises:
        ValueError: If the sparse_labels setting does not match labels and
          predictions.
      """
      if (
          len(labels.shape) != len(predictions.shape)
          or labels.shape[-1] != predictions.shape[-1]
      ):
          # Labels are of the form [class_id1, ...]
          #
          # Note that it is possible that the labels could be multi-label of the form
          # [[class_id1, class_id2], [class_id3, ...]]. However, this would require a
          # ragged or sparse tensor input to support. Ragged data in np.array is
          # encoded as a list object which doesn't accurately reflect the shape (i.e.
          # np.array([[1, 2], [3]]) has shape (2,). As such we will assume that all
          # multi-label use cases will use one-hot encodings (e.g. [0, 1. 1, ...]) and
          # will update this if/when RaggedTensorValue and SparseTensorValue value
          # types are supported in addition to np.ndarray.
          if sparse_labels is not None and not sparse_labels:
              raise ValueError(
                  "The number of labels = 1, but sparse labels are not being used\n\n"
                  "This is likley caused by a metric configuration error. Change to "
                  "use a non-sparse versions of the metrics or ensure that sparse "
                  f"labels are passed as input: labels={labels}, "
                  f"predictions={predictions}"
              )
          return True
      else:
          # Labels are of the form [0, 0, 1, ...] (i.e. one-hot). This includes
          # regression and binary classification.
          #
          # Similar to the note above, this is only true if multi-label inputs are
          # always encoded as one-hot since it is possible for a multi-label encoding
          # using [class_id1, ...] to use all the classes and therefore match the
          # prediction's last dimension in length.
          if sparse_labels is not None and sparse_labels:
              raise ValueError(
                  "The number of labels > 1, but sparse labels are being used\n\n"
                  "This is likley caused by a metric configuration error. Change to "
                  "use sparse versions of the metrics or ensure that non-sparse labels "
                  f"are passed as input: labels={labels}, predictions={predictions}"
              )
          return False
  
imports: import inspect
  import math
  from typing import Any, Callable, Dict, Iterable, Iterator, List, Mapping, Optional, Tuple, Union
  import numpy
  import tensorflow
  from tensorflow_model_analysis import constants
  from tensorflow_model_analysis.api import types
  from tensorflow_model_analysis.metrics import metric_types
  from tensorflow_model_analysis.proto import config_pb2
  from tensorflow_model_analysis.utils import util
  from tensorflow_metadata.proto.v0 import schema_pb2
label_desc: Use image node_id 24 for calling a global function with example usage: _verify_sparse_labels(labels, predictions, sparse_labels) and returns: True, False