code: def acc_and_f1(preds, labels):
      acc = simple_accuracy(preds, labels)
      f1 = f1_score(y_true=labels, y_pred=preds)
      return {
          "acc": acc,
          "f1": f1,
          "acc_and_f1": (acc + f1) / 2,
      }
  
imports: import math
  from dataclasses import dataclass, field
  from itertools import chain
  import numpy
  import torch
  import torch.nn.functional
  from sklearn.metrics import f1_score
  from sklearn.metrics import matthews_corrcoef
  from scipy.stats import pearsonr, spearmanr
  from fairseq.logging import metrics
  from fairseq.criterions import FairseqCriterion, register_criterion
  from fairseq.dataclass import FairseqDataclass
  from fairseq.logging.meters import safe_round
label_desc: Use image node_id 2 for calling a global function with example usage: acc_and_f1(preds, labels) and returns: dict