How can I specify I want output of which units in LSTM?

I see this code concept(with Keras library) in most code examples of LSTM:

model.add(LSTM(X))


But I don't really know if I have 10 time-steps in input side and need the last time-step in output is the following code true?

model.add(LSTM(10))


Or if I have 10 input time-steps and need 10 output time-steps(I mean I need all outputs from all units) is the following code true?

model.add(LSTM(10))


How should I specify if I have 1 layer LSTM with 10 units, I need all of 10 outputs? Or I need 1 last output from unit 10? Or the last 5 outputs from unit 5 to 10?

• If you need the output as sequences, don't add the Dense layer. Instead do LSTM( X , return_sequences=True ). This will return all the sequences. – Shubham Panchal Mar 1 at 12:19
• @ShubhamPanchal: What if I only need the 5 or 3 or 1 last output of the sequence? How can I specify this? – user145959 Mar 1 at 12:32
• Are all your features numeric, and you want the next time-step prediction for each time-step of the 10? As far as I know, there isnt a way to only get part of the outputs only. You can just return sequences=true and only use part of it, however. – kylec123 Mar 1 at 15:21
• @kylec123: May you put a simple code for that? I don't know is it necessary to put a Dense() layer after LSTM(10 , return_sequences = True) layer to get the sequences or not? I also don't know how to get the complete sequence and split some part of it? – user145959 Mar 1 at 15:54
• @kylec123: Yes, all of my data is numeric data. – user145959 Mar 1 at 15:55

LSTM(10 , return_sequences = True)

TimeDistributed(Dense(num_features))