class_docstr: TransR model.
docstr: Construct train program
code: def construct_train_program(self):
      """
      Construct train program
      """
      (
          entity_embedding,
          relation_embedding,
          transfer_matrix,
      ) = self.creat_share_variables()
      pos_head = lookup_table(
          self.train_pos_input[:, 0], entity_embedding
      )
      pos_tail = lookup_table(
          self.train_pos_input[:, 2], entity_embedding
      )
      pos_rel = lookup_table(
          self.train_pos_input[:, 1], relation_embedding
      )
      neg_head = lookup_table(
          self.train_neg_input[:, 0], entity_embedding
      )
      neg_tail = lookup_table(
          self.train_neg_input[:, 2], entity_embedding
      )
      neg_rel = lookup_table(
          self.train_neg_input[:, 1], relation_embedding
      )
  
      rel_matrix = fluid.layers.reshape(
          lookup_table(self.train_pos_input[:, 1], transfer_matrix),
          [-1, self._hidden_size, self._hidden_size],
      )
      pos_head_trans = self.matmul_with_expend_dims(
          pos_head, rel_matrix
      )
      pos_tail_trans = self.matmul_with_expend_dims(
          pos_tail, rel_matrix
      )
  
      trans_neg = True
      if trans_neg:
          rel_matrix_neg = fluid.layers.reshape(
              lookup_table(self.train_neg_input[:, 1], transfer_matrix),
              [-1, self._hidden_size, self._hidden_size],
          )
          neg_head_trans = self.matmul_with_expend_dims(
              neg_head, rel_matrix_neg
          )
          neg_tail_trans = self.matmul_with_expend_dims(
              neg_tail, rel_matrix_neg
          )
      else:
          neg_head_trans = self.matmul_with_expend_dims(
              neg_head, rel_matrix
          )
          neg_tail_trans = self.matmul_with_expend_dims(
              neg_tail, rel_matrix
          )
  
      pos_score = self.score_with_l2_normalize(
          pos_head_trans, pos_rel, pos_tail_trans
      )
      neg_score = self.score_with_l2_normalize(
          neg_head_trans, neg_rel, neg_tail_trans
      )
  
      pos = fluid.layers.reduce_sum(
          fluid.layers.abs(pos_score), -1, keep_dim=False
      )
      neg = fluid.layers.reduce_sum(
          fluid.layers.abs(neg_score), -1, keep_dim=False
      )
      neg = fluid.layers.reshape(
          neg, shape=[-1, self._neg_times], inplace=True
      )
  
      loss = fluid.layers.reduce_mean(
          fluid.layers.relu(pos - neg + self._margin)
      )
      return [loss]
  
file_path: PGL/legacy/examples/pgl-ke/model/TransR.py
imports: import numpy
  import paddle.fluid
  from .Model import Model
  from .utils import lookup_table
label_desc: Use image node_id 5 for calling the TransR obj's underlying member method code with example usage: obj.construct_train_program() and returns: list