Ask Your Question

Revision history [back]

When using an LSTM (Long Short-Term Memory) layer in Keras with return_sequences=True, the output of each time step is returned rather than just the final output. Thus, the output shape of the LSTM layer will be (batch_size, timesteps, output_dim).

In this context, adding a Dense layer following the LSTM layer allows for further processing of the output of each time step. The Dense layer applies a linear transformation to each time step's output separately, and can be thought of as a fully connected layer that maps the input features to the output classes.

Overall, this architecture is commonly used in sequential data problems where we want to model the whole sequence, such as time-series forecasting or sequence classification.