code: def evaluate(args):
      # file paths
      system_pred_file = args["output_file"]
      gold_file = args["gold_file"]
      model_file = build_model_filename(args)
  
      # load model
      trainer = Trainer(
          model_file=model_file, device=args["device"], args=args
      )
      loaded_args, vocab = trainer.args, trainer.vocab
  
      for k in args:
          if (
              k.endswith("_dir")
              or k.endswith("_file")
              or k in ["shorthand"]
          ):
              loaded_args[k] = args[k]
  
      # load data
      logger.info(
          "Loading data with batch size {}...".format(
              args["batch_size"]
          )
      )
      doc = CoNLL.conll2doc(input_file=args["eval_file"])
      batch = DataLoader(
          doc,
          args["batch_size"],
          loaded_args,
          vocab=vocab,
          evaluation=True,
      )
  
      # skip eval if dev data does not exist
      if len(batch) == 0:
          logger.warning(
              "Skip evaluation because no dev data is available...\nLemma score:\n{} ".format(
                  args["shorthand"]
              )
          )
          return
  
      dict_preds = trainer.predict_dict(batch.doc.get([TEXT, UPOS]))
  
      if loaded_args.get("dict_only", False):
          preds = dict_preds
      else:
          logger.info("Running the seq2seq model...")
          preds = []
          edits = []
          for i, b in enumerate(batch):
              ps, es = trainer.predict(b, args["beam_size"])
              preds += ps
              if es is not None:
                  edits += es
          preds = trainer.postprocess(
              batch.doc.get([TEXT]), preds, edits=edits
          )
  
          if loaded_args.get("ensemble_dict", False):
              logger.info(
                  "[Ensembling dict with seq2seq lemmatizer...]"
              )
              preds = trainer.ensemble(
                  batch.doc.get([TEXT, UPOS]), preds
              )
  
      # write to file and score
      batch.doc.set([LEMMA], preds)
      CoNLL.write_doc2conll(batch.doc, system_pred_file)
      if gold_file is not None:
          _, _, score = scorer.score(system_pred_file, gold_file)
  
          logger.info(
              "Finished evaluation\nLemma score:\n{} {:.2f}".format(
                  args["shorthand"], score * 100
              )
          )
  
imports: import logging
  import sys
  import os
  import shutil
  import time
  from datetime import datetime
  import argparse
  import numpy
  import random
  import torch
  from torch import nn, optim
  from stanza.models.lemma.data import DataLoader
  from stanza.models.lemma.vocab import Vocab
  from stanza.models.lemma.trainer import Trainer
  from stanza.models.lemma import scorer, edit
  from stanza.models.common import utils
  import stanza.models.common.seq2seq_constant
  from stanza.models.common.doc import *
  from stanza.utils.conll import CoNLL
  from stanza.models import _training_logging
label_desc: Use image node_id 6 for calling a global function with example usage: evaluate(args) without return types