Keras中LSTM尺寸的错误数量

时间:2017-01-05 13:28:38

标签: tensorflow neural-network keras recurrent-neural-network lstm

我正在尝试使用Recurrent Neural Networks对文本进行分类,并且在实现以下Python代码时遇到问题(后端在TensorFlow上):

from keras.models import Sequential
from keras.layers import LSTM
from keras.layers import Dense
from keras.layers import Embedding
import numpy
import pandas as pd

seed = 7
numpy.random.seed(seed)

raw_data = pd.read_excel('Data.xlsx',sep=',')
df = raw_data.iloc[:,0:2]
df['Input']=df['Input'].astype(str)

X = df['Input'].values
X = pd.get_dummies(X).as_matrix() # Convert Dataframe to Nd-Araay

Y = df['Output'].values
Y = pd.get_dummies(Y).as_matrix() # Convert Dataframe to Nd-Araay

model = Sequential()
model.add(LSTM(450, input_shape =(X.shape[0], X.shape[1])))
model.add(Dense(Y.shape[1], activation='softmax'))

model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
model.fit(X, Y, nb_epoch=100, batch_size=100,verbose=0)    

loss, accuracy = model.evaluate(X, Y)
print("\nLoss: %.2f, Accuracy: %.2f%%" % (loss, accuracy*100))

我的输入,即X是由411行和1组成的Nd阵列。 407列,Y由411行组成。 7列及以下是我得到的错误:

expected lstm_input_43 to have 3 dimensions, but got array with shape (411, 407)

0 个答案:

没有答案