PPristone AcademyLearn · Mentor · Build

Part of the Pristone Academy AI Technical Track

Attention is all you need — how transformers read everything at once.

The one idea that made modern AI possible: every word gets to look at every other word, in parallel.

200,000 FT
The Big PictureWhy it matters

To understand a word, you have to know which other words it depends on.

Take the sentence “The animal didn't cross the street because it was too tired.” What does “it” refer to? You resolved that instantly by linking “it” back to “animal.” That act — letting one word pull context from the right other words — is exactly what the attention mechanism does, for every word, simultaneously.

Attention is the heart of the transformer, the architecture behind GPT, Claude, and essentially every modern language model. The 2017 paper that introduced it was titled, with some confidence, “Attention Is All You Need.” The title was a direct shot at the era it ended: the previous models all leaned on recurrence (reading word by word) or convolution (scanning local windows). The paper's claim was that you could throw both out and keep only attention. They were right. Once attention existed, the field changed overnight.

Picture a library card catalog. Each word holds up a question card (a query): “who out there is relevant to me?” Every other word offers a label card (a key) describing what it is. The word matches its query against all the keys, and from the best matches it pulls the actual content (the values).

Try it. Pick a word below and watch how much attention it pays to every other word. Click “it” and notice where the weight lands — then switch sentences and watch the same word point somewhere new.

Interactive · self-attention

1. Pick a word — that's the query:

2. See how much it attends to every other word (the keys). Brighter = more attention:

The
2%
animal
37%
didn’t
2%
cross
2%
the
2%
street
5%
because
9%
it
22%
was
9%
too
5%
tired
2%

it attends hardest to animal. That link is exactly how the model resolves what “it” refers to — and the same sentence flips the answer when the noun changes.

Weights shown are illustrative, chosen to make the idea visible. A real transformer learns them from data and runs many such patterns (heads) at once.

Why this was a breakthrough

Before attention, models read text one word at a time, left to right, and forgot the beginning by the time they reached the end. Attention lets every word see every other word at once — no forgetting, and the whole thing runs in parallel on a GPU.

30,000 FT
The MechanicsHow it works

Query, key, value — match, weight, and blend.

From each word's embedding, the model derives three vectors by multiplying it with three learned weight matrices. Then it does a weighted lookup.

Query (Q)

What this word is looking for. “I'm a pronoun — who's my antecedent?”

Key (K)

What each word offers. “I'm a singular animal noun.” A query scores high against keys it matches.

Value (V)

The content actually pulled in once a match is found — the information that gets blended into the result.

The dot product of a query with every key gives a score: how relevant is each word to this one? Those scores are passed through softmax to become weights that sum to one — a distribution of attention, exactly the bars you saw in the demo. The output is the values, blended in those proportions. The whole operation is one tidy formula:

Attention(Q, K, V) = softmax( QKᵀ/√dₖ ) Vscore every query against every key, scale, softmax into weights, then take the weighted sum of values

Why divide by √dₖ?

Dot products of long vectors grow large, and large numbers push softmax into a corner where one weight is roughly one and the rest are roughly zero — gradients vanish and learning stalls. Dividing by √dₖ (the square root of the key dimension) keeps the scores in a sane range so the softmax stays soft. It is a small detail that makes the whole thing trainable.

The dot product and matrix multiplication here are linear algebra; softmax turning scores into a probability distribution is statistics. The intuition you just built is the same one we go deeper on, by hand, in a 1:1 session.
UNDER THE HOOD
Two RefinementsWhat makes it work

Run it many times in parallel, and hide the future during training.

Multi-head attention

One attention pass captures one kind of relationship. So the model runs many in parallel — each a head with its own Q/K/V matrices. One head tracks grammar, another long-range references, another tone. Their outputs are concatenated. Parallel perspectives, fused.

Causal masking

A language model predicts the next word, so during training it must not peek ahead. A causal mask sets the attention score for any future word to −∞ before softmax, zeroing its weight. Each word can only attend to itself and what came before.

Why it replaced RNNs and CNNs

The previous generation paid for distance. Recurrent networks processed text strictly in sequence, each step waiting on the last — slow to train and prone to forgetting across long passages. Convolutional ones saw only local windows and had to stack many layers to reach across a sentence. Attention has two decisive advantages over both: parallelism (all words processed at once, so GPUs scream) and long-range dependencies (a word at position 1 connects to position 5,000 just as directly as to its neighbor). Speed plus memory — that combination is why transformers won.

Courtside

The old architectures ran fixed plays. The RNN was a strict passing chain — point guard to shooting guard to forward to center, in order, every possession, the early read fading before it reached the end. The CNN was local zone vision — each defender watching only their patch, needing layers of relays to see the whole floor.

Attention is the point guard with full-court vision: one glance reads every teammate at once and decides who matters right now. No passing order, no local blind spots — the far corner as clear as the near one. That is the entire upgrade.

The cost nobody mentions

Every word attends to every other word, so the cost grows with the square of the sentence length. Double the context, quadruple the work. This quadratic cost is the central reason long context windows are expensive — and a hot area of research.

0 FT
What to Carry OffThe engine of the transformer

Three things to keep about attention.

It's a weighted lookup

Queries match against keys to produce weights; the output is a weighted blend of values. That's the whole idea — everything else is detail.

Parallel beats sequential

By letting every word see every other at once, attention unlocked both GPU-scale training and true long-range understanding. RNNs could do neither.

Heads see differently

Multi-head attention runs many lookups in parallel, each catching a different relationship — grammar, reference, tone — then fuses them.

The future is masked

Causal masking is what makes a transformer a next-word predictor: it can only ever look backward.

The one sentence to remember

Attention lets every word ask “who's relevant to me?” and pull in a weighted blend of everything that answers — done in parallel, across many heads, it's the entire engine of the modern language model.

If you want to go from “I get the analogy” to “I could implement this,” that's the jump a 1:1 session is built for.

Frequently asked questions

Attention lets each word in a sentence ask 'who else here is relevant to me?' and pull in a weighted blend of those words. It's how a model figures out, for example, that 'it' refers to 'the animal' — by letting 'it' look at every other word at once and lean hardest on the ones that matter.
It's the title of the 2017 paper that introduced the transformer. The claim was that you could throw out the older approaches — reading word by word (recurrence) and scanning local windows (convolution) — and keep only attention. It worked, and it reshaped the entire field.
For each word the model builds three vectors. The query is what the word is looking for; the key is what each word offers; the value is the content that gets pulled in once a match is found. A word scores its query against every key, turns those scores into weights, and blends the values in those proportions.
Two reasons. Parallelism: attention processes all words at once, so GPUs can train it fast, while RNNs had to go strictly in sequence. And long-range memory: a word can connect to one thousands of positions away just as directly as to its neighbor, instead of forgetting the start of a passage by the end.
One attention pass captures one kind of relationship. Multi-head attention runs many passes in parallel, each with its own query/key/value matrices — one head might track grammar, another long-range references, another tone. Their outputs are combined, giving the model several perspectives at once.

Curious who's behind these lessons? See the proof of work.

Competition math

Checking AMC 10 readiness for your student?

Take the free readiness check and get a quick band, strengths, and priority gaps before deciding on a diagnostic.

Take the check