class_docstr: Correlation-Sensitive Next-Basket Recommendation
  
  Parameters
  ----------
  name: string, default: 'Beacon'
      The name of the recommender model.
  
  emb_dim: int, optional, default: 2
      Embedding dimension
  
  rnn_unit: int, optional, default: 4
      Number of dimension in a rnn unit.
  
  alpha: float, optional, default: 0.5
      Hyperparameter to control the balance between correlative and sequential associations.
  
  rnn_cell_type: str, optional, default: 'LSTM'
      RNN cell type, options including ['LSTM', 'GRU', None]
      If None, BasicRNNCell will be used.
  
  dropout_rate: float, optional, default: 0.5
      Dropout rate of neural network dense layers
  
  nb_hop: int, optional, default: 1
      Number of hops for constructing correlation matrix.
      If 0, zeros matrix will be used.
  
  n_epochs: int, optional, default: 15
      Number of training epochs
  
  batch_size: int, optional, default: 32
      Batch size
  
  lr: float, optional, default: 0.001
      Initial value of learning rate for the optimizer.
  
  verbose: boolean, optional, default: False
      When True, running logs are displayed.
  
  seed: int, optional, default: None
      Random seed
  
  References
  ----------
  LE, Duc Trong, Hady Wirawan LAUW, and Yuan Fang.
  Correlation-sensitive next-basket recommendation.
  International Joint Conferences on Artificial Intelligence, 2019.
class_docstr_tok: ["Correlation-Sensitive","Next-Basket","Recommendation","Parameters","--","--","--","--","--","name",":","string",",","default",":","'Beacon'","The","name","of","the","recommender","model",".","emb_dim",":","int",",","optional",",","default",":","2","Embedding","dimension","rnn_unit",":","int",",","optional",",","default",":","4","Number","of","dimension","in","a","rnn","unit",".","alpha",":","float",",","optional",",","default",":","0.5","Hyperparameter","to","control","the","balance","between","correlative","and","sequential","associations",".","rnn_cell_type",":","str",",","optional",",","default",":","'LSTM'","RNN","cell","type",",","options","including","[","'LSTM","'",",","'GRU","'",",","None","]","If","None",",","BasicRNNCell","will","be","used",".","dropout_rate",":","float",",","optional",",","default",":","0.5","Dropout","rate","of","neural","network","dense","layers","nb_hop",":","int",",","optional",",","default",":","1","Number","of","hops","for","constructing","correlation","matrix",".","If","0",",","zeros","matrix","will","be","used",".","n_epochs",":","int",",","optional",",","default",":","15","Number","of","training","epochs","batch_size",":","int",",","optional",",","default",":","32","Batch","size","lr",":","float",",","optional",",","default",":","0.001","Initial","value","of","learning","rate","for","the","optimizer",".","verbose",":","boolean",",","optional",",","default",":","False","When","True",",","running","logs","are","displayed",".","seed",":","int",",","optional",",","default",":","None","Random","seed","References","--","--","--","--","--","LE",",","Duc","Trong",",","Hady","Wirawan","LAUW",",","and","Yuan","Fang",".","Correlation-sensitive","next-basket","recommendation",".","International","Joint","Conferences","on","Artificial","Intelligence",",","2019","."]
code: def fit(self, train_set, val_set=None):
      import tensorflow.compat.v1 as tf
  
      from .beacon_tf import BeaconModel
  
      tf.disable_eager_execution()
  
      # less verbose TF
      os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"
      tf.logging.set_verbosity(tf.logging.ERROR)
  
      super().fit(train_set=train_set, val_set=val_set)
  
      self.correlation_matrix = self._build_correlation_matrix(
          train_set=train_set, val_set=val_set, n_items=self.total_items
      )
      self.item_probs = self._compute_item_probs(
          train_set=train_set, val_set=val_set, n_items=self.total_items
      )
  
      config = tf.ConfigProto()
      config.gpu_options.allow_growth = True
      config.log_device_placement = False
      sess = tf.Session(config=config)
  
      self.model = BeaconModel(
          sess,
          self.emb_dim,
          self.rnn_unit,
          self.alpha,
          train_set.max_basket_size,
          self.total_items,
          self.item_probs,
          self.correlation_matrix,
          self.rnn_cell_type,
          self.dropout_rate,
          self.seed,
          self.lr,
      )
  
      sess.run(tf.global_variables_initializer())  # init variable
  
      last_loss = np.inf
      last_val_loss = np.inf
      loop = trange(self.n_epochs, disable=not self.verbose)
      loop.set_postfix(
          loss=last_loss,
          val_loss=last_val_loss,
      )
      train_pool = []
      validation_pool = []
      for _ in loop:
          train_loss = 0.0
          trained_cnt = 0
          for batch_basket_items in self._data_iter(
              train_set, shuffle=True, current_pool=train_pool
          ):
              s, s_length, y = self._transform_data(
                  batch_basket_items, self.total_items
              )
              loss = self.model.train_batch(s, s_length, y)
              current_batch_size = len(batch_basket_items)
              trained_cnt += current_batch_size
              train_loss += loss * current_batch_size
              last_loss = train_loss / trained_cnt
              loop.set_postfix(
                  loss=last_loss,
                  val_loss=last_val_loss,
              )
  
          if val_set is not None:
              val_loss = 0.0
              val_cnt = 0
              for batch_basket_items in self._data_iter(
                  val_set, shuffle=False, current_pool=validation_pool
              ):
                  s, s_length, y = self._transform_data(
                      batch_basket_items, self.total_items
                  )
                  loss = self.model.validate_batch(s, s_length, y)
                  current_batch_size = len(batch_basket_items)
                  val_cnt += current_batch_size
                  val_loss += loss * current_batch_size
                  last_val_loss = val_loss / val_cnt
                  loop.set_postfix(
                      loss=last_loss,
                      val_loss=last_val_loss,
                  )
  
      return self
  
file_path: cornac/cornac/models/beacon/recom_beacon.py
imports: import os
  from collections import Counter
  import numpy
  from scipy.sparse import csc_matrix, csr_matrix, diags
  from tqdm.auto import trange
  from ..recommender import NextBasketRecommender
label_desc: Use image node_id 2 for calling the Beacon obj's underlying member method code with example usage: obj.fit(train_set, val_set) and returns: self