code: def evaluate(args):
      # file paths
      model_file = model_file_name(args)
  
      loaded_args, trainer, vocab = load_model(args, model_file)
      logger.debug("Loaded model for eval from %s", model_file)
      logger.debug(
          "Using the %d tagset for evaluation",
          loaded_args["predict_tagset"],
      )
  
      # load data
      logger.info(
          "Loading data with batch size {}...".format(
              args["batch_size"]
          )
      )
      with open(args["eval_file"]) as fin:
          doc = Document(json.load(fin))
      batch = DataLoader(
          doc,
          args["batch_size"],
          loaded_args,
          vocab=vocab,
          evaluation=True,
          bert_tokenizer=trainer.model.bert_tokenizer,
      )
      bioes_to_bio = (
          loaded_args["train_scheme"] == "bio"
          and loaded_args["scheme"] == "bioes"
      )
      warn_missing_tags(
          trainer.vocab["tag"],
          batch.tags,
          "eval_file",
          bioes_to_bio=bioes_to_bio,
      )
  
      logger.info("Start evaluation...")
      preds = []
      for i, b in enumerate(batch):
          preds += trainer.predict(b)
  
      gold_tags = batch.tags
      # TODO: might still want to add multiple layers of tag evaluation to the scorer
      gold_tags = [
          [x[trainer.args["predict_tagset"]] for x in tags]
          for tags in gold_tags
      ]
  
      _, _, score, entity_f1 = scorer.score_by_entity(
          preds, gold_tags, ignore_tags=args["ignore_tag_scores"]
      )
      _, _, _, confusion = scorer.score_by_token(
          preds, gold_tags, ignore_tags=args["ignore_tag_scores"]
      )
      logger.info(
          "Weighted f1 for non-O tokens: %5f",
          confusion_to_weighted_f1(confusion, exclude=["O"]),
      )
  
      logger.info(
          "NER tagger score: %s %s %s %.2f",
          args["shorthand"],
          model_file,
          args["eval_file"],
          score * 100,
      )
      entity_f1_lines = [
          "%s: %.2f" % (x, y * 100) for x, y in entity_f1.items()
      ]
      logger.info(
          "NER Entity F1 scores:\n  %s", "\n  ".join(entity_f1_lines)
      )
      logger.info(
          "NER token confusion matrix:\n{}".format(
              format_confusion(confusion)
          )
      )
  
      if args["eval_output_file"]:
          write_ner_results(
              args["eval_output_file"],
              batch,
              preds,
              trainer.args["predict_tagset"],
          )
  
      return confusion
  
imports: import sys
  import os
  import time
  from datetime import datetime
  import argparse
  import logging
  import numpy
  import random
  import re
  import json
  import torch
  from torch import nn, optim
  from stanza.models.ner.data import DataLoader
  from stanza.models.ner.trainer import Trainer
  from stanza.models.ner import scorer
  from stanza.models.common import utils
  from stanza.models.common.pretrain import Pretrain
  from stanza.utils.conll import CoNLL
  from stanza.models.common.doc import *
  from stanza.models import _training_logging
  from stanza.utils.confusion import confusion_to_weighted_f1, format_confusion
label_desc: Use image node_id 10 for calling a global function with example usage: evaluate(args) and returns: confusion