我正在使用here中的代码来测试文本生成中的LSTM网络。我改变的唯一一行是
raw_text = open('books/(1) The Hunger Games.txt').read()
而不是
filename = "wonderland.txt"
raw_text = open(filename).read()
我收到此错误
Using TensorFlow backend.
Total Characters: 521930
Total Vocab: 50
Total Patterns: 521830
100 1
Traceback (most recent call last):
File "main.py", line 50, in <module>
model.add(LSTM(256, input_shape=(X.shape[1], X.shape[2]), return_sequences=True))
File "/usr/local/lib/python3.4/dist-packages/keras/models.py", line 294, in add
layer.create_input_layer(batch_input_shape, input_dtype)
File "/usr/local/lib/python3.4/dist-packages/keras/engine/topology.py", line 398, in create_input_layer
self(x)
File "/usr/local/lib/python3.4/dist-packages/keras/engine/topology.py", line 569, in __call__
self.add_inbound_node(inbound_layers, node_indices, tensor_indices)
File "/usr/local/lib/python3.4/dist-packages/keras/engine/topology.py", line 632, in add_inbound_node
Node.create_node(self, inbound_layers, node_indices, tensor_indices)
File "/usr/local/lib/python3.4/dist-packages/keras/engine/topology.py", line 164, in create_node
output_tensors = to_list(outbound_layer.call(input_tensors[0], mask=input_masks[0]))
File "/usr/local/lib/python3.4/dist-packages/keras/layers/recurrent.py", line 227, in call
input_length=input_shape[1])
File "/usr/local/lib/python3.4/dist-packages/keras/backend/tensorflow_backend.py", line 1836, in rnn
axes = [1, 0] + list(range(2, len(outputs.get_shape())))
File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/framework/tensor_shape.py", line 462, in __len__
raise ValueError("Cannot take the length of Shape with unknown rank.")
ValueError: Cannot take the length of Shape with unknown rank.
我一直在四处寻找,我无法理解为什么它不会采取输入维度。任何想法都非常受欢迎。
提前致谢!
稍后编辑:即使使用原始文件也无效。