code: def eval_model(args, trainer, batches, vocab, mwt_dict):
      oov_count, N, all_preds, doc = output_predictions(
          args["conll_file"],
          trainer,
          batches,
          vocab,
          mwt_dict,
          args["max_seqlen"],
      )
  
      all_preds = np.concatenate(all_preds, 0)
      labels = np.concatenate(batches.labels())
      counter = Counter(zip(all_preds, labels))
  
      def f1(pred, gold, mapping):
          pred = [mapping[p] for p in pred]
          gold = [mapping[g] for g in gold]
  
          lastp = -1
          lastg = -1
          tp = 0
          fp = 0
          fn = 0
          for i, (p, g) in enumerate(zip(pred, gold)):
              if p == g > 0 and lastp == lastg:
                  lastp = i
                  lastg = i
                  tp += 1
              elif p > 0 and g > 0:
                  lastp = i
                  lastg = i
                  fp += 1
                  fn += 1
              elif p > 0:
                  # and g == 0
                  lastp = i
                  fp += 1
              elif g > 0:
                  lastg = i
                  fn += 1
  
          if tp == 0:
              return 0
          else:
              return 2 * tp / (2 * tp + fp + fn)
  
      f1tok = f1(all_preds, labels, {0: 0, 1: 1, 2: 1, 3: 1, 4: 1})
      f1sent = f1(all_preds, labels, {0: 0, 1: 0, 2: 1, 3: 0, 4: 1})
      f1mwt = f1(all_preds, labels, {0: 0, 1: 1, 2: 1, 3: 2, 4: 2})
      logger.info(
          f"{args['shorthand']}: token F1 = {f1tok*100:.2f}, sentence F1 = {f1sent*100:.2f}, mwt F1 = {f1mwt*100:.2f}"
      )
      return harmonic_mean([f1tok, f1sent, f1mwt], [1, 1, 0.01])
  
imports: from collections import Counter
  from copy import copy
  import json
  import numpy
  import re
  import logging
  import os
  from torch.utils.data import DataLoader
  import stanza.utils.default_paths
  from stanza.models.common.utils import ud_scores, harmonic_mean
  from stanza.models.common.doc import Document
  from stanza.utils.conll import CoNLL
  from stanza.models.common.doc import *
  from stanza.models.tokenization.data import SortedDataset
label_desc: Use image node_id 14 for calling a global function with example usage: eval_model(args, trainer, batches, vocab, mwt_dict) and returns: harmonic_mean, int, unknown