简体   繁体   中英

Keras LSTM input dimension

def train_model_lstm(train_x, train_y, classes): train_x, train_y = np.array(train_x), np.array(train_y) train_x = np.reshape(train_x, (train_x.shape[0], train_x.shape[1], 1))

data_dim = 1
timesteps = train_x.shape[1]

regressor = Sequential()

regressor.add(LSTM(units=50, return_sequences=True, input_shape=(timesteps, data_dim)))
regressor.add(Dropout(0.2))

regressor.add(LSTM(units=50, return_sequences=True))
regressor.add(Dropout(0.2))

regressor.add(LSTM(units=50, return_sequences=True))
regressor.add(Dropout(0.2))

regressor.add(LSTM(units=50))
regressor.add(Dropout(0.2))

regressor.add(Dense(len(classes), activation='softmax'))
regressor.compile(optimizer='adam', loss='mean_squared_error')

regressor.fit(train_x, train_y, epochs=2, batch_size=32)

I'm trying to feed my network and using LSTM algorithm to my chatbot
I got an error:

exception: Error when checking, expected lstm_1_input to have 3 dimensions, but got array with shape (367, 1)

Someone can advise how can i fix it?

You may want to provide the shapes of your final train_x and train_y next time.

I think that's where the error is.

Can you confirm that the shape of train_x is: (length of the dataset, timesteps, data_dim) and the train_y is (length of dataset, len(classes)) ?

Also, I don't think that's the best choice for the loss metric since you're using a softmax for a classification problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM