class_docstr: Task object for tf-ranking BERT.
class_docstr_tok: ["Task","object","for","tf-ranking","BERT","."]
docstr: Calculates metrics where lists are grouped by `query_feature_name`.
code: def _calculate_aggregated_metrics(
      self, flattened_aggregated_logs, query_feature_name
  ):
      """Calculates metrics where lists are grouped by `query_feature_name`."""
      qid2labels = {}
      qid2preds = {}
  
      qids = flattened_aggregated_logs[query_feature_name]
      preds = flattened_aggregated_logs[_PREDICTION]
      labels = flattened_aggregated_logs[_LABEL]
      for qid, pred, label in zip(qids, preds, labels):
          qid2labels[qid] = qid2labels.get(qid, []) + [label]
          qid2preds[qid] = qid2preds.get(qid, []) + [pred]
  
      metrics = [
          tfr_metrics.MeanAveragePrecisionMetric(name="Aggregated_MAP")
      ]
      for topn in [1, 5, 10]:
          metrics.append(
              tfr_metrics.NDCGMetric(
                  name="Aggregated_NDCG@{}".format(topn), topn=topn
              )
          )
      for topn in [1, 5, 10]:
          metrics.append(
              tfr_metrics.MRRMetric(
                  name="Aggregated_MRR@{}".format(topn), topn=topn
              )
          )
  
      output_results = {}
      for metric in metrics:
          for qid in qid2preds:
              preds = np.expand_dims(qid2preds[qid], 0)
              labels = np.expand_dims(qid2labels[qid], 0)
              metric.update_state(labels, preds)
          output_results.update(
              {
                  "agggregated_metrics/{}".format(
                      metric.name
                  ): metric.result().numpy()
              }
          )
          logging.info(
              "agggregated_metrics/%s = %f",
              metric.name,
              metric.result().numpy(),
          )
      return output_results
  
imports: import dataclasses
  import os
  import time
  from typing import Dict, Mapping, Optional, Tuple
  from absl import logging
  import numpy
  import tensorflow
  from official.core import task_factory
  from official.modeling.hyperparams import base_config
  from official.nlp.configs import encoders
  from tensorflow_ranking.extension import task
  from tensorflow_ranking.python.keras import metrics
  from tensorflow_ranking.python.keras import model
label_desc: Use image node_id 9 for calling the TFRBertTask obj's underlying member method code with example usage: obj._calculate_aggregated_metrics(flattened_aggregated_logs, query_feature_name) and returns: output_results