code: def joint_exact_counts(pred, label):
      """
      Return TP if joint groups match exactly
  
      :param pred, label: A joint group, represeted as a dict
      :return: A Counts namedtuple with TP, FP and FN counts
      """
      if pred["label"] != label["label"] or len(
          pred["entities"]
      ) != len(label["entities"]):
          return Counts(0, 1, 1)
      pred_entities = sorted(pred["entities"], key=lambda x: x["start"])
      label_entities = sorted(
          label["entities"], key=lambda x: x["start"]
      )
      for pred_entity, label_entity in zip(
          pred_entities, label_entities
      ):
          if (
              pred_entity["start"] != label_entity["start"]
              or pred_entity["end"] != label_entity["end"]
              or pred_entity["label"] != label_entity["label"]
          ):
              return Counts(0, 1, 1)
      return Counts(1, 0, 0)
  
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 5 for calling a global function with example usage: joint_exact_counts(pred, label) and returns: Counts, Counts, Counts