class_docstr: NAML model(Neural News Recommendation with Attentive Multi-View Learning)
  
  Chuhan Wu, Fangzhao Wu, Mingxiao An, Jianqiang Huang, Yongfeng Huang and Xing Xie,
  Neural News Recommendation with Attentive Multi-View Learning, IJCAI 2019
  
  Attributes:
      word2vec_embedding (numpy.ndarray): Pretrained word embedding matrix.
      hparam (object): Global hyper-parameters.
class_docstr_tok: ["NAML","model","(","Neural","News","Recommendation","with","Attentive","Multi-View","Learning",")","Chuhan","Wu",",","Fangzhao","Wu",",","Mingxiao","An",",","Jianqiang","Huang",",","Yongfeng","Huang","and","Xing","Xie",",","Neural","News","Recommendation","with","Attentive","Multi-View","Learning",",","IJCAI","2019","Attributes",":","word2vec_embedding","(","numpy.ndarray",")",":","Pretrained","word","embedding","matrix",".","hparam","(","object",")",":","Global","hyper-parameters","."]
docstr: The main function to create NAML's logic. The core of NAML
  is a user encoder and a news encoder.
  
  Returns:
      object: a model used to train.
      object: a model used to evaluate and predict.
docstr_tok: ["The","main","function","to","create","NAML","'s","logic",".","The","core","of","NAML","is","a","user","encoder","and","a","news","encoder",".","Returns",":","object",":","a","model","used","to","train",".","object",":","a","model","used","to","evaluate","and","predict","."]
code: def _build_naml(self):
      """The main function to create NAML's logic. The core of NAML
      is a user encoder and a news encoder.
  
      Returns:
          object: a model used to train.
          object: a model used to evaluate and predict.
      """
      hparams = self.hparams
  
      his_input_title = keras.Input(
          shape=(hparams.his_size, hparams.title_size), dtype="int32"
      )
      his_input_body = keras.Input(
          shape=(hparams.his_size, hparams.body_size), dtype="int32"
      )
      his_input_vert = keras.Input(
          shape=(hparams.his_size, 1), dtype="int32"
      )
      his_input_subvert = keras.Input(
          shape=(hparams.his_size, 1), dtype="int32"
      )
  
      pred_input_title = keras.Input(
          shape=(hparams.npratio + 1, hparams.title_size), dtype="int32"
      )
      pred_input_body = keras.Input(
          shape=(hparams.npratio + 1, hparams.body_size), dtype="int32"
      )
      pred_input_vert = keras.Input(
          shape=(hparams.npratio + 1, 1), dtype="int32"
      )
      pred_input_subvert = keras.Input(
          shape=(hparams.npratio + 1, 1), dtype="int32"
      )
  
      pred_input_title_one = keras.Input(
          shape=(
              1,
              hparams.title_size,
          ),
          dtype="int32",
      )
      pred_input_body_one = keras.Input(
          shape=(
              1,
              hparams.body_size,
          ),
          dtype="int32",
      )
      pred_input_vert_one = keras.Input(shape=(1, 1), dtype="int32")
      pred_input_subvert_one = keras.Input(shape=(1, 1), dtype="int32")
  
      his_title_body_verts = layers.Concatenate(axis=-1)(
          [
              his_input_title,
              his_input_body,
              his_input_vert,
              his_input_subvert,
          ]
      )
  
      pred_title_body_verts = layers.Concatenate(axis=-1)(
          [
              pred_input_title,
              pred_input_body,
              pred_input_vert,
              pred_input_subvert,
          ]
      )
  
      pred_title_body_verts_one = layers.Concatenate(axis=-1)(
          [
              pred_input_title_one,
              pred_input_body_one,
              pred_input_vert_one,
              pred_input_subvert_one,
          ]
      )
      pred_title_body_verts_one = layers.Reshape((-1,))(
          pred_title_body_verts_one
      )
  
      embedding_layer = layers.Embedding(
          self.word2vec_embedding.shape[0],
          hparams.word_emb_dim,
          weights=[self.word2vec_embedding],
          trainable=True,
      )
  
      self.newsencoder = self._build_newsencoder(embedding_layer)
      self.userencoder = self._build_userencoder(self.newsencoder)
  
      user_present = self.userencoder(his_title_body_verts)
      news_present = layers.TimeDistributed(self.newsencoder)(
          pred_title_body_verts
      )
      news_present_one = self.newsencoder(pred_title_body_verts_one)
  
      preds = layers.Dot(axes=-1)([news_present, user_present])
      preds = layers.Activation(activation="softmax")(preds)
  
      pred_one = layers.Dot(axes=-1)([news_present_one, user_present])
      pred_one = layers.Activation(activation="sigmoid")(pred_one)
  
      model = keras.Model(
          [
              his_input_title,
              his_input_body,
              his_input_vert,
              his_input_subvert,
              pred_input_title,
              pred_input_body,
              pred_input_vert,
              pred_input_subvert,
          ],
          preds,
      )
  
      scorer = keras.Model(
          [
              his_input_title,
              his_input_body,
              his_input_vert,
              his_input_subvert,
              pred_input_title_one,
              pred_input_body_one,
              pred_input_vert_one,
              pred_input_subvert_one,
          ],
          pred_one,
      )
  
      return model, scorer
  
file_path: recommenders/recommenders/models/newsrec/models/naml.py
imports: import numpy
  import tensorflow.keras
  from tensorflow.keras import layers
  from recommenders.models.newsrec.models.base_model import BaseModel
  from recommenders.models.newsrec.models.layers import AttLayer2
label_desc: Use image node_id 12 for calling the NAMLModel obj's underlying member method code with example usage: obj._build_naml() and returns: model,  scorer