code: def __init__(
      self,
      sess,
      emb_dim,
      rnn_units,
      alpha,
      max_seq_length,
      n_items,
      item_probs,
      adj_matrix,
      rnn_cell_type,
      rnn_dropout_rate,
      seed,
      lr,
  ):
      self.scope = "GRN"
      self.session = sess
      self.seed = seed
      self.lr = tf.constant(lr)
  
      self.emb_dim = emb_dim
      self.rnn_units = rnn_units
  
      self.max_seq_length = max_seq_length
      self.n_items = n_items
      self.item_probs = item_probs
      self.alpha = alpha
  
      with tf.variable_scope(self.scope):
          # Initialized for n_hop adjacency matrix
          self.A = tf.constant(
              adj_matrix.todense(), name="Adj_Matrix", dtype=tf.float32
          )
  
          uniform_initializer = (
              np.ones(shape=(self.n_items), dtype=np.float32)
              / self.n_items
          )
          self.I_B = tf.get_variable(
              dtype=tf.float32,
              initializer=tf.constant(
                  uniform_initializer, dtype=tf.float32
              ),
              name="I_B",
          )
          self.I_B_Diag = tf.nn.relu(tf.diag(self.I_B, name="I_B_Diag"))
  
          self.C_Basket = tf.get_variable(
              dtype=tf.float32,
              initializer=tf.constant(adj_matrix.mean()),
              name="C_B",
          )
          self.y = tf.placeholder(
              dtype=tf.float32,
              shape=(None, self.n_items),
              name="Target_basket",
          )
  
          # Basket Sequence encoder
          with tf.name_scope("Basket_Sequence_Encoder"):
              self.bseq = tf.sparse.placeholder(
                  dtype=tf.float32,
                  name="bseq_input",
              )
              self.bseq_length = tf.placeholder(
                  dtype=tf.int32, shape=(None,), name="bseq_length"
              )
  
              self.bseq_encoder = tf.sparse.reshape(
                  self.bseq, shape=[-1, self.n_items], name="bseq_2d"
              )
              self.bseq_encoder = self.encode_basket_graph(
                  self.bseq_encoder, self.C_Basket, True
              )
              self.bseq_encoder = tf.reshape(
                  self.bseq_encoder,
                  shape=[-1, self.max_seq_length, self.n_items],
                  name="bsxMxN",
              )
              self.bseq_encoder = create_basket_encoder(
                  self.bseq_encoder,
                  emb_dim,
                  param_initializer=tf.initializers.he_uniform(),
                  activation_func=tf.nn.relu,
              )
  
              # batch_size x max_seq_length x H
              rnn_encoder = create_rnn_encoder(
                  self.bseq_encoder,
                  self.rnn_units,
                  rnn_dropout_rate,
                  self.bseq_length,
                  rnn_cell_type,
                  param_initializer=tf.initializers.glorot_uniform(),
                  seed=self.seed,
              )
  
              # Hack to build the indexing and retrieve the right output. # batch_size x H
              h_T = get_last_right_output(
                  rnn_encoder,
                  self.max_seq_length,
                  self.bseq_length,
                  self.rnn_units,
              )
  
          # Next basket estimation
          with tf.name_scope("Next_Basket"):
              W_H = tf.get_variable(
                  dtype=tf.float32,
                  initializer=tf.initializers.glorot_uniform(),
                  shape=(self.rnn_units, self.n_items),
                  name="W_H",
              )
  
              next_item_probs = tf.nn.sigmoid(tf.matmul(h_T, W_H))
              logits = (
                  1.0 - self.alpha
              ) * next_item_probs + self.alpha * self.encode_basket_graph(
                  next_item_probs, tf.constant(0.0)
              )
  
          with tf.name_scope("Loss"):
              self.loss = self.compute_loss(logits, self.y)
  
              self.predictions = tf.nn.sigmoid(logits)
  
          # Adam optimizer
          train_op = tf.train.RMSPropOptimizer(learning_rate=self.lr)
  
          # Op to calculate every variable gradient
          self.grads = train_op.compute_gradients(
              self.loss, tf.trainable_variables()
          )
          self.update_grads = train_op.apply_gradients(self.grads)
  
file_path: cornac/cornac/models/beacon/beacon_tf.py
imports: import numpy
  import warnings
  import tensorflow.compat.v1
label_desc: Use image node_id 1 to create a new BeaconModel object  with example: obj = BeaconModel(sess, emb_dim, rnn_units, alpha, max_seq_length, n_items, item_probs, adj_matrix, rnn_cell_type, rnn_dropout_rate, seed, lr)