NELSONZHAO / zhihu

This repo contains the source code in my personal column (https://zhuanlan.zhihu.com/zhaoyeyu), implemented using Python 3.6. Including Natural Language Processing and Computer Vision projects, such as text generation, machine translation, deep convolution GAN and other actual combat code.
https://zhuanlan.zhihu.com/zhaoyeyu
3.5k stars 2.14k forks source link

seq2seq模型运行时错误:ValueError: too many values to unpack (expected 2) #6

Open bayou3 opened 7 years ago

bayou3 commented 7 years ago

首先感谢楼主的分享,对于basic_seq2seq中的代码,运行时产生如下错误,我的tensorflow是最新的1.3.0 gpu版本,执行时所有代码均未改动,想楼主帮看看 Traceback (most recent call last): File "D:\Workspaces\Eclipse\PythonLearn1\src\seq2seq__init__.py", line 227, in num_layers)
File "D:\Workspaces\Eclipse\PythonLearn1\src\seq2seq__init.py", line 189, in seq2seq_model decoder_input) File "D:\Workspaces\Eclipse\PythonLearn1\src\seq2seq\init__.py", line 146, in decoding_layer maximum_iterations=max_target_sequence_length) ValueError: too many values to unpack (expected 2)

NELSONZHAO commented 7 years ago

我重新跑了一遍,问题主要在于TensorFlow的版本问题,我当时写代码的版本是1.1,1.3的部分接口发生改变,这种问题修改调用接口的代码就可以。解决方案: 1.使用TensorFlow1.1版本重新跑。 2.decoding_layer函数里修改代码: training_decoder_output, _ = tf.contrib.seq2seq.dynamic_decode(training_decoder, impute_finished=True, maximum_iterations=max_target_sequence_length)training_decoder_output, _, _ = tf.contrib.seq2seq.dynamic_decode(training_decoder, impute_finished=True, maximum_iterations=max_target_sequence_length)

修改: predicting_decoder_output, _ = tf.contrib.seq2seq.dynamic_decode(predicting_decoder, impute_finished=True, maximum_iterations=max_target_sequence_length) 为: predicting_decoder_output, _, _ = tf.contrib.seq2seq.dynamic_decode(predicting_decoder, impute_finished=True, maximum_iterations=max_target_sequence_length)

1和2方案我都试过了,可以正常运行