code: def classification_metrics(
      preds: Sequence[int],
      labels: Sequence[int],
      metric: Optional[str] = "micro-f1",
      id2label: Optional[Dict] = None,
      label_path_sep: Optional[str] = "-",
  ) -> float:
      """evaluation metrics for classification task.
  
      Args:
          preds (Sequence[int]): predicted label ids for each examples
          labels (Sequence[int]): gold label ids for each examples
          metric (str, optional): type of evaluation function, support 'micro-f1', 'macro-f1', 'accuracy', 'precision', 'recall'. Defaults to "micro-f1".
  
      Returns:
          score (float): evaluation score
      """
  
      if metric == "micro-f1":
          score = f1_score(labels, preds, average="micro")
      elif metric == "macro-f1":
          score = f1_score(labels, preds, average="macro")
      elif metric == "accuracy":
          score = accuracy_score(labels, preds)
      elif metric == "precision":
          score = precision_score(labels, preds)
      elif metric == "recall":
          score = recall_score(labels, preds)
      # only hierarchical label loose metric is supported TODO naive multilabel ?
      elif metric == "loose-micro-f1":
          score = loose_micro(
              labels,
              preds,
              id2label=id2label,
              label_path_sep=label_path_sep,
          )["f1"]
      elif metric == "loose-macro-f1":
          score = loose_macro(
              labels,
              preds,
              id2label=id2label,
              label_path_sep=label_path_sep,
          )["f1"]
      elif metric == "loose-micro-precision":
          score = loose_micro(
              labels,
              preds,
              id2label=id2label,
              label_path_sep=label_path_sep,
          )["precision"]
      elif metric == "loose-macro-precision":
          score = loose_macro(
              labels,
              preds,
              id2label=id2label,
              label_path_sep=label_path_sep,
          )["precision"]
      elif metric == "loose-micro-recall":
          score = loose_micro(
              labels,
              preds,
              id2label=id2label,
              label_path_sep=label_path_sep,
          )["recall"]
      elif metric == "loose-macro-recall":
          score = loose_macro(
              labels,
              preds,
              id2label=id2label,
              label_path_sep=label_path_sep,
          )["recall"]
      else:
          raise ValueError(
              "'{}' is not a valid evaluation type".format(metric)
          )
      return score
  
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 5 for calling a global function with example usage: classification_metrics(preds, labels, metric, id2label, label_path_sep) and returns: score