code: def evaluate(args, model, features, tag="dev"):
      device = torch.device(
          "cuda:0" if torch.cuda.is_available() else "cpu"
      )
      dataloader = DataLoader(
          features,
          batch_size=args.test_batch_size,
          shuffle=False,
          collate_fn=collate_fn,
          drop_last=False,
      )
      preds = []
      total_loss = 0
      for i, batch in enumerate(dataloader):
          model.eval()
  
          inputs = {
              "input_ids": batch[0].to(device),
              "attention_mask": batch[1].to(device),
              "labels": batch[2],
              "entity_pos": batch[3],
              "hts": batch[4],
          }
  
          with torch.no_grad():
              output = model(**inputs)
              loss = output[0]
              pred = output[1].cpu().numpy()
              pred[np.isnan(pred)] = 0
              preds.append(pred)
              total_loss += loss.item()
  
      average_loss = total_loss / (i + 1)
      preds = np.concatenate(preds, axis=0).astype(np.float32)
      ans = to_official(args, preds, features)
      if len(ans) > 0:
          best_f1, _, best_f1_ign, _, re_p, re_r = official_evaluate(
              ans, args.data_dir
          )
      output = {
          tag + "_F1": best_f1 * 100,
          tag + "_F1_ign": best_f1_ign * 100,
          tag + "_re_p": re_p * 100,
          tag + "_re_r": re_r * 100,
          tag + "_average_loss": average_loss,
      }
  
      return best_f1, output
  
file_path: DeepKE/example/re/document/run.py
imports: import os
  import time
  import hydra
  from hydra.utils import get_original_cwd
  import numpy
  import torch
  import ujson
  from torch.utils.data import DataLoader
  from transformers import AutoConfig, AutoModel, AutoTokenizer
  from transformers.optimization import AdamW, get_linear_schedule_with_warmup
  from deepke.relation_extraction.document import *
  import wandb
label_desc: Use image node_id 2 for calling a global function with example usage: evaluate(args, model, features, tag) and returns: best_f1,  output