code: def _class_weights_from_labels(
      class_ids: List[int],
      name: str = _CLASS_WEIGHTS_FROM_LABELS_NAME,
      eval_config: Optional[config_pb2.EvalConfig] = None,
      model_name: str = "",
      output_name: str = "",
      example_weighted: bool = False,
  ) -> metric_types.MetricComputations:
      """Returns metric computations for class weights based on labels.
  
      Args:
        class_ids: List of class Ids to compute weighted labels from.
        name: Metric name.
        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.
      """
      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,  # Use default
              combiner=_ClassWeightsFromLabelsCombiner(
                  key,
                  eval_config=eval_config,
                  example_weighted=example_weighted,
                  class_ids=class_ids,
              ),
          )
      ]
  
file_path: model-analysis/tensorflow_model_analysis/metrics/aggregation.py
imports: from typing import Any, Dict, Iterable, List, Optional
  import apache_beam
  from tensorflow_model_analysis.metrics import metric_types
  from tensorflow_model_analysis.metrics import metric_util
  from tensorflow_model_analysis.proto import config_pb2
label_desc: Use image node_id 5 for calling a global function with example usage: _class_weights_from_labels(class_ids, name, eval_config, model_name, output_name, example_weighted) and returns: list