From 7a2e6dead9a8d13ade81e699932b5e78cb6ea64b Mon Sep 17 00:00:00 2001 From: peterzhang2029 Date: Thu, 25 Jan 2018 18:59:59 +0800 Subject: [PATCH] fix test_rnn_encoder_decoder --- ...encoder_context.py => test_rnn_encoder_decoder.py} | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) rename python/paddle/v2/fluid/tests/book/{test_machine_translation_encoder_context.py => test_rnn_encoder_decoder.py} (95%) diff --git a/python/paddle/v2/fluid/tests/book/test_machine_translation_encoder_context.py b/python/paddle/v2/fluid/tests/book/test_rnn_encoder_decoder.py similarity index 95% rename from python/paddle/v2/fluid/tests/book/test_machine_translation_encoder_context.py rename to python/paddle/v2/fluid/tests/book/test_rnn_encoder_decoder.py index 53ed912c6..3fd3dbaf7 100644 --- a/python/paddle/v2/fluid/tests/book/test_machine_translation_encoder_context.py +++ b/python/paddle/v2/fluid/tests/book/test_rnn_encoder_decoder.py @@ -118,12 +118,13 @@ def seq_to_seq_net(): src_forward, src_backward = bi_lstm_encoder( input_seq=src_embedding, hidden_size=encoder_size) - encoded_vector = fluid.layers.concat( - input=[src_forward, src_backward], axis=1) + src_forward_last = fluid.layers.sequence_last_step(input=src_forward) + src_backward_first = fluid.layers.sequence_first_step(input=src_backward) - enc_vec_last = fluid.layers.sequence_last_step(input=encoded_vector) + encoded_vector = fluid.layers.concat( + input=[src_forward_last, src_backward_first], axis=1) - decoder_boot = fluid.layers.fc(input=enc_vec_last, + decoder_boot = fluid.layers.fc(input=encoded_vector, size=decoder_size, bias_attr=False, act='tanh') @@ -137,7 +138,7 @@ def seq_to_seq_net(): dtype='float32') prediction = lstm_decoder_without_attention(trg_embedding, decoder_boot, - enc_vec_last, decoder_size) + encoded_vector, decoder_size) label = fluid.layers.data( name='label_sequence', shape=[1], dtype='int64', lod_level=1) cost = fluid.layers.cross_entropy(input=prediction, label=label) -- GitLab