You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Keras SimpleRNN参数数量疑问:为何SimpleRNN(10)的参数为120?

解释SimpleRNN层的120个参数计算

Hey there! Great question about RNN parameter counts—this trips up a lot of folks when they first start working with recurrent layers, so let’s break down exactly why your SimpleRNN(10, input_shape=(3, 1)) layer has 120 parameters.

First, let’s recap your model setup for context:

model.add(SimpleRNN(10, input_shape=(3, 1)))
model.add(Dense(1, activation="linear"))

The key thing to remember is that RNN parameter counts depend only on the number of input features and the number of hidden units—the time step count (the 3 in your input_shape) doesn’t affect how many parameters the layer has. Here’s the breakdown for your SimpleRNN layer:

SimpleRNN layers have three types of parameters:

  • Input-to-hidden weights: Connects each input feature to each hidden unit. For your case, input features = 1 (from input_shape=(3,1)), hidden units = 10. So this is 1 * 10 = 10 parameters.
  • Hidden-to-hidden recurrent weights: Connects each hidden unit to every other hidden unit (including itself) for the looped recurrence. That’s 10 * 10 = 100 parameters.
  • Hidden layer biases: A bias term for each hidden unit. That’s 10 parameters.

Adding those up: 10 + 100 + 10 = 120—which matches exactly what your model summary shows!

You can also use this general formula to calculate SimpleRNN parameters anytime:
Total Parameters = (input_dim + units) * units + units = (input_dim + units + 1) * units

Plugging in your values: (1 + 10 + 1)*10 = 12*10 = 120—perfect, same result.

As a quick sanity check: if you changed your input to have 2 features (e.g., input_shape=(3,2)), the total parameters would jump to (2+10+1)*10=130—you can test that yourself to confirm the math holds.

内容的提问来源于stack exchange,提问作者youngtackpark

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 10:19:29