code: def evaluate(
      args,
      model,
      eval_dataset,
      tokenizer,
      labels,
      pad_token_label_id,
      mode,
      device,
      prefix="",
  ):
      OmegaConf.set_struct(args, True)
      with open_dict(args):
          args.eval_batch_size = args.per_gpu_eval_batch_size * max(
              1, args.n_gpu
          )
  
      # Note that DistributedSampler samples randomly
      eval_sampler = (
          SequentialSampler(eval_dataset)
          if args.local_rank == -1
          else DistributedSampler(eval_dataset)
      )
      eval_dataloader = DataLoader(
          eval_dataset,
          sampler=eval_sampler,
          batch_size=args.eval_batch_size,
      )
  
      # multi-gpu evaluate
      if args.n_gpu > 1:
          model = torch.nn.DataParallel(model)
  
      # Eval!
      logger.info("***** Running evaluation %s *****", prefix)
      logger.info("  Num examples = %d", len(eval_dataset))
      logger.info("  Batch size = %d", args.eval_batch_size)
      logger.info("  Mode = %s", mode)
      eval_loss = 0.0
      nb_eval_steps = 0
      preds = None
      out_label_ids = None
      model.eval()
      for batch in tqdm(eval_dataloader, desc="Evaluating"):
          batch = tuple(t.to(device) for t in batch)
  
          with torch.no_grad():
              inputs = {
                  "input_ids": batch[0],
                  "attention_mask": batch[1],
                  "labels": batch[3],
              }
              if args.model_type != "distilbert":
                  inputs["token_type_ids"] = (
                      batch[4]
                      if args.model_type in ["bert", "bertcrf", "xlnet"]
                      else None
                  )  # XLM and RoBERTa don"t use segment_ids
              outputs = model(
                  pad_token_label_id=pad_token_label_id, **inputs
              )
              tmp_eval_loss, logits, best_path = outputs
  
              if args.n_gpu > 1:
                  tmp_eval_loss = (
                      tmp_eval_loss.mean()
                  )  # mean() to average on multi-gpu parallel evaluating
  
              eval_loss += tmp_eval_loss.item()
  
          nb_eval_steps += 1
          if preds is None:
              preds = best_path.detach().cpu().numpy()
              out_label_ids = inputs["labels"].detach().cpu().numpy()
          else:
              preds = np.append(
                  preds, best_path.detach().cpu().numpy(), axis=0
              )
              out_label_ids = np.append(
                  out_label_ids,
                  inputs["labels"].detach().cpu().numpy(),
                  axis=0,
              )
  
      eval_loss = eval_loss / nb_eval_steps
  
      label_map = {i: label for i, label in enumerate(labels)}
  
      out_label_list = [[] for _ in range(out_label_ids.shape[0])]
      preds_list = [[] for _ in range(out_label_ids.shape[0])]
  
      for i in range(out_label_ids.shape[0]):
          for j in range(out_label_ids.shape[1]):
              if out_label_ids[i, j] != pad_token_label_id:
                  out_label_list[i].append(
                      label_map[out_label_ids[i][j]]
                  )
                  preds_list[i].append(label_map[preds[i][j]])
      results = {
          "loss": eval_loss,
          "precision": precision_score(out_label_list, preds_list),
          "recall": recall_score(out_label_list, preds_list),
          "f1": f1_score(out_label_list, preds_list),
      }
  
      logger.info("***** Eval results %s *****", prefix)
      for key in sorted(results.keys()):
          logger.info("  %s = %s", key, str(results[key]))
  
      return results, preds_list
  
imports: import argparse
  import glob
  import logging
  import os
  import sys
  import json
  import random
  import numpy
  import torch
  import hydra
  from hydra import utils
  from omegaconf import OmegaConf, open_dict
  from seqeval.metrics import f1_score, precision_score, recall_score
  from torch.utils.data import DataLoader, RandomSampler, SequentialSampler, TensorDataset
  from torch.utils.data.distributed import DistributedSampler
  from tqdm import tqdm, trange
  from transformers import WEIGHTS_NAME, AdamW, BertConfig, BertTokenizer, get_linear_schedule_with_warmup
  from deepke.event_extraction.standard.bertcrf.processor_ee import convert_examples_to_features, PROCESSORS
  from deepke.event_extraction.standard.bertcrf.bert_crf import *
label_desc: Use image node_id 3 for calling a global function with example usage: evaluate(args, model, eval_dataset, tokenizer, labels, pad_token_label_id, mode, device, prefix) and returns: results,  preds_list