code: def compute_metrics(metric, preds, labels):
      """
      Calculate the named metric values for the list of predictions vs list of labels.
  
      :param metric: The name of a predefined metric; a function that takes a prediction list and a label
          list and returns a dict from metric names to values, or recursively a list of metrics.
          Predefined metrics are: mcc, acc, acc_f1, pear_spear, seq_f1, f1_macro, squad, mse, r2,
          top_n_accuracy, text_similarity_metric.
      :type metric: Samples are truncated after this many tokens.
      :param preds: list of predictions
      :param labels: list of target labels
      :return: a dictionary mapping metric names to values.
      """
      assert len(preds) == len(labels)
      if metric == "mcc":
          return {"mcc": matthews_corrcoef(labels, preds)}
      elif metric == "acc":
          return simple_accuracy(preds, labels)
      elif metric == "acc_f1":
          return acc_and_f1(preds, labels)
      elif metric == "pear_spear":
          return pearson_and_spearman(preds, labels)
      # TODO this metric seems very specific for NER and doesnt work for
      elif metric == "seq_f1":
          return {"seq_f1": ner_f1_score(labels, preds)}
      elif metric == "f1_macro":
          return f1_macro(preds, labels)
      elif metric == "squad":
          return squad(preds, labels)
      elif metric == "mse":
          return {"mse": mean_squared_error(preds, labels)}
      elif metric == "r2":
          return {"r2": r2_score(preds, labels)}
      elif metric == "top_n_accuracy":
          return {"top_n_accuracy": top_n_accuracy(preds, labels)}
      elif metric == "text_similarity_metric":
          return text_similarity_metric(preds, labels)
      # elif metric == "masked_accuracy":
      #     return simple_accuracy(preds, labels, ignore=-1)
      elif isinstance(metric, list):
          ret = {}
          for m in metric:
              ret.update(compute_metrics(m, preds, labels))
          return ret
      elif metric in registered_metrics:
          metric_func = registered_metrics[metric]
          return metric_func(preds, labels)
      else:
          raise KeyError(metric)
  
imports: import logging
  import numpy
  import torch
  from functools import reduce
  from scipy.stats import pearsonr, spearmanr
  from seqeval.metrics import classification_report
  from seqeval.metrics import f1_score
  from sklearn.metrics import matthews_corrcoef, f1_score, mean_squared_error, r2_score, classification_report
  from farm.utils import flatten_list
label_desc: Use image node_id 7 for calling a global function with example usage: compute_metrics(metric, preds, labels) and returns: dict, simple_accuracy, acc_and_f1, pearson_and_spearman, dict, f1_macro, squad, dict, dict, dict, text_similarity_metric, ret, metric_func