# How to feed training set labels into Keras LSTM

I’m implementing an LSTM with Keras and I know that I have to reshape the training dataset in a 3D object. Basically I have a dataset of shape (300000, 839)and I reshape it as (100000, 3, 839) because I want a timestep of 3. The question is: how could I treat the training set labels? Have I to reshape also them? if I reshape the labels to 100000, I don't truncate 200000 labels, since the starting number of labels is 300000?

Thanks in advance.

## 1 Answer

Your approch so far is not exactly right. Assuming you want to use the many to one approcah, the way you do it is as follows:

You have a dataset like this: And you prepare your data in a way like this: Source

For a timestep of 3, you discard the first 2 occurrences of your labels and use $$y_{3}$$ for the inputs $$\{x_1, x_2,x_3\}$$.

Next you don't start in $$x_4$$. Instead you use the next three-item slice $$\{x_2, x_3, x_4\}$$ with the training label $$y_4$$.

You continue this way until the last imput $$\{x_{n-2}, x_{n-1}, x_{n}\}$$ to predict $$y_n$$. If you have $$n=30000$$ samples, you can generate up to $$n-2$$ (29998) training samples for your model following this logic.

• ’s thank you for the asnwer. So my model predictions will be 29998 labels? – pairon Feb 28 '20 at 12:18
• As fas as I understand what you want to do, yes – TitoOrt Feb 28 '20 at 12:22
• my task is to predict the correct words order given an unordered sentence. So, my dataset is a list of words (I could reshape the dataset in a 3D shape into a set of sentence, where each matrix of data is the set of words of the sentence). Optimally I would predict each word label, but if I have to truncate only the first 3 labels of the dataset (with timesteps=3) I think that is not a problem for the learning. What do you think about it? – pairon Feb 28 '20 at 15:00