POST 1 of 5 MorningAI/MLConcept
An RNN keeps a hidden state
📅 Day 47. Recurrent Neural Networks (RNNs) ruled sequential data from 2010 to 2018, then transformers replaced them. They're worth understanding for context.
🔄 The core idea — process a sequence one element at a time, maintaining a hidden state that 'remembers' what's been seen so far.
At each step t:
h_t = f(W_xh · x_t + W_hh · h_{t-1} + b)
Where:
→ x_t is the input at this step.
→ h_{t-1} is the hidden state from the previous step.
→ h_t is the new hidden state.
→ f is a non-linearity (typically tanh).
→ W_xh and W_hh are weight matrices (shared across all time steps).
The hidden state acts as the model's memory. As you process the sequence, h_t accumulates information about everything seen so far.
🎯 Useful for sequential data — text, audio, time-series, DNA sequences.
⚠️ Big problem — vanishing/exploding gradients. When you backprop through many time steps, the gradient is multiplied by W_hh each step. If |W_hh| < 1, the gradient vanishes (model can't learn long-term dependencies). If |W_hh| > 1, it explodes (training diverges).
In practice, vanilla RNNs struggle to learn dependencies more than ~10 steps apart.
🛠 The fix — LSTM (Long Short-Term Memory) and GRU (Gated Recurrent Unit). Both add explicit 'gates' that decide what to remember, forget, and write to the hidden state. The gating mechanism enables long-range learning that vanilla RNNs can't do.
LSTMs ruled NLP from 2014 to 2018. Then attention/transformers came.
💡 In 2026, you'll write RNNs rarely. They survive in resource-constrained settings (mobile speech recognition, embedded systems) and as a teaching example. For everything else — transformers.#DeepLearning#PyTorch#NeuralNetworks#AI#100DaysOfCode#RNN