(self)
| 470 | |
| 471 | # create model |
| 472 | def _create_model(self): |
| 473 | # input layer to get embedding of features |
| 474 | with tf.variable_scope('input_layer', |
| 475 | partitioner=self._input_layer_partitioner, |
| 476 | reuse=tf.AUTO_REUSE): |
| 477 | uid_emb, item_emb, his_item_emb, noclk_his_item_emb, sequence_length = self._embedding_input_layer( |
| 478 | ) |
| 479 | |
| 480 | if self.bf16: |
| 481 | uid_emb = tf.cast(uid_emb, tf.bfloat16) |
| 482 | item_emb = tf.cast(item_emb, tf.bfloat16) |
| 483 | his_item_emb = tf.cast(his_item_emb, tf.bfloat16) |
| 484 | noclk_his_item_emb = tf.cast(noclk_his_item_emb, tf.bfloat16) |
| 485 | |
| 486 | item_his_eb_sum = tf.reduce_sum(his_item_emb, 1) |
| 487 | mask = tf.sequence_mask(sequence_length) |
| 488 | |
| 489 | # RNN layer_1 |
| 490 | with tf.variable_scope('rnn_1'): |
| 491 | run_output_1, _ = tf.nn.dynamic_rnn( |
| 492 | tf.nn.rnn_cell.GRUCell(self._hidden_size), |
| 493 | inputs=his_item_emb, |
| 494 | sequence_length=sequence_length, |
| 495 | dtype=self._data_type, |
| 496 | scope='gru1') |
| 497 | tf.summary.histogram('GRU_outputs', run_output_1) |
| 498 | |
| 499 | # Aux loss |
| 500 | aux_loss_scope = tf.variable_scope( |
| 501 | 'aux_loss', partitioner=self._dense_layer_partitioner) |
| 502 | with aux_loss_scope.keep_weights(dtype=tf.float32) if self.bf16 \ |
| 503 | else aux_loss_scope: |
| 504 | self._aux_loss = self._auxiliary_loss(run_output_1[:, :-1, :], |
| 505 | his_item_emb[:, 1:, :], |
| 506 | noclk_his_item_emb[:, 1:, :], |
| 507 | mask[:, 1:], |
| 508 | dtype=self._data_type, |
| 509 | stag='gru') |
| 510 | if self.bf16: |
| 511 | self._aux_loss = tf.cast(self._aux_loss, tf.float32) |
| 512 | |
| 513 | # Attention layer |
| 514 | attention_scope = tf.variable_scope('attention_layer') |
| 515 | with attention_scope.keep_weights(dtype=tf.float32) if self.bf16 \ |
| 516 | else attention_scope: |
| 517 | _, alphas = self._attention(item_emb, |
| 518 | run_output_1, |
| 519 | self._attention_size, |
| 520 | mask, |
| 521 | softmax_stag=1, |
| 522 | stag='1_1', |
| 523 | mode='LIST', |
| 524 | return_alphas=True) |
| 525 | tf.summary.histogram('alpha_outputs', alphas) |
| 526 | |
| 527 | # RNN layer_2 |
| 528 | with tf.variable_scope('rnn_2'): |
| 529 | _, final_state2 = tf.nn.dynamic_rnn( |
no test coverage detected