RNN Explained: Why Recurrent Neural Networks Still Matter for Sequence Modeling
This article traces the origins of recurrent neural networks (RNNs) and explains why they became the foundation of sequence modeling. It covers the limitations of feedforward networks on language, how RNNs use shared weights and hidden states as memory, the three structural bottlenecks of serial computation, vanishing and exploding gradients, and fixed-size memory, and how LSTM and GRU gating mitigate these issues. It also shows how attention emerged from this lineage and where recurrent approaches still offer practical advantages today.
RNNs Explained: Why the Original Sequence Model Is Still Relevant
To understand why today’s large language models (LLMs) adopted the attention architecture, you first have to answer a more basic question: how does a machine “read” a sentence at all? The answer lies in the history of sequence modeling, and the recurrent neural network (RNN) is where that lineage begins. This article centers on RNNs, looking back at the problem that motivated them and forward to the gating variants and modern architectures that followed.
1. The Starting Point: Language Is a Sequence, and Traditional Networks Are Not
In the early days of deep learning, the dominant feedforward neural networks assumed that the input was a fixed-dimension vector whose elements were mutually independent. That assumption works reasonably well for images but is a fundamental mismatch for language.
Natural language has three rigid characteristics:
- Variable length: A sentence might be 3 words long or 300 words long, so the input dimension cannot be fixed in advance.
- Order sensitivity: “I hit him” and “He hit me” contain exactly the same set of words but mean opposite things.
- Long-range dependencies: The subject at the start of a sentence may determine the form of the verb at the end, spanning dozens of words.
Force a fixed-dimension network to handle this and the only option is to compress the whole sentence into a fixed-length vector, losing much of the order information in the process. Researchers therefore turned to a more natural idea: let the network read word by word, like a person, remembering as it goes.
2. The Core Mechanism: Memory Encoded in Weights
At its core, an RNN is time-unfolded parameter sharing. It performs the same computation at every time step and carries the previous step’s hidden state into the next one:
# Illustrative pseudocode: a single RNN steph = zeros(hidden_dim) # initial hidden state, like "blank memory"for x_t in tokens: # read tokens one time step at a timeh = tanh(W_x @ x_t + W_h @ h + b) # current input + previous memoryy_t = softmax(W_y @ h) # prediction for the current step
Three points are worth emphasizing:
- Weight sharing: Every time step reuses the same
W_xandW_h, so the model can process sequences of arbitrary length and the parameter count is independent of sequence length. - The hidden state is the memory:
his a fixed-length vector that is repeatedly overwritten and updated, acting as “the entire history after compression.” - Unlimited context in theory: Because the recurrent structure can be unfolded indefinitely, an RNN can conceptually handle inputs of any length, which is its biggest advantage over fixed-length input models.
3. The Fatal Pain Points: Why RNNs Don’t Scale
The elegance of step-by-step propagation comes with a price, and the structural flaws come down to three.
First, no parallelism. Step t must wait for the h of step t-1 to finish, which creates a hard serial dependency along the time dimension. When training on long sequences, the parallel compute of the GPU sits largely idle and wall-clock time grows linearly with length. This is the first bottleneck to surface in training at industrial scale.
Second, vanishing and exploding gradients. During backpropagation, the gradient has to be multiplied repeatedly by the transposed W_h matrix along the time axis. If its spectral norm is below 1, the gradient decays exponentially and signals from distant positions are nearly zeroed out; if it is above 1, it blows up exponentially and the values diverge. The practical consequence:
The model can learn that “the previous word influences the next word,” but it cannot learn that “the 3rd word influences the 50th word.”
Third, the memory capacity bottleneck. A fixed-length h has to hold the entire history, so information inevitably competes for space. The longer the sequence, the more thoroughly early content is overwritten, which conflicts directly with the need for long-range dependencies.
4. Gated Improvements: Teaching Memory to Forget Selectively
To address these problems, the long short-term memory network (LSTM) and the gated recurrent unit (GRU) introduced gating mechanisms: learnable switches that control the flow of information.
# Illustrative single LSTM step: three gates + one candidate memoryf = sigmoid(W_f @ [h_prev, x_t]) # forget gate: how much old memory to dropi = sigmoid(W_i @ [h_prev, x_t]) # input gate: how much new information to writeo = sigmoid(W_o @ [h_prev, x_t]) # output gate: how much memory to exposec_t = f * c_prev + i * tanh(W_c @ [h_prev, x_t])h_t = o * tanh(c_t)
The contribution here is that the cell state c_t provides an approximately linear information highway, allowing gradients to span multiple time steps without being compressed over and over. That extends the dependency range the model can capture from a handful of steps to dozens or even hundreds. GRU simplifies the three gates into two, with fewer parameters and faster convergence, and on small and medium-scale tasks it often performs on par with LSTM.
But it is important to be clear-eyed: gating mitigates the problem, it does not cure it. The serial dependency remains, early information still decays over long sequences, and the extra computation introduced by the gates slows training down further.
5. The Bridge: Why Attention Became Inevitable
The early line of improvement bolted an attention mechanism onto the RNN: instead of relying on a single h when decoding, the model takes a weighted sum over the states of all encoder time steps, with weights computed dynamically from the similarity between the current state and each of the others.
score = q @ K.T / sqrt(d_k) # similarity scoringattn = softmax(score) @ V # normalize into weights, then aggregate
This step mattered a great deal: for the first time, any two positions could interact directly, the path length dropped from O(n) to O(1), and both scoring and aggregation are matrix operations that are naturally parallelizable. Removing the recurrent structure entirely along this line of thinking produced a fully attention-based sequence architecture: the serial bottleneck of RNNs was eliminated while long-range dependency modeling was preserved and strengthened.
6. The Ideas Behind RNNs Never Left
Treating RNNs as obsolete is a misreading. At inference time, the RNN hidden state is fixed-length and does not grow as the context expands, which keeps it practically useful in very long streaming scenarios, on edge devices, and in low-latency online serving. Modern approaches such as state space models are essentially a continuation of the same idea: parallel training plus recurrent inference. In engineering practice, the choice should come back to the constraints:
- Training throughput first, long context requirements → attention-based architectures;
- Limited memory and latency, need for unbounded streaming → recurrent / state space approaches;
- Small and medium-scale labeled data, short sequences → LSTM/GRU remain a cost-effective baseline.
Conclusion
The historical value of RNNs does not lie in their becoming the mainstream choice, but in being the first to formalize “order” and “memory” as a trainable computational structure, and in clearly exposing the two fundamental tensions of serial computation and long-range decay. It was the direct response to those tensions that gave rise to the attention architecture and today’s large models. Understanding RNNs is the key to understanding why modern sequence modeling is designed the way it is.
