class_docstr: Base class for models
class_docstr_tok: ["Base","class","for","models"]
docstr: Initializing the model. Create common logics which are needed by all deeprec models, such as loss function,
  parameter set.
  
  Args:
      hparams (object): An `HParams` object, holds the entire set of hyperparameters.
      iterator_creator (object): An iterator to load the data.
      graph (object): An optional graph.
      seed (int): Random seed.
docstr_tok: ["Initializing","the","model",".","Create","common","logics","which","are","needed","by","all","deeprec","models",",","such","as","loss","function",",","parameter","set",".","Args",":","hparams","(","object",")",":","An","`","HParams","`","object",",","holds","the","entire","set","of","hyperparameters",".","iterator_creator","(","object",")",":","An","iterator","to","load","the","data",".","graph","(","object",")",":","An","optional","graph",".","seed","(","int",")",":","Random","seed","."]
code: def __init__(self, hparams, iterator_creator, graph=None, seed=None):
      """Initializing the model. Create common logics which are needed by all deeprec models, such as loss function,
      parameter set.
  
      Args:
          hparams (object): An `HParams` object, holds the entire set of hyperparameters.
          iterator_creator (object): An iterator to load the data.
          graph (object): An optional graph.
          seed (int): Random seed.
      """
      self.seed = seed
      tf.compat.v1.set_random_seed(seed)
      np.random.seed(seed)
  
      self.graph = graph if graph is not None else tf.Graph()
      self.iterator = iterator_creator(hparams, self.graph)
      self.train_num_ngs = (
          hparams.train_num_ngs
          if "train_num_ngs" in hparams.values()
          else None
      )
  
      with self.graph.as_default():
          self.hparams = hparams
  
          self.layer_params = []
          self.embed_params = []
          self.cross_params = []
          self.layer_keeps = tf.compat.v1.placeholder(
              tf.float32, name="layer_keeps"
          )
          self.keep_prob_train = None
          self.keep_prob_test = None
          self.is_train_stage = tf.compat.v1.placeholder(
              tf.bool, shape=(), name="is_training"
          )
          self.group = tf.compat.v1.placeholder(
              tf.int32, shape=(), name="group"
          )
  
          self.initializer = self._get_initializer()
  
          self.logit = self._build_graph()
          self.pred = self._get_pred(self.logit, self.hparams.method)
  
          self.loss = self._get_loss()
          self.saver = tf.compat.v1.train.Saver(
              max_to_keep=self.hparams.epochs
          )
          self.update = self._build_train_opt()
          self.extra_update_ops = tf.compat.v1.get_collection(
              tf.compat.v1.GraphKeys.UPDATE_OPS
          )
          self.init_op = tf.compat.v1.global_variables_initializer()
          self.merged = self._add_summaries()
  
      # set GPU use with on demand growth
      gpu_options = tf.compat.v1.GPUOptions(allow_growth=True)
      self.sess = tf.compat.v1.Session(
          graph=self.graph,
          config=tf.compat.v1.ConfigProto(gpu_options=gpu_options),
      )
      self.sess.run(self.init_op)
  
imports: from os.path import join
  import abc
  import time
  import os
  import numpy
  import tensorflow
  from recommenders.models.deeprec.deeprec_utils import cal_metric
label_desc: Use image node_id 1 to create a new BaseModel object  with example: obj = BaseModel(hparams, iterator_creator, graph, seed)