Advanced level · Module 5: Attention Mechanisms in NLP · Lesson 1 of 3
Why Attention: the Bottleneck Problem
Learners see why squeezing a whole input into one vector fails on long inputs and how attention lets the decoder look back at every encoder state.
In this lesson you will
- Explain the encoder-decoder bottleneck
- Describe how attention computes a context per output step
Key concepts
bottleneckencoder outputsalignment scoressoftmax weightscontext vector per step
The lesson
In a basic seq2seq model, the whole input must fit into one fixed-size vector. Performance drops as inputs get longer, which you can measure on the date task by adding long, noisy prefixes.
Attention keeps all encoder outputs. At each decoding step, the decoder scores every encoder position, turns the scores into weights with softmax and takes a weighted average as the context for that step.
The weights show which input positions the model used for each output token: a soft alignment that can be visualised.
Step by step
- Measure exact-match accuracy of the existing model as input length increases.
- Write out the attention computation for one decoding step.
- Compute softmax weights by hand for three scores.
- Predict how attention should change the length curve.
Practice activity
Show the bottleneck effect with an accuracy-by-length chart and explain attention step by step.
Expected result: A chart showing degradation with length and a correct worked attention step.
Check your understanding
-
What is the bottleneck in basic seq2seq?
Show answer
The whole input is compressed into one fixed-size vector.
-
What do attention weights add up to?
Show answer
One, because they come from a softmax.
Further learning
Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.