code: def evaluate(model, data_iterator, params, ex_params, mark="Val"):
      """Evaluate the model on `steps` batches."""
      # set model to evaluation mode
      model.eval()
      rel_num = params.rel_num
  
      predictions = []
      ground_truths = []
      correct_num, predict_num, gold_num = 0, 0, 0
  
      for batch in tqdm(data_iterator, unit="Batch", ascii=True):
          # to device
          batch = tuple(
              t.to(params.device) if isinstance(t, torch.Tensor) else t
              for t in batch
          )
          input_ids, attention_mask, triples, input_tokens = batch
          bs, seq_len = input_ids.size()
  
          # inference
          with torch.no_grad():
              pred_seqs, pre_corres, xi, pred_rels = model(
                  input_ids,
                  attention_mask=attention_mask,
                  ex_params=ex_params,
              )
  
              # (sum(x_i), seq_len)
              pred_seqs = pred_seqs.detach().cpu().numpy()
              # (bs, seq_len, seq_len)
              pre_corres = pre_corres.detach().cpu().numpy()
          if ex_params["ensure_rel"]:
              # (bs,)
              xi = np.array(xi)
              # (sum(s_i),)
              pred_rels = pred_rels.detach().cpu().numpy()
              # decode by per batch
              xi_index = np.cumsum(xi).tolist()
              # (bs+1,)
              xi_index.insert(0, 0)
  
          for idx in range(bs):
              if ex_params["ensure_rel"]:
                  pre_triples = tag_mapping_corres(
                      predict_tags=pred_seqs[
                          xi_index[idx] : xi_index[idx + 1]
                      ],
                      pre_corres=pre_corres[idx],
                      pre_rels=pred_rels[
                          xi_index[idx] : xi_index[idx + 1]
                      ],
                      label2idx_sub=Label2IdxSub,
                      label2idx_obj=Label2IdxObj,
                  )
              else:
                  pre_triples = tag_mapping_corres(
                      predict_tags=pred_seqs[
                          idx * rel_num : (idx + 1) * rel_num
                      ],
                      pre_corres=pre_corres[idx],
                      label2idx_sub=Label2IdxSub,
                      label2idx_obj=Label2IdxObj,
                  )
  
              gold_triples = span2str(triples[idx], input_tokens[idx])
              pre_triples = span2str(pre_triples, input_tokens[idx])
              ground_truths.append(list(set(gold_triples)))
              predictions.append(list(set(pre_triples)))
              # counter
              correct_num += len(set(pre_triples) & set(gold_triples))
              predict_num += len(set(pre_triples))
              gold_num += len(set(gold_triples))
      metrics = get_metrics(correct_num, predict_num, gold_num)
      # logging loss, f1 and report
      metrics_str = "; ".join(
          "{}: {:05.3f}".format(k, v) for k, v in metrics.items()
      )
      logging.info("- {} metrics:\n".format(mark) + metrics_str)
      return metrics, predictions, ground_truths
  
file_path: DeepKE/example/triple/PRGC/predict.py
imports: import json
  import logging
  import random
  import argparse
  from tqdm import tqdm
  import os
  import torch
  import numpy
  import pandas
  import hydra
  from hydra.utils import get_original_cwd
  from deepke.triple_extraction.PRGC import *
label_desc: Use image node_id 3 for calling a global function with example usage: evaluate(model, data_iterator, params, ex_params, mark) and returns: metrics,  predictions,  ground_truths