code: def calc_mrr(
      emb, w, test_mask, triplets_to_filter, batch_size=100, filter=True
  ):
      with torch.no_grad():
          test_triplets = triplets_to_filter[test_mask]
          s, r, o = (
              test_triplets[:, 0],
              test_triplets[:, 1],
              test_triplets[:, 2],
          )
          test_size = len(s)
          triplets_to_filter = {
              tuple(triplet) for triplet in triplets_to_filter.tolist()
          }
          ranks_s = perturb_and_get_filtered_rank(
              emb,
              w,
              s,
              r,
              o,
              test_size,
              triplets_to_filter,
              filter_o=False,
          )
          ranks_o = perturb_and_get_filtered_rank(
              emb, w, s, r, o, test_size, triplets_to_filter
          )
          ranks = torch.cat([ranks_s, ranks_o])
          ranks += 1  # change to 1-indexed
          mrr = torch.mean(1.0 / ranks.float()).item()
      return mrr
  
imports: import dgl
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  import tqdm
  from dgl.data.knowledge_graph import FB15k237Dataset
  from dgl.dataloading import GraphDataLoader
  from dgl.nn.pytorch import RelGraphConv
label_desc: Use image node_id 4 for calling a global function with example usage: calc_mrr(emb, w, test_mask, triplets_to_filter, batch_size, filter) and returns: mrr