Skip to main content
 首页 » 编程设计

python之tensorflow rnn : name 'seq2seq' is not defined

2025年05月04日27qlqwjy

我正在试用这个笔记本: https://github.com/sjchoi86/Tensorflow-101/blob/master/notebooks/char_rnn_sample_tutorial.ipynb

我在 [6] 中的这一行有问题:

outputs, final_state = seq2seq.rnn_decoder(inputs, istate, cell, loop_function=None, scope='rnnlm') 

我收到这个错误:

NameError: name 'seq2seq' is not defined 

我正在使用 tensorflow 1.0.1。我试过了

tf.contrib.seq2seq 

但我收到错误:

AttributeError: 'module' object has no attribute 'rnn_decoder' 

我认为这是在 tensorflow 1.0.1 中新实现的 rnn 网络的问题,但我不知道如何解决它。

请您参考如下方法:

因为seq2seq已经被移到tf.contrib.legacy_seq2seq .您应该将此行更改为:

outputs, final_state = tf.contrib.legacy_seq2seq.rnn_decoder(inputs, istate, cell, loop_function=None, scope='rnnlm')