My Y_train is a one-hot encoded label matrix.
The shape of my Y_train is (10, 1000, 3)
because I have three different categories.
My model is defined as:
model = Sequential()
model.add(LSTM(100, input_shape=(1000, 38), return_sequences=False))
model.add(Dense(3, activation='softmax'))
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['acc'])
When I train my model, I get the following error:
Error when checking target: expected dense_83 to have 2 dimensions, but got array with shape (8, 1000, 3)
This occurs because my Y_train is a 3d matrix, instead of a 2d matrix. The only way I've been able to solve this is by setting return_sequences=True
but not sure if that will affect my LSTM's output.
Is this the correct way to deal with categorical labels? By setting return_sequences=True
as a parameter of LSTM?
In other words, is it okay to return_sequences before a Softmax layer?
Thank you!