code: def scores_to_df(scores, metric_names=None):
      """Convert `scores` into a pandas DataFrame."""
      # Use METRIC_NAMES defined at the top as default
      metric_names = metric_names or METRIC_NAMES
      for tag in scores.keys():
          if tag not in metric_names:
              metric_names[tag] = Metric(tag)
              logging.warning(
                  "TensorBoard tag %s not found in metric_names. "
                  "Using tag as metric name.",
                  tag,
              )
  
      # Sort the tags in scores according to metric_names order
      sorted_tags = sorted(
          scores.keys(),
          key=lambda x: list(metric_names.keys()).index(x),
      )
      columns = [metric_names[t].name for t in sorted_tags]
  
      # Convert scores to dict with the format
      # {step_number: {tag1: value, tag2: value, ...}}
      step_scores = collections.defaultdict(
          lambda: collections.OrderedDict(
              [(t, np.nan) for t in sorted_tags]
          )
      )
      for tag in sorted_tags:
          for step, value in scores[tag]:
              # If a job gets evicted and restarts from a prior checkpoint, it's
              # possible that a single step has more than one eval result. In that case,
              # we pick the max value across all the eval results.
              if step_scores[step][tag]:
                  step_scores[step][tag] = max(
                      value, step_scores[step][tag]
                  )
              else:
                  step_scores[step][tag] = value
      sorted_items = sorted(list(step_scores.items()))
      data = [list(r.values()) for _, r in sorted_items]
      index = [s for s, _ in sorted_items]
      df = pd.DataFrame(data, index, columns)
      df.index.name = "step"
      return df
  
file_path: text-to-text-transfer-transformer/t5/evaluation/eval_utils.py
imports: import collections
  import os
  from absl import logging
  import numpy
  import pandas
  import tensorflow.compat.v1
  import tensorflow_datasets
label_desc: Use image node_id 5 for calling a global function with example usage: scores_to_df(scores, metric_names) and returns: df