Esempio n. 1
0
    def _build_encoded_sequences(self, sequences, length, mode, hparams):
        num_bi_layers = 1
        num_uni_layers = hparams.enc_num_layers - num_bi_layers

        # Build bidirectional layers.
        bi_outputs, bi_state = model_utils.build_bidirectional_rnn(
            sequences=sequences,
            length=length,
            num_layers=num_bi_layers,
            num_residual_layers=0,  # no residual connection
            num_units=hparams.hidden_size,
            unit_type=hparams.rnn_unit_type,
            forget_bias=hparams.rnn_forget_bias,
            dropout=hparams.dropout,
            mode=mode)

        # Build unidirectional layers.
        outputs, state = model_utils.build_unidirectional_rnn(
            sequences=bi_outputs,
            length=length,
            num_layers=num_uni_layers,
            num_residual_layers=hparams.enc_num_residual_layers,
            num_units=hparams.hidden_size,
            unit_type=hparams.rnn_unit_type,
            forget_bias=hparams.rnn_forget_bias,
            dropout=hparams.dropout,
            mode=mode)

        # Pass all encoder states to the decoder except the first in the bi-layer.
        state = (bi_state[1], ) + ((state, ) if num_uni_layers == 1 else state)

        return outputs, state
Esempio n. 2
0
 def _build_encoded_sequences(self, sequences, length, mode, hparams):
     return model_utils.build_unidirectional_rnn(
         sequences=sequences,
         length=length,
         num_layers=hparams.enc_num_layers,
         num_residual_layers=hparams.enc_num_residual_layers,
         num_units=hparams.hidden_size,
         unit_type=hparams.rnn_unit_type,
         forget_bias=hparams.rnn_forget_bias,
         dropout=hparams.dropout,
         mode=mode)