code: def calc_class_metrics(
      all_preds, all_labels, metric_type="group", span_type="exact"
  ):
      """
      Calculates a set of metrics for each class.
  
      :param all_preds, all_labels: A list of list of groups. If metric_type ==
      "joint", the groups should in joint form with an "entities" key
      :param metric_type: A string, either "group" or "joint"
      :param span_type: A string, one of "exact", "token", "overlap", "superset"
      :return per_class_metrics: A dictionary of the form:
          {
              "class1": {
                  "precision": 0.5,
                  "recall": 0.5,
                  "f1-score": 0.5,
                  "support": 2,
                  "true_positives": 1,
                  "false_positives": 1,
                  "false_negatives": 1,
              }
              .
              .
              .
              "class_n: {...},
          }
      """
      class_counts = calc_class_counts(
          all_preds,
          all_labels,
          metric_type=metric_type,
          span_type=span_type,
      )
      per_class_metrics = {}
      for cls, counts in class_counts.items():
          TP = counts["true_positives"]
          FP = counts["false_positives"]
          FN = counts["false_negatives"]
  
          precision = calc_precision(TP, FP)
          recall = calc_recall(TP, FN)
          f1 = calc_f1(recall, precision)
          support = TP + FN
  
          per_class_metrics[cls] = {
              "precision": precision,
              "recall": recall,
              "f1-score": f1,
              "support": support,
              "true_positives": TP,
              "false_positives": FP,
              "false_negatives": FN,
          }
      return per_class_metrics
  
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 12 for calling a global function with example usage: calc_class_metrics(all_preds, all_labels, metric_type, span_type) and returns: per_class_metrics