0

I know there have been so many questions already for this but i can't i find a clear answer to this. Is this enter image description here correct? Taken from Understanding Keras LSTMs here. Does the batch-size correspond to enter image description here to 5 (0-4) in this picture? Taken from http://colah.github.io/posts/2015-08-Understanding-LSTMs/ here. With a keras line like this:

model.add(LSTM(units, batch_input_shape=(batch_size, n_time_steps, n_features), stateful=False))

note the statefull=False, So one input vector (one blue bubble) would be the size n_time_steps*n_features, right?

kluki
  • 59
  • 11

1 Answers1

0

To make your understanding clear, the batch_input_shape = (batch_size,time_steps,n_features) in the first image you have mentioned it will be represented as batch_input_shape = (batch_size,4,3). In the second image it will be batch_input_shape = (batch_size,5,1).
In both pictures batch size is not represented, so don't get confused about batch size here.

A better understanding of these dimensions can be observed below. enter image description here

For Stateful = True, the model expects the input to be in a sequence i.e not shuffled, nonoverlapping.
In this scenario, you need to fix the batch_size first.

  • If the data is small you can set the batch_size to 1(which is in most of the cases)
  • If data is large, you can set any number for batch_size and split the data to those equal number of batches so your data will be continuos when the next iteration starts.

At each iteration, the model instead of having a hidden state full of zeros, it will take the previous batch's final state as the initial state to the present batch.