seq2seq模型中与tf.variable_scope的混淆

时间:2019-02-03 18:07:06

标签: tensorflow nlp seq2seq

我正在尝试了解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参数将有助于使用我们从训练中得出的权重进行推断。

0 个答案:

没有答案