Sequence Models
Limitations That Motivate Attention
Ch.1: established WHY sequences need dedicated
Jr Codex Deep Learning Notes
Level: Advanced Prerequisites: Chapter 4: Sequence-to-Sequence & Encoder-Decoder Models Time to complete: ~15 minutes
Table of Contents
- This Module's Journey, in Review
- Limitation 1: the Fixed-Size Bottleneck
- Limitation 2: Sequential Processing Can't Parallelize
- Limitation 3: Long-Range Dependencies Still Decay
- A First Glimpse of the Solution
- Summary & Next Steps
1. This Module's Journey, in Review
Where This Module Has Taken Us
─────────────────────────────────────────
Ch.1: established WHY sequences need dedicated
architectures
Ch.2: RNNs — a hidden state carrying memory forward,
but limited by vanishing gradients
Ch.3: LSTMs/GRUs — gates and a cell state fixing
MUCH of the vanishing gradient problem
Ch.4: Encoder-decoder models — handling
unaligned sequence-to-sequence tasks,
but introducing a NEW bottleneck
─────────────────────────────────────────
This closing chapter names the three specific, interconnected limitations that remain — the exact problems that Module 6's attention mechanism and Transformer architecture were built to solve.
2. Limitation 1: the Fixed-Size Bottleneck
Already covered in depth in Chapter 4, Section 7 — compressing an entire input sequence into one fixed-size context vector inevitably loses information, more severely as sequence length grows.
The Core Insight That Leads to Attention
─────────────────────────────────────────
What if the decoder didn't have to rely on ONE compressed
summary at all? What if, at EACH decoding step, it could
look back and directly access ALL of the encoder's hidden
states, and learn to focus on whichever ones are MOST
relevant for generating the CURRENT output word?
This is, in one sentence, what ATTENTION does.
─────────────────────────────────────────
3. Limitation 2: Sequential Processing Can't Parallelize
RNNs, LSTMs, and GRUs all process a sequence one step at a time — step t's computation strictly requires step t-1's hidden state to already be computed. This is a fundamental obstacle to using GPU parallelism (Module 1, Chapter 4) effectively.
Why This Matters at Scale
─────────────────────────────────────────
A CNN (Module 4) can process every pixel/region of an
image in PARALLEL, since one region's computation doesn't
depend on another's result. An RNN CANNOT do this across
time steps — processing a 1,000-word document REQUIRES
1,000 SEQUENTIAL steps, no matter how many GPU cores are
available, since each step's computation genuinely depends
on the previous step finishing first.
This became an increasingly severe practical bottleneck as
training datasets and desired model sizes grew — training
time scales directly with sequence length, with limited
ability to speed this up through parallel hardware.
─────────────────────────────────────────
4. Limitation 3: Long-Range Dependencies Still Decay
Even with LSTMs/GRUs' improvements (Chapter 3), information about elements very far back in a long sequence still tends to fade — the cell state's additive updates slow the decay significantly, but don't eliminate it entirely, especially for sequences of many hundreds of steps.
A Concrete Failure Case
─────────────────────────────────────────
"The trophy doesn't fit in the suitcase because IT is too
big." — resolving what "IT" refers to (the trophy, not the
suitcase) requires connecting back to a word MANY tokens
earlier, correctly, and this kind of reference can occur
at ARBITRARY distances in real text — sometimes across
entire paragraphs. Even LSTMs' improved memory can struggle
with dependencies at this scale.
─────────────────────────────────────────
5. A First Glimpse of the Solution
The Reframing That Attention Introduces
─────────────────────────────────────────
Instead of forcing information to flow through a CHAIN of
sequential hidden states (RNN/LSTM style, Ch.2-3), what if
ANY position in a sequence could directly "attend to" ANY
OTHER position, regardless of distance, in a SINGLE step —
with the MODEL learning which connections matter most?
This directly addresses ALL THREE limitations at once:
- No fixed-size bottleneck (Section 2) — attend to ALL
encoder states directly, not one compressed summary
- No forced sequential processing (Section 3) — attention
computations between ALL positions can happen in
PARALLEL
- No long-range decay (Section 4) — a connection between
position 1 and position 500 is computed just as
DIRECTLY as a connection between adjacent positions
─────────────────────────────────────────
This reframing — introduced in the 2017 paper "Attention Is All You Need" (Module 1, Chapter 3) — is the single architectural idea most responsible for the current era of large language models, and is the complete subject of Module 6.
6. Summary & Next Steps
Key Takeaways
- Encoder-decoder RNN/LSTM models suffer from three interconnected limitations: a fixed-size context bottleneck, an inability to parallelize across time steps, and continued (if reduced) decay of long-range dependencies.
- Sequential processing being a hard requirement of RNN-family architectures is a fundamental obstacle to exploiting GPU parallelism at scale.
- Attention reframes sequence modeling entirely: instead of forcing information through a sequential chain, any position can directly attend to any other position, solving all three limitations simultaneously.
- This reframing directly led to the Transformer architecture, the subject of the next module.
Module 5 Complete — What's Next
You've now traced the complete evolution of sequence modeling: from the basic recurrent idea, through LSTMs' gating solution to vanishing gradients, to encoder-decoder models for unaligned sequence tasks, arriving at the specific limitations that motivated a fundamentally different approach. Module 6 covers that approach in full: the attention mechanism and the Transformer architecture.
Concept Check
- Why can't an RNN or LSTM parallelize its computation across time steps, unlike a CNN's convolution across spatial positions?
- Name the three limitations of encoder-decoder RNN models covered in this chapter, and briefly explain each.
- How does attention address all three limitations simultaneously, in one sentence per limitation?
Next Module
→ Module 6: Attention & Transformers
Jr Codex — 1-on-1 Personalized Coaching | Back to Module Index | Back to DL Index