我一直在研究基于this教程的seq2seq模型(尝试使用不同长度的输入和输出进行一些更改),只使用带有填充符号的我自己的数据集。但每当我尝试使用不同长度的输入和输出时,每当我尝试从中获得预测时,我总会得到以下错误:
InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'labels0' with dtype int32
[[Node: labels0 = Placeholder[dtype=DT_INT32, shape=[], _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
对于记录,这里是我的代码中的重要部分,我定义了变量和那些东西
Vairables:
encInput = [tf.placeholder(tf.int32, shape = (None,), name="inp%i" % t) for t in range(seqLengthT)]
labels = [tf.placeholder(tf.int32, shape = (None,), name="labels%i" % t) for t in range(seqLengthH)]
weights = [tf.ones_like(labels_t, dtype = tf.float32) for labels_t in labels]
decInput = ([tf.zeros_like(encInput[0], dtype = np.int32, name = "GO")] + labels[:-1])
prevMem = tf.zeros(batchSize, memoryDim)
Seq2Seq模型:
decOut, decMem = seq2seq.embedding_rnn_seq2seq(encInput, decInput, cell, vocabSizeT, vocabSizeH, embeddingDim, feed_previous = False)
损耗:
loss = seq2seq.sequence_loss(decOut, labels, weights, vocabSizeT)
测试输入:
feed_dic = {encInput[t]: batchX[t] for t in range(seqLengthT)} feed_dic[keep_prob] = 1
以下是似乎导致所有问题的一行:
decOutBat = sess.run(decOut, feed_dic)
对我来说没有任何意义的是,我已经尝试了所有我能想到的东西,而我却无处可去。我已经确定我正在以正确的dtype输入数组,我确保所有变量都是正确的长度。有趣的是,它适用于第一个输入,即" GO"符号,但之后它不起作用。当我以相同的序列长度运行输入和输出时,它工作正常,正常运行。我只是希望它以这种方式运行,因为当我输出预测时,它认为它们都是0,这是填充序列,我不完全理解如何实现bucketing,所以这对我来说是最好的路线去吧。
非常感谢任何帮助
编辑:这是完整的堆栈跟踪:
Traceback (most recent call last):
File "/home/tucker/anaconda3/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 972, in _do_call
return fn(*args)
File "/home/tucker/anaconda3/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 954, in _run_fn
status, run_metadata)
File "/home/tucker/anaconda3/lib/python3.5/contextlib.py", line 66, in __exit__
next(self.gen)
File "/home/tucker/anaconda3/lib/python3.5/site-packages/tensorflow/python/framework/errors.py", line 463, in raise_exception_on_not_ok_status
pywrap_tensorflow.TF_GetCode(status))
tensorflow.python.framework.errors.InvalidArgumentError: You must feed a value for placeholder tensor 'labels2' with dtype int32
[[Node: labels2 = Placeholder[dtype=DT_INT32, shape=[], _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "run.py", line 57, in <module>
bTest(testX, testY, batchSize)
File "network.pyx", line 383, in network.bTest (network.c:8672)
output = test(eX)
File "network.pyx", line 243, in network.test (network.c:6589)
decOutBat = sess.run(decOut, feed_dic)
File "/home/tucker/anaconda3/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 717, in run
run_metadata_ptr)
File "/home/tucker/anaconda3/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 915, in _run
feed_dict_string, options, run_metadata)
File "/home/tucker/anaconda3/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 965, in _do_run
target_list, options, run_metadata)
File "/home/tucker/anaconda3/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 985, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors.InvalidArgumentError: You must feed a value for placeholder tensor 'labels2' with dtype int32
[[Node: labels2 = Placeholder[dtype=DT_INT32, shape=[], _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
Caused by op 'labels2', defined at:
File "run.py", line 30, in <module>
encInput, labels, weights, decInput, prevMem = createVariables(seqLengthT, seqLengthH, batchSize, vocabSizeT, vocabSizeH, embeddingDim, memoryDim)
File "/home/tucker/anaconda3/lib/python3.5/site-packages/tensorflow/python/ops/array_ops.py", line 1332, in placeholder
name=name)
File "/home/tucker/anaconda3/lib/python3.5/site-packages/tensorflow/python/ops/gen_array_ops.py", line 1748, in _placeholder
name=name)
File "/home/tucker/anaconda3/lib/python3.5/site-packages/tensorflow/python/framework/op_def_library.py", line 749, in apply_op
op_def=op_def)
File "/home/tucker/anaconda3/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 2380, in create_op
original_op=self._default_original_op, op_def=op_def)
File "/home/tucker/anaconda3/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 1298, in __init__
self._traceback = _extract_stack()
InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'labels2' with dtype int32
[[Node: labels2 = Placeholder[dtype=DT_INT32, shape=[], _device="/job:localhost/replica:0/task:0/cpu:0"]()]]