Tensorflow重用rnn_seq2seq模型
我正在尝试用tensorflow创建一个程序来处理序列。tf.nn.seq2seq函数中的一个选项是feed_previous参数。这是我可以在训练时使用的东西,但不能在评估/运行时使用。目前我尝试了以下方法:Tensorflow重用rnn_seq2seq模型,tensorflow,Tensorflow,我正在尝试用tensorflow创建一个程序来处理序列。tf.nn.seq2seq函数中的一个选项是feed_previous参数。这是我可以在训练时使用的东西,但不能在评估/运行时使用。目前我尝试了以下方法: (outputs_dict,state_dict) = tf.nn.seq2seq.one2many_rnn_seq2seq(enc_inp,decoder_inputs_dictionary,cell, vocab_size, decoder_symbols_dictionary,em
(outputs_dict,state_dict) = tf.nn.seq2seq.one2many_rnn_seq2seq(enc_inp,decoder_inputs_dictionary,cell, vocab_size, decoder_symbols_dictionary,embedding_size=embedding_dim)
(evaluation_dict,evaluation_state_dict) = tf.nn.seq2seq.one2many_rnn_seq2seq(enc_inp,decoder_inputs_dictionary,cell, vocab_size, decoder_symbols_dictionary,embedding_size=embedding_dim,feed_previous=True)
但是我得到了错误:“ValueError:Variable one2many\u rnn\u seq2seq/rnn/EmbeddingWrapper/embedding已经存在,不允许。您的意思是在VarScope中设置reuse=True吗?”
有人知道怎么做吗
- 重用我的模型,以便我可以在培训期间使用feed_previous,而不是在评估期间
- 艾伦给我指出了正确的方向
我用来解决问题的代码(我想)是:
你考虑过一个新的计划吗?您应该将它们都包装在具有相同名称的变量作用域中,并为第二个变量设置reuse=True!在这种情况下,不清楚如何使用变量作用域,请看我的答案,了解我用来修复它的代码。
with tf.variable_scope("decoder1") as scope:
(outputs_dict, state_dict) = tf.nn.seq2seq.one2many_rnn_seq2seq(enc_inp, train_decoder_inputs_dictionary,
cell, vocab_size, decoder_symbols_dictionary,
embedding_size=embedding_dim, feed_previous=True)
with tf.variable_scope("decoder1",reuse=True) as scope:
(runtime_outputs_dict, runtime_state_dict) = tf.nn.seq2seq.one2many_rnn_seq2seq(enc_inp, runtime_decoder_inputs_dictionary,
cell, vocab_size, decoder_symbols_dictionary,
embedding_size=embedding_dim, feed_previous=True)