code: def joint_metrics(preds, labels, span_type="exact", average=None):
      """
      Takes a set of NER + group predictions and labels and returns either per-class
      metrics or average metrics.
  
      :param preds, labels: A list of tuples, where each tuple is ([Doc A NER
      annotations, ...], [Doc A group annotations, ...]). The output of joint
      grouping models can be directly used
      :param span_type: A string, one of "exact", "token", "overlap", "superset"
      :param average: A string, one of "micro", "macro", "weighted"
      :return: Average F1 if average was specified, else per-class metrics
      """
      pred_groups = create_joint_groups(preds)
      label_groups = create_joint_groups(labels)
  
      return get_metrics(
          pred_groups,
          label_groups,
          metric_type="joint",
          span_type=span_type,
          average=average,
      )
  
imports: from copy import deepcopy
  from collections import namedtuple
  import numpy
  from scipy.optimize import linear_sum_assignment
  from finetune.util.metrics import _convert_to_token_list, _get_unique_classes, calc_precision, calc_recall, calc_f1
label_desc: Use image node_id 22 for calling a global function with example usage: joint_metrics(preds, labels, span_type, average) and returns: get_metrics