code: def __init__(
      self,
      ent_tot,
      rel_tot,
      dim_e=100,
      dim_r=100,
      p_norm=1,
      norm_flag=True,
      rand_init=False,
      margin=None,
  ):
      super(TransR, self).__init__(ent_tot, rel_tot)
  
      self.dim_e = dim_e
      self.dim_r = dim_r
      self.norm_flag = norm_flag
      self.p_norm = p_norm
      self.rand_init = rand_init
  
      self.ent_embeddings = nn.Embedding(self.ent_tot, self.dim_e)
      self.rel_embeddings = nn.Embedding(self.rel_tot, self.dim_r)
      nn.init.xavier_uniform_(self.ent_embeddings.weight.data)
      nn.init.xavier_uniform_(self.rel_embeddings.weight.data)
  
      self.transfer_matrix = nn.Embedding(
          self.rel_tot, self.dim_e * self.dim_r
      )
      if not self.rand_init:
          identity = torch.zeros(self.dim_e, self.dim_r)
          for i in range(min(self.dim_e, self.dim_r)):
              identity[i][i] = 1
          identity = identity.view(self.dim_r * self.dim_e)
          for i in range(self.rel_tot):
              self.transfer_matrix.weight.data[i] = identity
      else:
          nn.init.xavier_uniform_(self.transfer_matrix.weight.data)
  
      if margin != None:
          self.margin = nn.Parameter(torch.Tensor([margin]))
          self.margin.requires_grad = False
          self.margin_flag = True
      else:
          self.margin_flag = False
  
file_path: OpenKE/openke/module/model/TransR.py
imports: import torch
  import torch.nn
  import torch.nn.functional
  from .Model import Model
label_desc: Use image node_id 1 to create a new TransR object from inherited base classes: Model with example: obj = TransR(ent_tot, rel_tot, dim_e, dim_r, p_norm, norm_flag, rand_init, margin)