code: def combine_dict_based_evaluations(
      evaluations: Dict[str, List[beam.pvalue.PCollection]]
  ) -> Evaluation:
      """Combines multiple evaluation outputs together when the outputs are dicts.
  
      Note that the dict here refers to the output in the PCollection. The
      evaluations themselves are dicts of PCollections keyed by category ('metrics',
      'plots', 'analysis', etc). This util is used to group the outputs of one or
      more of these evaluations where the PCollections themselves must be dicts. For
      example, a 'metrics' evaluation might store its output in PCollection of dicts
      containing metric keys and metric values. This util would be used to group the
      outputs from running two or more independent metrics evaluations together into
      a single PCollection.
  
      Args:
        evaluations: Dict of lists of PCollections of outputs from different
          evaluators keyed by type of output ('metrics', 'plots', 'analysis', etc).
  
      Returns:
        Dict of consolidated PCollections of outputs keyed by type of output.
      """
      result = {}
      for k, v in evaluations.items():
          if len(v) == 1:
              result[k] = v[0]
              continue
  
          result[k] = (
              v
              | "FlattenEvaluationOutput(%s)" % k >> beam.Flatten()
              | "CombineEvaluationOutput(%s)" % k
              >> beam.CombinePerKey(_CombineEvaluationDictionariesFn())
          )
      return result
  
file_path: model-analysis/tensorflow_model_analysis/evaluators/evaluator.py
imports: from typing import Any, Dict, Iterable, List, NamedTuple, Optional
  import apache_beam
  from tensorflow_model_analysis.extractors import extractor
label_desc: Use image node_id 2 for calling a global function with example usage: combine_dict_based_evaluations(evaluations) and returns: result