No feed_previous argument to tensorflow basic_rnn_seq2seq

The function embedding_rnn_seq2seqin the seq2seq module with tensor flows provides an argument feed_previous, which means that during decoding it uses only the first input of the decoder, and then uses the previous output of the decoder for subsequent inputs of the decoder. Is there an easy way to get this behavior from a function basic_rnn_seq2seq?

+4
source share
1 answer

This API is now deprecated, but if someone else is looking for a solution, I suggest looking at this GitHub repo: raindeer / seq2seq_experiments

In short, to create his own decoder, the author uses the following (important part loop_function):

def _init_seq2seq(self, encoder_inputs, decoder_inputs, cell, feed_previous):

    def inference_loop_function(prev, _):
        prev = tf.nn.xw_plus_b(prev, self.w_softmax, self.b_softmax)
        return tf.to_float(tf.equal(prev, tf.reduce_max(prev, reduction_indices=[1], keep_dims=True)))

    loop_function = inference_loop_function if feed_previous else None

    with variable_scope.variable_scope('seq2seq'):
        _, final_enc_state = rnn.rnn(cell, encoder_inputs, dtype=dtypes.float32)
        return seq2seq.rnn_decoder(decoder_inputs, final_enc_state, cell, loop_function=loop_function)
0
source

All Articles