Deep Learning · TEE · section
Counting parameters in a dense network
Neural-network foundations
Definition. A dense layer connects every input component to every receiving neuron. Its trainable parameters are these connection weights and the receiving neurons' independently trainable biases.
Deriving the parameter count
For m inputs and n receiving neurons, each receiver needs m weights. There are therefore mn weights. With one bias per receiver, there are n additional parameters:
P_{\mathrm{dense}}=mn+n=(m+1)nActivation values are computed from data and parameters; they are not additional trainable parameters. The input layer supplies data and does not acquire an extra bias merely because it appears in a diagram.
Complete numerical
Question. A network has 10 input features, three hidden layers with 5 neurons each, and 4 outputs. Every receiving neuron has a bias. Count its trainable parameters.
Given
Layer sizes: 10 inputs → 5 hidden → 5 hidden → 5 hidden → 4 outputs.
Every hidden/output neuron has one bias.
To find
Count weights and biases at each receiving layer, then the total.
Formula — which one and why
Dense-layer parameters. Every output neuron receives every input, so multiply inputs by outputs for weights. Add one bias per receiving neuron. Sum separate layers.
n_in = incoming features; n_out = receiving neurons. The input layer itself has no learned receiving weights or biases.
P=(n_{\mathrm{in}}+1)n_{\mathrm{out}}Yaad rakhne ka cue: Har output ke liye saare inputs plus ek bias.
Solution — step by step
Step 1: identify the consecutive layer widths.
10\longrightarrow5\longrightarrow5\longrightarrow5\longrightarrow4There are four trainable dense transformations. A connection between two hidden layers is counted once, as part of the receiving layer's parameters.
Step 2: count weights and biases for each transformation.
| Transformation | Weights | Biases | Layer total |
|---|---|---|---|
| Input → hidden 1 | 10 × 5 = 50 | 5 | 55 |
| Hidden 1 → hidden 2 | 5 × 5 = 25 | 5 | 30 |
| Hidden 2 → hidden 3 | 5 × 5 = 25 | 5 | 30 |
| Hidden 3 → output | 5 × 4 = 20 | 4 | 24 |
Step 3: add the layer totals.
P=55+30+30+24=139Equivalently, the network has 120 weights and 19 biases, so 120 + 19 = 139.
Final answer: 139 trainable parameters. If a question explicitly removes biases, count only the 120 weights. Optimizer states such as Adam's moments are extra training storage, not extra parameters in this predictive network.