Gated Recurrent Units (GRU)
What Problem Does GRU Solve?
Standard RNN issue: Gradient vanishes exponentially over many timesteps → can't learn long-range dependencies.
LSTM solution: Separate cell state with gates to control information flow.
GRU insight: Do we really need a separate cell state? What if we combine the hidden state and cell state into one , and merge the forget and input gates into a single update gate? This cuts parameters by ~25% while keeping most of LSTM's power.
The GRU Architecture

GRU has 2 gates operating on hidden state :
Derivation from First Principles
Goal: Update hidden state from and , controlling information flow.
Step 1: Compute Reset Gate
Why this step? We need to decide: is the past relevant for the new candidate we're about to compute? If the sequence context changes (e.g., topic shift), we want to "reset" and not be biased by irrelevant history.
Step 2: Compute Candidate Hidden State
Why this step?
- element-wise multiplies the old state by the reset gate. If is small, we ignore .
- Concatenate with , pass through tanh to get a candidate update in .
- This is the "proposed new memory" if were to fully replace .
Step 3: Compute Update Gate
Why this step? We need to decide: how much of the old to keep vs. how much of the new candidate to accept. This is the interpolation weight.
Step 4: Final Hidden State (Linear Interpolation)
Why this step?
- If : → preserve old memory (like LSTM's high forget gate).
- If : → accept new candidate (like LSTM's high input gate).
- This is a convex combination: acts as a learned interpolation weight per dimension.
Key insight: The update gate merges LSTM's forget and input gates. In LSTM, you have separate (forget) and (input). In GRU, when is high (keep old), it's low for new (reject new), and vice versa—they're coupled as and .
GRU vs LSTM: Formula Comparison
| LSTM | GRU |
|---|---|
| 3 gates: forget , input , output | 2 gates: update , reset |
| Separate cell state and hidden state | Single hidden state (no separate cell) |
| (no output gate, is directly exposed) |
Parameter count: GRU has ~25% fewer parameters than LSTM (2 gates vs 3, no separate cell state weights).
Example 1: Sentiment Analysis Sentence
Sequence: "The movie started well but the ending was terrible."
Let's trace one GRU cell at word "but" (timestep ):
- Input: = embedding of "but", = hidden state after "well" (likely positive sentiment accumulated).
Step 1: Compute : "But" signals a contrast. If the network has learned that "but" often reverses sentiment, might be low (say 0.2), meaning "don't rely heavily on the positive —we're about to change direction."
Why this step? The reset gate detects the contrast word and decides to partially ignore the positive history.
Step 2: Compute : With , we multiply by 0.2, heavily damping the old positive sentiment. The candidate is now mostly driven by ("but") and will start shifting toward neutral or preparing for negativity.
Why this step? We compute a fresh candidate that's not overly biased by the past positive context.
Step 3: Compute : "But" is a pivot word. The network might learn should be low (say 0.3), meaning "don't keep much of the old positive —accept more of the new candidate."
Why this step? The update gate decides to shift away from the old sentiment toward the new candidate.
Step 4: Final : The new hidden state is 70% the candidate (which has low influence from past due to reset gate) and 30% the old state. Net effect: sentiment representation shifts from positive toward neutral/negative.
Result: As the sequence continues ("ending was terrible"), the reset gate will again be low, update gate will favor new negative information, and final will represent negative sentiment.
Example 2: Long-Term Dependency (Name Recall)
Sequence: "Alice went to the park. She played with her dog. Later, she went home. __ was tired."
We want to fill the blank with "Alice" (or "She"), requiring memory of "Alice" from the start.
At the blank (timestep ):
- Many timesteps have passed since "Alice" was mentioned.
- Intermediate words ("park", "dog", "home") are less relevant to who is tired.
GRU behavior:
For intermediate words (park, dog, home):
- is high (say 0.8–0.9): The update gate learns these words don't change the subject identity, so . The identity "Alice" is preserved through the term being small—we mostly keep old .
Why this works: High acts like LSTM's high forget gate + low input gate: "keep old memory, ignore new irrelevant content." Gradient flows backward through the and terms, which are gated—gradient highway.
At the blank:
- still encodes "Alice" because intermediate were high.
- The decoder can extract "Alice" from to generate "She" or "Alice was tired."
Key: GRU's update gate controls the gradient flow. When , the gradient (chain rule), avoiding vanishing gradient.
Common Mistakes
When to Use GRU vs LSTM?
| Use GRU | Use LSTM |
|---|---|
| Default choice for new projects (simpler) | Very long sequences (100+ steps) |
| Small datasets (fewer params → less overfit) | Complex hierarchical dependencies |
| Faster training/inference needed | When you have compute budget and want max expressiveness |
| Performance is close to LSTM empirically | Speech, complex NLP (slight edge in some benchmarks) |
Rule of thumb: Start with GRU. If you hit a performance ceiling and have resources, try LSTM. The difference is often marginal (1-2% accuracy) in practice.
Recall Explain to a 12-Year-Old
Imagine you're writing a story in a notebook, one sentence at a time. You have two sticky notes to help you decide what to write next: Sticky Note 1 (Reset Gate): "Should I look back at what I wrote before to get ideas, or should I start fresh?" If the story changes topics (like going from pirates to princesses), you might ignore the old sentences. Low reset = "forget the old stuff for this new idea."
Sticky Note 2 (Update Gate): "Should I keep my current page as-is, or should I erase some and write the new sentence?" If the new sentence is really important, you erase more of the old page (low update gate). If the old stuff is still important, you keep most of it (high update gate).
The GRU does this automatically for every word in a sentence, deciding "how much old memory to keep" and "how much past context to use for new ideas." It's like a smart notebook that knows when to remember and when to move on—perfect for understanding long stories or conversations!
Connections
- 3.5.03-Long-Short-Term-Memory-(LSTM) — GRU simplifies LSTM by merging gates
- 3.5.02-Vanishing-and-Exploding-Gradients — GRU solves vanishing gradient via gating
- 3.5.01-Basic-RNN-Architecture — GRU extends basic RNN with gates for long-term memory
- 3.5.06-Bidirectional-RNNs — GRU can be used bidirectionally for context from both directions
- 3.6.01-Attention-Mechanism — Attention can replace/augment GRU for very long sequences
#flashcards/ai-ml
What are the two gates in a GRU and what does each control? :: Reset gate controls how much of past hidden state influences the new candidate. Update gate controls interpolation between old hidden state and new candidate.
Write the GRU final hidden state update equation :: , where is update gate, is candidate hidden state.
How does GRU's update gate relate to LSTM's forget and input gates?
What is the role of the reset gate in the candidate computation?
Why does GRU avoid vanishing gradients?
GRU vs LSTM: which has fewer parameters and by roughly how much?
If you see the word "but" in sentiment analysis, should the GRU's reset gate be high or low, and why?
In a long sequence where intermediate words are irrelevant, should the update gate be high or low?
Concept Map
Hinglish (regional understanding)
Intuition Hinglish mein samjho
GRU ek simplified version hai LSTM ka. Socho RNN ko long-term memory problem hai—bahut zyada timesteps ke bad gradient vanish ho jata hai, toh network bhool jaata hai purane words. LSTM neisko solve kiya3 gates se aur alag cell state se, lekin thoda complex ho gaya. GRU bolta hai: kya zarurat hai 3 gates ki? Chaliye 2 gates se kaam chalate hain—ek update gate jo decide karta hai kitna purana hidden state rakhna hai aur kitna naya candidate lena hai, aur ek reset gate jo decide karta hai ki naya candidate banate waqt kitna purana context use karna hai.
Result kya hai? GRU me 25% kam parameters hain LSTM se