# Should I only use scalar labels with Keras LSTM?

I have an array X_train = (1110,25,2) and a y_train = (1110,5,2). It means I use arrays with length of 25 for inputs and length of 5 for labels. But when I use:

model = Sequential()
model.add(LSTM(units = 25, return_sequences = True, input_shape = (25, 2)))
model.compile(optimizer = 'adam', loss = 'mean_squared_error')
model.fit(X_train, y_train, epochs = 100 , batch_size = 25)


It gives me this error in the last line of the code:

ValueError: Error when checking target: expected dense_1 to have 2 dimensions, but got array with shape (1110, 5, 2) [Finished in 5.1s with exit code 1]

The code works if I change the length of y_train to the 1, but I like to test longer y labels to train. What is the problem and how can I fix it?

EDIT: I create X_train and y_train arrays with this code:

for i in range((len(training_set)%30) + 30 , len(training_set) - days ):
X_train.append(training_set_scaled[i-30:i-5])
y_train.append(training_set_scaled[i-5:i])
X_train, y_train = np.array(X_train), np.array(y_train)


This is the result of model.summary()

model.summary()
_________________________________________________________________
Layer (type)                 Output Shape              Param #
=================================================================
lstm_45 (LSTM)               (None, 25, 25)            2800
_________________________________________________________________
dropout_45 (Dropout)         (None, 25, 25)            0
_________________________________________________________________
lstm_46 (LSTM)               (None, 25, 25)            5100
_________________________________________________________________
dropout_46 (Dropout)         (None, 25, 25)            0
_________________________________________________________________
lstm_47 (LSTM)               (None, 25, 25)            5100
_________________________________________________________________
dropout_47 (Dropout)         (None, 25, 25)            0
_________________________________________________________________
lstm_48 (LSTM)               (None, 25)                5100
_________________________________________________________________
dropout_48 (Dropout)         (None, 25)                0
_________________________________________________________________
dense_12 (Dense)             (None, 2)                 52
=================================================================
Total params: 18,152
Trainable params: 18,152
Non-trainable params: 0
_________________________________________________________________


EDIT2: I have tried to solve my problem with RepeatVector() function in encoder-decoder approach with the following code:

model = Sequential()
model.add(LSTM(units = 25, return_sequences = True, input_shape = (25, 2)))
model.add(LSTM(units = 25, return_sequences = True))
model.add(LSTM(units = 25)) #, return_sequences = True))
model.add(LSTM(units = 5 ,return_sequences = True))
model.add(LSTM(units = 5 ,return_sequences = True ))


But I get this stupid result:

model.summary()

• I am trying to create X_train with capturing 25 elements, then shift it 1 position then capture 25 elements till the end of the whole data. And do the same process with length of 5 for y_train array. – user3486308 Feb 25 '19 at 19:54
• Also the last LSTM layer is return_sequence = False cause I have connected it to a Dense(units = 2) layer that is my last layer. – user3486308 Feb 25 '19 at 19:58