code: def _sparse_metrics(
      metrics: Dict[str, List[tf.keras.metrics.Metric]]
  ) -> Dict[str, List[tf.keras.metrics.Metric]]:
      """Returns input metrics filtered to contain only the sparse metrics."""
      results = {}
      for k, v in metrics.items():
          for m in v:
              if m.__class__.__name__.startswith("Sparse"):
                  if k not in results:
                      results[k] = []
                  results[k].append(m)
      return results
  
imports: import collections
  import importlib
  import itertools
  from typing import Any, Dict, Iterable, List, Optional, Type, Tuple, Union
  import apache_beam
  import numpy
  import tensorflow
  from tensorflow_model_analysis import constants
  from tensorflow_model_analysis.metrics import binary_confusion_matrices
  from tensorflow_model_analysis.metrics import metric_types
  from tensorflow_model_analysis.metrics import metric_util
  from tensorflow_model_analysis.metrics import tf_metric_accumulators
  from tensorflow_model_analysis.proto import config_pb2
  from tensorflow_model_analysis.utils import model_util
label_desc: Use image node_id 3 for calling a global function with example usage: _sparse_metrics(metrics) and returns: results