code: def compute_avg_glue(df, metric_names=None):
      """Compute average GLUE and SuperGLUE scores from a DataFrame.
  
      Will only compute a given average score if all of the metrics for that
      benchmark appear as columns in the DataFrame.
  
      Args:
        df: pandas.DataFrame, columns should be metric names.
        metric_names: dict mapping tensorboard tag to metric name.
      Returns:
        A pandas.DataFrame which has GLUE and SuperGLUE averages calculated.
      """
      # Use METRIC_NAMES defined at the top as default
      metric_names = metric_names or METRIC_NAMES
      all_glue_tags = {
          k
          for k in metric_names.keys()
          if "glue" in k and "average" not in k
      }
      superglue_tags = {k for k in all_glue_tags if "super" in k}
      glue_tags = all_glue_tags - superglue_tags
      average_keys = ["Average GLUE Score", "Average SuperGLUE Score"]
      for average_key, tags in zip(
          average_keys, [glue_tags, superglue_tags]
      ):
          # Only compute average if all metric names appear as columns in the DF
          if {metric_names[t].name for t in tags}.issubset(
              set(df.columns)
          ):
              # Compute average over each metric group
              group_to_metrics = collections.defaultdict(set)
              for tag in tags:
                  metric = metric_names[tag]
                  group_to_metrics[metric.group].add(metric.name)
              accum = None
              for metrics in group_to_metrics.values():
                  group_avg = np.mean([df[k] for k in metrics], axis=0)
                  accum = (
                      group_avg if accum is None else accum + group_avg
                  )
              # Compute average across all groups
              average = accum / len(group_to_metrics)
              df[average_key] = average
      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 4 for calling a global function with example usage: compute_avg_glue(df, metric_names) and returns: df