Python 嵌入层后的LSTM-值错误:Isn';t符号张量?

Python 嵌入层后的LSTM-值错误:Isn';t符号张量?,python,Python,由于某些原因,我无法将LSTM层添加到我的模型中: embed_size=8 LSTM=Sequential() LSTM.add(Embedding(max_words,embed_size,input_length=max_len)) LSTM.add(LSTM(30, return_sequences=True,name='lstm_layer')) LSTM.add(GlobalMaxPool1D()) ... 我得到以下错误: 3 LSTM.add(Embedding(m

由于某些原因,我无法将LSTM层添加到我的模型中:

embed_size=8
LSTM=Sequential()
LSTM.add(Embedding(max_words,embed_size,input_length=max_len))
LSTM.add(LSTM(30, return_sequences=True,name='lstm_layer'))
LSTM.add(GlobalMaxPool1D())
...
我得到以下错误:

      3 LSTM.add(Embedding(max_words,embed_size,input_length=max_len))
----> 4 LSTM.add(LSTM(30, return_sequences=True,name='lstm_layer'))
      5 LSTM.add(GlobalMaxPool1D())
      6 LSTM.add(Dropout(0.1))

C:\anaconda3\lib\site-packages\keras\engine\base_layer.py in __call__(self, inputs, **kwargs)
    438             # Raise exceptions in case the input is not compatible
    439             # with the input_spec set at build time.
--> 440             self.assert_input_compatibility(inputs)
    441 
    442             # Handle mask propagation.

C:\anaconda3\lib\site-packages\keras\engine\base_layer.py in assert_input_compatibility(self, inputs)
    283                                  'Received type: ' +
    284                                  str(type(x)) + '. Full input: ' +
--> 285                                  str(inputs) + '. All inputs to the layer '
    286                                  'should be tensors.')
    287 

ValueError: Layer sequential_6 was called with an input that isn't a symbolic tensor. Received type: <class 'int'>. Full input: [30]. All inputs to the layer should be tenso
知道有什么问题吗

谢谢


KS

只是名称空间中的一个问题,您将覆盖导入的LSTM层。 将型号名称中的
LSTM
更改为
LSTM

from keras import Sequential, Model
from keras.layers import Embedding,LSTM, GlobalMaxPool1D
embed_size=8
max_len = 1000
max_words = 10
lstm=Sequential()
lstm.add(Embedding(max_words,embed_size,input_length=max_len))
lstm.add(LSTM(30, return_sequences=True,name='lstm_layer'))
lstm.add(GlobalMaxPool1D())
很好

新来者详细说明:

import语句设置一个名为
LSTM
的本地引用,它是一个实现Keras层的类。然后,它在语句
LSTM=Sequential()
中被覆盖。现在名称
LSTM
是Keras顺序模型的一个实例。最后,在语句
LSTM.add(LSTM(…)
中,内部操作
LSTM(…)
是对模型的调用,由
Sequential
类的
调用方法实现(此功能在python中是本机的)。所以抛出的错误是,调用顺序_6的输入不是符号张量,这意味着调用
Sequential
类的实例(框架自动将其命名为Sequential_6),其输入与实现不兼容。这个断言是在
Sequential
类的
\uuuu调用
实现中实现的。

噢,这是一个愚蠢的错误:)仍然习惯于python语法。THY@KostaS. 我注意到你从来没有接受过你问题的任何答案。我强烈建议您通过单击绿色复选标记开始接受答案。这个似乎解决了你的问题,为什么不接受呢?
from keras import Sequential, Model
from keras.layers import Embedding,LSTM, GlobalMaxPool1D
embed_size=8
max_len = 1000
max_words = 10
lstm=Sequential()
lstm.add(Embedding(max_words,embed_size,input_length=max_len))
lstm.add(LSTM(30, return_sequences=True,name='lstm_layer'))
lstm.add(GlobalMaxPool1D())