class_docstr: DKN model (Deep Knowledge-Aware Network)
  
  :Citation:
  
      H. Wang, F. Zhang, X. Xie and M. Guo, "DKN: Deep Knowledge-Aware Network for News
      Recommendation", in Proceedings of the 2018 World Wide Web Conference on World
      Wide Web, 2018.
class_docstr_tok: ["DKN","model","(","Deep","Knowledge-Aware","Network",")",":","Citation",":","H.","Wang",",","F.","Zhang",",","X.","Xie","and","M.","Guo",",","``","DKN",":","Deep","Knowledge-Aware","Network","for","News","Recommendation","''",",","in","Proceedings","of","the","2018","World","Wide","Web","Conference","on","World","Wide","Web",",","2018","."]
docstr: Initialization steps for DKN.
  Compared with the BaseModel, DKN requires two different pre-computed embeddings,
  i.e. word embedding and entity embedding.
  After creating these two embedding variables, BaseModel's `__init__` method will be called.
  
  Args:
      hparams (object): Global hyper-parameters.
      iterator_creator (object): DKN data loader class.
docstr_tok: ["Initialization","steps","for","DKN",".","Compared","with","the","BaseModel",",","DKN","requires","two","different","pre-computed","embeddings",",","i.e",".","word","embedding","and","entity","embedding",".","After","creating","these","two","embedding","variables",",","BaseModel","'s","`","__init__","`","method","will","be","called",".","Args",":","hparams","(","object",")",":","Global","hyper-parameters",".","iterator_creator","(","object",")",":","DKN","data","loader","class","."]
code: def __init__(self, hparams, iterator_creator):
      """Initialization steps for DKN.
      Compared with the BaseModel, DKN requires two different pre-computed embeddings,
      i.e. word embedding and entity embedding.
      After creating these two embedding variables, BaseModel's `__init__` method will be called.
  
      Args:
          hparams (object): Global hyper-parameters.
          iterator_creator (object): DKN data loader class.
      """
      self.graph = tf.Graph()
      with self.graph.as_default():
          with tf.compat.v1.name_scope("embedding"):
              word2vec_embedding = self._init_embedding(
                  hparams.wordEmb_file
              )
              self.embedding = tf.Variable(
                  word2vec_embedding, trainable=True, name="word"
              )
  
              if hparams.use_entity:
                  e_embedding = self._init_embedding(
                      hparams.entityEmb_file
                  )
                  W = tf.Variable(
                      tf.random.uniform(
                          [hparams.entity_dim, hparams.dim], -1, 1
                      ),
                      trainable=True,
                  )
                  b = tf.Variable(
                      tf.zeros([hparams.dim]), trainable=True
                  )
                  self.entity_embedding = tf.nn.tanh(
                      tf.matmul(e_embedding, W) + b
                  )
              else:
                  self.entity_embedding = tf.Variable(
                      tf.constant(
                          0.0,
                          shape=[hparams.entity_size, hparams.dim],
                          dtype=tf.float32,
                      ),
                      trainable=True,
                      name="entity",
                  )
  
              if hparams.use_context:
                  c_embedding = self._init_embedding(
                      hparams.contextEmb_file
                  )
                  W = tf.Variable(
                      tf.random.uniform(
                          [hparams.entity_dim, hparams.dim], -1, 1
                      ),
                      trainable=True,
                  )
                  b = tf.Variable(
                      tf.zeros([hparams.dim]), trainable=True
                  )
                  self.context_embedding = tf.nn.tanh(
                      tf.matmul(c_embedding, W) + b
                  )
              else:
                  self.context_embedding = tf.Variable(
                      tf.constant(
                          0.0,
                          shape=[hparams.entity_size, hparams.dim],
                          dtype=tf.float32,
                      ),
                      trainable=True,
                      name="context",
                  )
  
      super().__init__(hparams, iterator_creator, graph=self.graph)
  
file_path: recommenders/recommenders/models/deeprec/models/dkn.py
imports: import numpy
  import tensorflow
  from recommenders.models.deeprec.models.base_model import BaseModel
label_desc: Use image node_id 1 to create a new DKN object from inherited base classes: BaseModel with example: obj = DKN(hparams, iterator_creator)