code: def filter(
      triplets_to_filter,
      target_s,
      target_r,
      target_o,
      num_nodes,
      filter_o=True,
  ):
      """Get candidate heads or tails to score"""
      target_s, target_r, target_o = (
          int(target_s),
          int(target_r),
          int(target_o),
      )
      # Add the ground truth node first
      if filter_o:
          candidate_nodes = [target_o]
      else:
          candidate_nodes = [target_s]
      for e in range(num_nodes):
          triplet = (
              (target_s, target_r, e)
              if filter_o
              else (e, target_r, target_o)
          )
          # Do not consider a node if it leads to a real triplet
          if triplet not in triplets_to_filter:
              candidate_nodes.append(e)
      return torch.LongTensor(candidate_nodes)
  
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 2 for calling a global function with example usage: filter(triplets_to_filter, target_s, target_r, target_o, num_nodes, filter_o) and returns: torch