Start studying
Module 5 · Transformers Module contents
Module 5  ·  Card 1 / 19beginner

Attention

Attention lets a model decide which parts of the input matter for each output.

Instead of one fixed summary it computes a weighted blend of all positions.

Positions that are relevant get a high weight, the rest get a low one.

This removed the fixed-vector bottleneck of old seq2seq models.

It is the single idea the entire transformer architecture is built around.

Learn in depth ↓
Module 05 · Transformers · 19 concepts
In depth  /  15 lines

Attention, in more detail

Attention lets a model decide, for each thing it produces, which inputs matter.

The old sequence models had to squeeze the entire input into one fixed vector.

That worked for short sentences and fell apart on long ones.

The information was there in principle and unreachable in practice.

Attention replaces the single summary with a fresh blend for every output step.

At each step the model scores every input position for relevance right now.

Those scores are turned into weights that sum to one.

The output is the weighted mixture of all positions, dominated by the relevant ones.

Nothing is discarded, since irrelevant positions simply receive a near-zero weight.

The weights are computed, not stored, so they change with every step and every input.

It was introduced in 2014 as an addition to translation models and improved them immediately.

The 2017 transformer paper removed everything else and kept only attention.

The title, attention is all you need, was a fair description of the result.

Attention weights are often shown as heatmaps and read as an explanation.

They show where the model looked, which is suggestive but not a full account of why.

Want the full technical article? Wikipedia ↗
Test yourself

5 questions on this card. Every option explains itself once you pick, right or wrong.

Question 1 of 5
What problem does attention solve that RNNs struggled with?
Question 2 of 5
In attention, what role does the key play?
Question 3 of 5
Why are attention scores divided by the square root of the key dimension?
Question 4 of 5
Why do transformers need positional encoding?
Question 5 of 5
Why use multiple attention heads instead of one?
Transformers

19 concepts in this module, then a graded test with every answer explained.

Study this module →
↑↓ move↵ openesc close