code: def EvaluateQueryBasedMetrics(  # pylint: disable=invalid-name
      extracts: beam.pvalue.PCollection,
      prediction_key: str,
      query_id: str,
      combine_fns: List[beam.CombineFn],
      metrics_key: str = constants.METRICS_KEY,
  ) -> evaluator.Evaluation:
      """Evaluates query-based metrics.
  
      Args:
        extracts: PCollection of Extracts. The extracts MUST contain a
          FeaturesPredictionsLabels extract keyed by
          tfma.FEATURE_PREDICTION_LABELS_KEY and a list of SliceKeyType extracts
          keyed by tfma.SLICE_KEY_TYPES_KEY. Typically these will be added by
          calling the default_extractors function.
        prediction_key: Key in predictions dictionary to use as the prediction (for
          sorting examples within the query). Use the empty string if the Estimator
          returns a predictions Tensor (not a dictionary).
        query_id: Key of query ID column in the features dictionary.
        combine_fns: List of query based metrics combine functions.
        metrics_key: Name to use for metrics key in Evaluation output.
  
      Returns:
        Evaluation containing metrics dictionaries keyed by 'metrics'.
      """
  
      # pylint: disable=no-value-for-parameter
      metrics = (
          extracts
          | "Filter"
          >> extractor.Filter(
              include=[
                  constants.FEATURES_PREDICTIONS_LABELS_KEY,
                  constants.SLICE_KEY_TYPES_KEY,
              ]
          )
          | "ComputeQueryBasedMetrics"
          >> ComputeQueryBasedMetrics(
              query_id=query_id,
              combine_fns=combine_fns,
              prediction_key=prediction_key,
          )
      )
      # pylint: enable=no-value-for-parameter
  
      return {metrics_key: metrics}
  
imports: from typing import Any, Dict, Iterable, Iterator, List, Optional, Tuple
  import apache_beam
  import numpy
  import tensorflow
  from tensorflow_model_analysis import constants
  from tensorflow_model_analysis.api import types
  from tensorflow_model_analysis.eval_saved_model import constants
  from tensorflow_model_analysis.eval_saved_model import encoding
  from tensorflow_model_analysis.eval_saved_model import util
  from tensorflow_model_analysis.evaluators import evaluator
  from tensorflow_model_analysis.evaluators.query_metrics import query_types
  from tensorflow_model_analysis.extractors import extractor
  from tensorflow_model_analysis.extractors import slice_key_extractor
label_desc: Use image node_id 3 for calling a global function with example usage: EvaluateQueryBasedMetrics(extracts, prediction_key, query_id, combine_fns, metrics_key) and returns: dict