code: def loose_macro(labels, preds, id2label, label_path_sep):
      if id2label is None:
          raise ValueError(
              "no id2label dict provided, cannot calculate loose_micro_f1 !"
          )
      labels = [label_path(id2label[i], label_path_sep) for i in labels]
      preds = [label_path(id2label[i], label_path_sep) for i in preds]
      p = 0.0
      r = 0.0
      for label, pred in zip(labels, preds):
          label = set(label)
          pred = set(pred)
          if len(pred) > 0:
              p += len(label.intersection(pred)) / len(pred)
          if len(label) > 0:
              r += len(label.intersection(pred)) / len(label)
      p /= len(labels)
      r /= len(labels)
      f = f1(p, r)
      return {"precision": p, "recall": r, "f1": f}
  
file_path: OpenPrompt/openprompt/utils/metrics.py
imports: from sklearn.metrics import f1_score, precision_score, recall_score, accuracy_score
  from typing import *
  from openprompt.utils.logging import logger
label_desc: Use image node_id 4 for calling a global function with example usage: loose_macro(labels, preds, id2label, label_path_sep) and returns: dict