RNN Architecture › Hidden State Dimensionality
Language AI HandbookAll chapters RNN Architecture › Hidden State DimensionalityOne section · Sections in this chapter5 / 19 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
The size of the hidden state is a core hyperparameter. It controls the capacity of the RNN's memory. A larger gives the network more room to store information about the sequence, but it also increases the number of parameters and computational cost.
The dominant parameter cost comes from the recurrent matrix , which scales quadratically with . Doubling the hidden size quadruples the number of recurrent parameters. For this reason, practical RNNs typically use hidden sizes between 128 and 2048, depending on the task and available compute.
The total parameter count for an Elman RNN is:
where comes from , from , from , from , and from .
# Compute RNN parameter counts for various hidden sizes
D = 128 # input (embedding) dimension
V = 10_000 # vocabulary size (for language modeling)
hidden_sizes = [64, 128, 256, 512, 1024]
param_counts = {}
for H in hidden_sizes:
W_hh = H * H
W_xh = H * D
b_h = H
W_hy = V * H
b_y = V
total = W_hh + W_xh + b_h + W_hy + b_y
param_counts[H] = {
"W_hh": W_hh,
"W_xh": W_xh,
"W_hy": W_hy,
"total": total,
} H W_hh W_xh W_hy Total
----------------------------------------------------
64 4,096 8,192 640,000 662,352
128 16,384 16,384 1,280,000 1,322,896
256 65,536 32,768 2,560,000 2,668,560
512 262,144 65,536 5,120,000 5,458,192
1024 1,048,576 131,072 10,240,000 11,430,672The quadratic growth from is visible in the numbers: going from to increases the recurrent matrix from 4,096 to 262,144 parameters, a 64-fold increase despite only an 8-fold increase in . This growth dynamic has practical consequences for how you budget parameters. For many language modeling tasks with large vocabularies, the output weight matrix is the single largest component at small hidden sizes, because with creates a 640,000-element matrix even at .

The stacked bars make the growth dynamic clear. Across the hidden sizes shown, the output weight matrix dominates because the vocabulary size () is large. The recurrent matrix does not overtake it in this range, but its share grows steadily because it scales quadratically with . This asymmetry explains why practitioners often use techniques like weight tying (sharing the embedding matrix with ) to reduce the output matrix cost.
Choosing Hidden Size in Practice
The choice of hidden size involves tradeoffs between representational capacity, parameter count, and computational speed. A rule of thumb is to start with hidden sizes of 128 or 256 for character-level models on small datasets, 512 to 1024 for word-level models on medium datasets, and 1024 to 2048 for larger-scale applications. However, the optimal size always depends on the complexity of the task, the amount of training data, and the available compute budget.
One important observation is that the hidden state does not need to be as large as the vocabulary to achieve good language modeling. The hidden state is a continuous vector, and even a 128-dimensional vector can encode rich probabilistic information about possible next tokens through the linear projection into vocabulary space. The compression that happens between -dimensional hidden state and -dimensional vocabulary logits is one of the key ways RNNs generalize: they must learn a compact representation of language that explains the data, rather than memorizing explicit transition probabilities.