rmeertens
rmeertens

Reputation: 4451

Tensorflow re-use rnn_seq2seq model

I'm trying to create a program with tensorflow to do something with a sequence. An option in the tf.nn.seq2seq functions is the feed_previous parameter. This is something that I CAN use at train-time, but not at evaluation/runtime. Currently I tried this:

(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)

But I get the error: "ValueError: Variable one2many_rnn_seq2seq/RNN/EmbeddingWrapper/embedding already exists, disallowed. Did you mean to set reuse=True in VarScope?"

Does anybody know how to

Upvotes: 1

Views: 270

Answers (1)

rmeertens
rmeertens

Reputation: 4451

Allen pointed me in the right direction!

The code I used to solve my problems (I think) is:

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)

Upvotes: 1

Related Questions