class_docstr: Implementation of GATNE model.
  
  Args:
      config: dict, some configure parameters.
      dataset: instance of Dataset class
      place: GPU or CPU place 
class_docstr_tok: ["Implementation","of","GATNE","model",".","Args",":","config",":","dict",",","some","configure","parameters",".","dataset",":","instance","of","Dataset","class","place",":","GPU","or","CPU","place"]
docstr: Build the GATNE net.
          
docstr_tok: ["Build","the","GATNE","net","."]
code: def forward(self):
      """Build the GATNE net."""
      param_attr_init = fluid.initializer.Uniform(
          low=-1.0, high=1.0, seed=np.random.randint(100)
      )
      embed_param_attrs = fluid.ParamAttr(
          name="Base_node_embed", initializer=param_attr_init
      )
  
      # node_embeddings
      base_node_embed = fl.embedding(
          input=fl.reshape(self.train_inputs, shape=[-1, 1]),
          size=[self.num_nodes, self.embedding_size],
          param_attr=embed_param_attrs,
      )
  
      node_features = []
      for edge_type in self.edge_types:
          param_attr_init = fluid.initializer.Uniform(
              low=-1.0, high=1.0, seed=np.random.randint(100)
          )
          embed_param_attrs = fluid.ParamAttr(
              name="%s_node_embed" % edge_type,
              initializer=param_attr_init,
          )
  
          features = fl.embedding(
              input=self.gw[edge_type].node_feat["index"],
              size=[self.num_nodes, self.embedding_u_size],
              param_attr=embed_param_attrs,
          )
  
          node_features.append(features)
  
      # mp_output: list of embedding(self.num_nodes, dim)
      mp_output = self.message_passing(
          self.gw, self.edge_types, node_features
      )
  
      # U : (num_type[m], num_nodes, dim[s])
      node_type_embed = fl.stack(mp_output, axis=0)
  
      # U : (num_nodes, num_type[m], dim[s])
      node_type_embed = fl.transpose(node_type_embed, perm=[1, 0, 2])
  
      # gather node_type_embed from train_inputs
      node_type_embed = fl.gather(node_type_embed, self.train_inputs)
  
      # M_r
      tn_initializer = fluid.initializer.TruncatedNormalInitializer(
          loc=0.0, scale=1.0 / math.sqrt(self.embedding_size)
      )
  
      trans_weights = fl.create_parameter(
          shape=[
              self.edge_type_count,
              self.embedding_u_size,
              self.embedding_size // self.att_head,
          ],
          default_initializer=tn_initializer,
          dtype="float32",
          name="trans_w",
      )
  
      # W_r
      trans_weights_s1 = fl.create_parameter(
          shape=[
              self.edge_type_count,
              self.embedding_u_size,
              self.dim_a,
          ],
          default_initializer=tn_initializer,
          dtype="float32",
          name="trans_w_s1",
      )
  
      # w_r
      trans_weights_s2 = fl.create_parameter(
          shape=[self.edge_type_count, self.dim_a, self.att_head],
          default_initializer=tn_initializer,
          dtype="float32",
          name="trans_w_s2",
      )
  
      trans_w = fl.gather(trans_weights, self.train_types)
      trans_w_s1 = fl.gather(trans_weights_s1, self.train_types)
      trans_w_s2 = fl.gather(trans_weights_s2, self.train_types)
  
      attention = self.attention(
          node_type_embed, trans_w_s1, trans_w_s2
      )
      node_type_embed = fl.matmul(attention, node_type_embed)
      node_embed = base_node_embed + fl.reshape(
          fl.matmul(node_type_embed, trans_w), [-1, self.embedding_size]
      )
  
      self.last_node_embed = fl.l2_normalize(node_embed, axis=1)
  
      nce_weight_initializer = (
          fluid.initializer.TruncatedNormalInitializer(
              loc=0.0, scale=1.0 / math.sqrt(self.embedding_size)
          )
      )
      nce_weight_attrs = fluid.ParamAttr(
          name="nce_weight", initializer=nce_weight_initializer
      )
  
      weight_pos = fl.embedding(
          input=self.train_labels,
          size=[self.num_nodes, self.embedding_size],
          param_attr=nce_weight_attrs,
      )
      weight_neg = fl.embedding(
          input=self.train_negs,
          size=[self.num_nodes, self.embedding_size],
          param_attr=nce_weight_attrs,
      )
      tmp_node_embed = fl.unsqueeze(self.last_node_embed, axes=[1])
      pos_logits = fl.matmul(
          tmp_node_embed, weight_pos, transpose_y=True
      )  # [B, 1, 1]
  
      neg_logits = fl.matmul(
          tmp_node_embed, weight_neg, transpose_y=True
      )  # [B, 1, neg_num]
  
      pos_score = fl.squeeze(pos_logits, axes=[1])
      pos_score = fl.clip(pos_score, min=-10, max=10)
      pos_score = -1.0 * fl.logsigmoid(pos_score)
  
      neg_score = fl.squeeze(neg_logits, axes=[1])
      neg_score = fl.clip(neg_score, min=-10, max=10)
      neg_score = -1.0 * fl.logsigmoid(-1.0 * neg_score)
  
      neg_score = fl.reduce_sum(neg_score, dim=1, keep_dim=True)
      self.loss = fl.reduce_mean(pos_score + neg_score)
  
file_path: PGL/legacy/examples/GATNE/model.py
imports: import numpy
  import math
  import logging
  import paddle.fluid
  import paddle.fluid.layers
  from pgl import heter_graph_wrapper
label_desc: Use image node_id 2 for calling the GATNE obj's underlying member method code with example usage: obj.forward() without return types