code: def ranking_and_hits_this(
      cfg,
      model,
      dev_rank_batcher,
      vocab,
      name,
      kg_graph=None,
      logger=None,
  ):
      print("")
      print("-" * 50)
      print(name)
      print("-" * 50)
      print("")
      if logger is not None:
          logger.write("")
          logger.write("-" * 50)
          logger.write(name)
          logger.write("-" * 50)
          logger.write("")
      hits_left = []
      hits_right = []
      hits = []
      ranks = []
      ranks_left = []
      ranks_right = []
      for _ in range(10):
          hits_left.append([])
          hits_right.append([])
          hits.append([])
  
      for i, str2var in enumerate(dev_rank_batcher):
          e1 = str2var["e1_tensor"]
          e2 = str2var["e2_tensor"]
          rel = str2var["rel_tensor"]
          rel_reverse = str2var["rel_eval_tensor"]
          e2_multi1 = str2var["e2_multi1"].float()
          e2_multi2 = str2var["e2_multi2"].float()
          if cfg["cuda"]:
              e1 = e1.to("cuda")
              e2 = e2.to("cuda")
              rel = rel.to("cuda")
              rel_reverse = rel_reverse.to("cuda")
              e2_multi1 = e2_multi1.to("cuda")
              e2_multi2 = e2_multi2.to("cuda")
  
          pred1 = model(e1, rel, kg_graph)
          pred2 = model(e2, rel_reverse, kg_graph)
          pred1, pred2 = pred1.data, pred2.data
          e1, e2 = e1.data, e2.data
          e2_multi1, e2_multi2 = e2_multi1.data, e2_multi2.data
          for i in range(e1.shape[0]):
              # these filters contain ALL labels
              filter1 = e2_multi1[i].long()
              filter2 = e2_multi2[i].long()
  
              # save the prediction that is relevant
              target_value1 = pred1[i, e2[i, 0].item()].item()
              target_value2 = pred2[i, e1[i, 0].item()].item()
              # zero all known cases (this are not interesting)
              # this corresponds to the filtered setting
              pred1[i][filter1] = 0.0
              pred2[i][filter2] = 0.0
              # write base the saved values
              pred1[i][e2[i]] = target_value1
              pred2[i][e1[i]] = target_value2
  
          # sort and rank
          max_values, argsort1 = torch.sort(pred1, 1, descending=True)
          max_values, argsort2 = torch.sort(pred2, 1, descending=True)
  
          argsort1 = argsort1.cpu().numpy()
          argsort2 = argsort2.cpu().numpy()
          for i in range(e1.shape[0]):
              # find the rank of the target entities
              rank1 = np.where(argsort1[i] == e2[i, 0].item())[0][0]
              rank2 = np.where(argsort2[i] == e1[i, 0].item())[0][0]
              # rank+1, since the lowest rank is rank 1 not rank 0
              ranks.append(rank1 + 1)
              ranks_left.append(rank1 + 1)
              ranks.append(rank2 + 1)
              ranks_right.append(rank2 + 1)
  
              # this could be done more elegantly, but here you go
              for hits_level in range(10):
                  if rank1 <= hits_level:
                      hits[hits_level].append(1.0)
                      hits_left[hits_level].append(1.0)
                  else:
                      hits[hits_level].append(0.0)
                      hits_left[hits_level].append(0.0)
  
                  if rank2 <= hits_level:
                      hits[hits_level].append(1.0)
                      hits_right[hits_level].append(1.0)
                  else:
                      hits[hits_level].append(0.0)
                      hits_right[hits_level].append(0.0)
  
          # dev_rank_batcher.state.loss = [0]
  
      for i in range(10):
          print(
              "Hits left @{0}: {1}".format(i + 1, np.mean(hits_left[i]))
          )
          print(
              "Hits right @{0}: {1}".format(
                  i + 1, np.mean(hits_right[i])
              )
          )
          print("Hits @{0}: {1}".format(i + 1, np.mean(hits[i])))
      print("Mean rank left: {0}".format(np.mean(ranks_left)))
      print("Mean rank right: {0}".format(np.mean(ranks_right)))
      print("Mean rank: {0}".format(np.mean(ranks)))
      print(
          "Mean reciprocal rank left: {0}".format(
              np.mean(1.0 / np.array(ranks_left))
          )
      )
      print(
          "Mean reciprocal rank right: {0}".format(
              np.mean(1.0 / np.array(ranks_right))
          )
      )
      print(
          "Mean reciprocal rank: {0}".format(
              np.mean(1.0 / np.array(ranks))
          )
      )
  
      if logger is not None:
          for i in [0, 9]:
              logger.write(
                  "Hits left @{0}: {1}".format(
                      i + 1, np.mean(hits_left[i])
                  )
              )
              logger.write(
                  "Hits right @{0}: {1}".format(
                      i + 1, np.mean(hits_right[i])
                  )
              )
              logger.write(
                  "Hits @{0}: {1}".format(i + 1, np.mean(hits[i]))
              )
          logger.write(
              "Mean rank left: {0}".format(np.mean(ranks_left))
          )
          logger.write(
              "Mean rank right: {0}".format(np.mean(ranks_right))
          )
          logger.write("Mean rank: {0}".format(np.mean(ranks)))
          logger.write(
              "Mean reciprocal rank left: {0}".format(
                  np.mean(1.0 / np.array(ranks_left))
              )
          )
          logger.write(
              "Mean reciprocal rank right: {0}".format(
                  np.mean(1.0 / np.array(ranks_right))
              )
          )
          logger.write(
              "Mean reciprocal rank: {0}".format(
                  np.mean(1.0 / np.array(ranks))
              )
          )
  
      return np.mean(1.0 / np.array(ranks))
  
imports: import argparse
  import os
  import numpy
  import torch
  import torch.backends.cudnn
  import torch.nn
  from torch.utils.data import DataLoader
  from graph4nlp.pytorch.datasets.kinship import KinshipDataset
  from graph4nlp.pytorch.modules.utils.config_utils import get_yaml_config
  from graph4nlp.pytorch.modules.utils.logger import Logger
  from .model import Complex, ConvE, Distmult, GCNComplex, GCNDistMult, GGNNDistMult
label_desc: Use image node_id 1 for calling a global function with example usage: ranking_and_hits_this(cfg, model, dev_rank_batcher, vocab, name, kg_graph, logger) and returns: np