class_docstr: Task object for tf-ranking BERT.
class_docstr_tok: ["Task","object","for","tf-ranking","BERT","."]
docstr: Calculates aggregated metrics and writes predictions to csv.
code: def reduce_aggregated_logs(self, aggregated_logs, global_step=None):
      """Calculates aggregated metrics and writes predictions to csv."""
      # Aggregate and flatten all the logs.
      flattened_aggregated_logs = {
          key: np.reshape(np.concatenate(logs, axis=0), -1)
          for key, logs in aggregated_logs.items()
      }
  
      # Output predictions, labels, query ids and document ids to a csv file.
      if self.task_config.output_preds:
          output_dir = os.path.join(self._logging_dir, "prediction")
          if not tf.io.gfile.exists(output_dir):
              tf.io.gfile.makedirs(output_dir)
          flattened_output_logs = {
              key: flattened_aggregated_logs[key]
              for key in list(self._get_output_feature_names())
              + [_PREDICTION, _LABEL]
          }
          output_path = os.path.join(
              output_dir,
              "%s.csv" % (time.strftime("%s", time.localtime())),
          )
          self._write_as_csv(flattened_output_logs, output_path)
  
      # Calculate aggregated metrics.
      output = {}
      if self.task_config.aggregated_metrics:
          output = self._calculate_aggregated_metrics(
              flattened_aggregated_logs, QUERY_ID
          )
  
      return output
  
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 6 for calling the TFRBertTask obj's underlying member method code with example usage: obj.reduce_aggregated_logs(aggregated_logs, global_step) and returns: output