code: def evaluate(
      model,
      loader,
      evaluate_mode="test",
      filter_dict=None,
      save_path="./tmp/",
      data_mode="hrt",
  ):
      """Evaluate given KGE model."""
      if data_mode == "wikikg2":
          evaluate_wikikg2(model, loader, evaluate_mode, save_path)
      elif data_mode == "wikikg90m":
          evaluate_wikikg90m(model, loader, evaluate_mode, save_path)
      else:
          model.eval()
          with paddle.no_grad():
              h_metrics = []
              t_metrics = []
              output = {"h,r->t": {}, "t,r->h": {}, "average": {}}
  
              for h, r, t in tqdm(loader):
                  t_score = model.predict(h, r, mode="tail")
                  h_score = model.predict(t, r, mode="head")
  
                  if filter_dict is not None:
                      h_filter_list = [
                          filter_dict["head"][(ti, ri)]
                          for ti, ri in zip(t.numpy(), r.numpy())
                      ]
                      t_filter_list = [
                          filter_dict["tail"][(hi, ri)]
                          for hi, ri in zip(h.numpy(), r.numpy())
                      ]
                  else:
                      h_filter_list = None
                      t_filter_list = None
  
                  h_metrics += calculate_metrics(
                      h_score, h, h_filter_list
                  )
                  t_metrics += calculate_metrics(
                      t_score, t, t_filter_list
                  )
  
              for metric in h_metrics[0].keys():
                  output["t,r->h"][metric] = np.mean(
                      [x[metric] for x in h_metrics]
                  )
                  output["h,r->t"][metric] = np.mean(
                      [x[metric] for x in t_metrics]
                  )
                  output["average"][metric] = (
                      output["t,r->h"][metric]
                      + output["h,r->t"][metric]
                  ) / 2
              logging.info(
                  "-------------- %s result --------------"
                  % evaluate_mode
              )
              logging.info(
                  "t,r->h  |"
                  + " ".join(
                      [
                          "{}: {}".format(k, v)
                          for k, v in output["t,r->h"].items()
                      ]
                  )
              )
              logging.info(
                  "h,r->t  |"
                  + " ".join(
                      [
                          "{}: {}".format(k, v)
                          for k, v in output["h,r->t"].items()
                      ]
                  )
              )
              logging.info(
                  "average |"
                  + " ".join(
                      [
                          "{}: {}".format(k, v)
                          for k, v in output["average"].items()
                      ]
                  )
              )
              logging.info("-----------------------------------------")
  
imports: import os
  import csv
  import math
  import json
  import time
  import random
  import logging
  import functools
  import traceback
  from collections import defaultdict
  from _thread import start_new_thread
  from multiprocessing import Queue, Process
  import numpy
  from tqdm import tqdm
  import paddle
  import paddle.distributed
label_desc: Use image node_id 9 for calling a global function with example usage: evaluate(model, loader, evaluate_mode, filter_dict, save_path, data_mode) without return types