class_docstr: Computes class weights from labels.
class_docstr_tok: ["Computes","class","weights","from","labels","."]
code: def add_input(
      self,
      accumulator: Dict[int, float],
      element: metric_types.StandardMetricInputs,
  ) -> Dict[int, float]:
      for (
          label,
          _,
          example_weight,
      ) in metric_util.to_label_prediction_example_weight(
          element,
          eval_config=self._eval_config,
          model_name=self._key.model_name,
          output_name=self._key.output_name,
          example_weighted=self._example_weighted,
          flatten=False,
          allow_none=True,
          require_single_example_weight=True,
      ):
          example_weight = float(example_weight)
          if label is not None:
              for class_id in self._class_ids:
                  if label.size == 1:
                      label_value = float(label.item() == class_id)
                  else:
                      if class_id >= len(label):
                          raise ValueError(
                              "class_id {} used with weighted_macro_average is outside the "
                              "range of the label provided: label={}, "
                              "StandardMetricInput={}".format(
                                  class_id, label, element
                              )
                          )
                      label_value = float(label[class_id])
                  accumulator[class_id] += label_value * example_weight
      return accumulator
  
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 3 for calling the _ClassWeightsFromLabelsCombiner obj's underlying member method code with example usage: obj.add_input(accumulator, element) and returns: accumulator