(self)
| 350 | |
| 351 | # create model |
| 352 | def _create_model(self): |
| 353 | # input layer to get embedding of features |
| 354 | with tf.variable_scope('input_layer', |
| 355 | partitioner=self._input_layer_partitioner, |
| 356 | reuse=tf.AUTO_REUSE): |
| 357 | uid_emb, item_emb, his_item_emb, sequence_length = self._embedding_input_layer( |
| 358 | ) |
| 359 | |
| 360 | item_his_eb_sum = tf.reduce_sum(his_item_emb, 1) |
| 361 | mask = tf.sequence_mask(sequence_length) |
| 362 | |
| 363 | # Attention layer |
| 364 | attention_scope = tf.variable_scope('attention_layer') |
| 365 | with attention_scope.keep_weights(dtype=tf.float32) if self.bf16 \ |
| 366 | else attention_scope: |
| 367 | attention_output = self._attention(item_emb, his_item_emb, |
| 368 | self._attention_size, mask) |
| 369 | att_fea = tf.reduce_sum(attention_output, 1) |
| 370 | tf.summary.histogram('alpha_outputs', att_fea) |
| 371 | |
| 372 | top_input = tf.concat([ |
| 373 | uid_emb, item_emb, item_his_eb_sum, item_emb * item_his_eb_sum, |
| 374 | att_fea |
| 375 | ], 1) |
| 376 | |
| 377 | if self.bf16: |
| 378 | top_input = tf.cast(top_input, tf.bfloat16) |
| 379 | # Top MLP layer |
| 380 | top_mlp_scope = tf.variable_scope( |
| 381 | 'top_mlp_layer', |
| 382 | partitioner=self._dense_layer_partitioner, |
| 383 | reuse=tf.AUTO_REUSE) |
| 384 | with top_mlp_scope.keep_weights(dtype=tf.float32) if self.bf16 \ |
| 385 | else top_mlp_scope: |
| 386 | self._logits = self._top_fc_layer(top_input) |
| 387 | if self.bf16: |
| 388 | self._logits = tf.cast(self._logits, dtype=tf.float32) |
| 389 | |
| 390 | self.probability = tf.math.sigmoid(self._logits) |
| 391 | self.output = tf.round(self.probability) |
| 392 | |
| 393 | # compute loss |
| 394 | def _create_loss(self): |
no test coverage detected