How does the input dimensions get converted to the output dimensions for the LSTM Layer in Keras? From reading Colah's blog post, it seems as though the number of "timesteps"
(AKA the input_dim
or the first value in the input_shape
) should equal the number of neurons, which should equal the number of outputs from this LSTM layer (delineated by the units
argument for the LSTM
layer).
From reading this post, I understand the input shapes. What I am baffled by is how Keras plugs the inputs into each of the LSTM "smart neurons".
Example code that baffles me:
model = Sequential()
model.add(LSTM(32, input_shape=(10, 64)))
model.add(Dense(2))
From this, I would think that the LSTM layer has 10 neurons and each neuron is fed a vector of length 64. However, it seems it has 32 neurons and I have no idea what is being fed into each. I understand that for the LSTM to connect to the Dense layer, we can just plug all 32 outputs to each of the 2 neurons. What confuses me is the InputLayer to the LSTM.
input_shape=(10, 64)
means that you have 10 timesteps and 64 features, the number of samples can be anything. So basically it is a 3d: (n_samples=?, timesteps=10, n_features=64). When we havemodel.add(LSTM(32, input_shape=(10, 64)))
: this will add a LSTM layer with 32 neurons and all of them will get each of 10 timesteps one by one and they will have their own output, so the output of LSTM will be (?,32). Feel free to correct me – Ruyle