With the Sequential API
If I create a LSTM with the Sequential API of Keras with the following code:
from keras.models import Sequential
from keras.layers import LSTM
model = Sequential()
model.add(LSTM(2, input_dim=3))
then
model.summary()
returns 48 parameters, which is OK as indicated in this Stack Overflow question.
Quick details:
input_dim = 3, output_dim = 2
n_params = 4 * output_dim * (output_dim + input_dim + 1) = 4 * 2 * (2 + 3 + 1) = 48
With the Functional API
But if I do the same with the functional API with the following code:
from keras.models import Model
from keras.layers import Input
from keras.layers import LSTM
inputs = Input(shape=(3, 1))
lstm = LSTM(2)(inputs)
model = Model(input=inputs, output=lstm)
then
model.summary()
returns 32 parameters.
Why there is such a difference?