code: def group_token_counts(pred, label):
      """
      Return TP, FP, FN counts based on tokens in groups
  
      :param pred, label: A group, represeted as a dict
      :return: A Counts namedtuple with TP, FP and FN counts
      """
      pred_tokens = _convert_to_token_list(pred["spans"])
      label_tokens = _convert_to_token_list(label["spans"])
  
      if pred["label"] != label["label"]:
          # All predicted tokens are false positives
          # All ground truth tokens are false negatives
          return Counts(0, len(pred_tokens), len(label_tokens))
  
      TP, FP, FN = 0, 0, 0
      # TP and FN
      for l_token in label_tokens:
          for p_token in pred_tokens:
              if (
                  p_token["start"] == l_token["start"]
                  and p_token["end"] == l_token["end"]
              ):
                  TP += 1
                  break
          else:
              FN += 1
      # FP
      for p_token in pred_tokens:
          for l_token in label_tokens:
              if (
                  p_token["start"] == l_token["start"]
                  and p_token["end"] == l_token["end"]
              ):
                  break
          else:
              FP += 1
      return Counts(TP, FP, FN)
  
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 2 for calling a global function with example usage: group_token_counts(pred, label) and returns: Counts, Counts