Reputation: 746
I am working in RNN. I have following lines of code from some site. If you observe second layer has no "returnSequence" parameter.
I am assuming return sequence is mandatory as it should return the sequences. Can you please tell why this is not defined.
First layer LSTM:
regressor.add(LSTM(units = 30, return_sequences = True))
Second layer LSTM:
regressor.add(LSTM(units = 30))
Upvotes: 7
Views: 6740
Reputation: 500
when the LSTM layer is followed by a Dense layer you should set return_sequence=False, otherwise when you use several LSTM layers stacked together you should set it to TRUE
LSTM(units, return_sequences=True...)
LSTM(units, return_sequences=True...)
LSTM(units, return_sequences=False...)
Dense(...)
Upvotes: 0
Reputation: 3473
When the return_sequences
argument is set to False
(default), the network will only output hn, i.e. the hidden state at the final time step. Otherwise, the network will output the full sequence of hidden states, [h1, h2, ..., hn]. The internal equations of the layer are unchanged. Refer to the documentation.
Upvotes: 15