Recurrent Neural Network RNN
A Recurrent Neural Network (RNN) is a class of neural networks built specifically for sequential data. Its defining trait is that the network "loops" along the time dimension: the output at each step depends not only on the current input but also on the hidden state of the previous step. This lets it handle variable-length sequences, such as a sentence, a stretch of speech, or the price movement of a stock.
Core Principles
At each time step t, an RNN takes an input xt and the hidden state ht-1 from the previous step, computes a new hidden state ht, and produces an output yt. The key point is that the same set of weights is shared across all time steps, so the number of parameters does not grow with sequence length. In effect, this lets the network "remember" what it has already seen.
But a vanilla RNN has a fatal flaw: vanishing and exploding gradients. During backpropagation the gradient is multiplied repeatedly across time steps; if the norm of the Jacobian at each step is less than 1, the gradient decays exponentially toward zero, and the network cannot retain long-range dependencies: information from the start of a sentence fades away after a few dozen words.
Improvements
LSTM (Long Short-Term Memory) introduces a gating mechanism: the forget gate decides which old information to discard, the input gate decides which new information to write, and the output gate decides what to output. The cell state acts like a conveyor belt that lets gradients flow over long distances almost without loss.
GRU (Gated Recurrent Unit) is a simplified LSTM that merges the three gates into two (an update gate and a reset gate). It has fewer parameters and trains faster, while often coming close to LSTM performance.
Bidirectional RNN reads the sequence both forward and backward, so every position sees the full context. This suits text classification and named entity recognition.
Common Misconceptions
Many people assume RNNs have been completely displaced by Transformers. In practice, in real-time streaming settings (speech recognition, sensor time-series forecasting) and on resource-constrained embedded devices, RNNs and their variants still hold an advantage: inference needs only O(1) memory, whereas Transformer attention needs O(n^2).
Applications
Speech recognition, machine translation (the mainstream approach before 2017), text generation, stock forecasting, ECG anomaly detection, and user behavior sequence modeling. Today they exist mainly as a complement to Transformers.