我正在尝试了解seq2seq模型的程序。我找到了用于解码器的代码:
with tf.variable_scope("decode"):
output_layer = tf.layers.Dense(target_vocab_size)
train_output = decoding_layer_train(encoder_outputs,
encoder_state,
cells,
dec_embed_input,
target_sequence_length,
max_target_sequence_length,
output_layer,
keep_prob)
with tf.variable_scope("decode", reuse=True):
infer_output = decoding_layer_infer(encoder_outputs,
encoder_state,
cells,
dec_embeddings,
target_vocab_to_int['<GO>'],
target_vocab_to_int['<EOS>'],
max_target_sequence_length,
target_vocab_size,
output_layer,
batch_size,
keep_prob,
target_sequence_length)
为什么我们将相同的作用域“解码器”用于训练和推断输出。我猜想,reuse=True
参数将有助于使用我们从训练中得出的权重进行推断。