Hi,
I am trying to build a simple RNN in Keras and PyTorch. Unfortunately, both have different number of parameters. Can someone explain why?
In Keras:
model = keras.models.Sequential([
    keras.layers.SimpleRNN(1, input_shape=[None, 1])
])

model.summary()
# This returns 'Total params: 3'

In PyTorch
class SimpleRNN(nn.Module):
    def __init__(self):
        super(SimpleRNN, self).__init__()
        self.rnn = nn.RNN(input_size=1,
                         hidden_size=1,
                         num_layers=1,
                         nonlinearity='tanh',
                         batch_first=True
                         )
    def forward(self,X):
        out, _ = self.rnn(X)
        out = out[:,-1, :]
        return out
        
model_sr = SimpleRNN()

def count_parameters(model):
    return sum(param.numel() for param in model.parameters())

count_parameters(model_sr)
# returns 4