code: def compute_report_metrics(head, preds, labels):
      if head.ph_output_type in registered_reports:
          report_fn = registered_reports[head.ph_output_type]
      elif head.ph_output_type == "per_token":
          report_fn = token_classification_report
      elif head.ph_output_type == "per_sequence":
          report_fn = classification_report
      elif head.ph_output_type == "per_token_squad":
          report_fn = lambda *args, **kwargs: "Not Implemented"
      elif head.ph_output_type == "per_sequence_continuous":
          report_fn = r2_score
      else:
          raise AttributeError(
              f"No report function for head.ph_output_type '{head.ph_output_type}'. "
              f"You can register a custom one via register_report(name='{head.ph_output_type}', implementation=<your_report_function>"
          )
  
      # CHANGE PARAMETERS, not all report_fn accept digits
      if head.ph_output_type in ["per_sequence"]:
          # supply labels as all possible combination because if ground truth labels do not cover
          # all values in label_list (maybe dev set is small), the report will break
          if head.model_type == "multilabel_text_classification":
              # For multilabel classification, we don't eval with string labels here, but with multihot vectors.
              # Therefore we need to supply all possible label ids instead of label values.
              all_possible_labels = list(range(len(head.label_list)))
          elif head.model_type == "text_similarity":
              labels = reduce(
                  lambda x, y: x + list(y.astype("long")), labels, []
              )
              preds = reduce(
                  lambda x, y: x
                  + [0] * y[0]
                  + [1]
                  + [0] * (len(y) - y[0] - 1),
                  preds,
                  [],
              )
              all_possible_labels = list(range(len(head.label_list)))
          else:
              all_possible_labels = head.label_list
          return report_fn(
              labels,
              preds,
              digits=4,
              labels=all_possible_labels,
              target_names=head.label_list,
          )
      else:
          return report_fn(labels, preds)
  
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 8 for calling a global function with example usage: compute_report_metrics(head, preds, labels) and returns: report_fn, report_fn