metacareerguide.com
Understanding & Using LLMs · Module 03

How attention works

Every model you have heard of — Claude, GPT, Gemini — is built on one idea published in 2017. It has an intimidating name and a genuinely simple core: when reading a word, look at the other words that matter.

You do not need the maths. You do need the intuition, because it explains why models are good at some things and unreliable at others, and why context length is the number everyone argues about.

The problem it solved

Before 2017, language models read strictly left to right, one word at a time, carrying a running summary. This works for short sentences and falls apart on long ones — by the end of a paragraph the summary has been overwritten so many times that the beginning is effectively gone.

You can feel the problem yourself. Read this: “The trophy would not fit into the brown suitcase because it was too large.”

What does it refer to? The trophy. Now change one word: “…because it was too small.” Suddenly it is the suitcase.

Nothing about the word it changed. To resolve it, you have to look back at two nouns and weigh them against an adjective at the end. A running summary cannot do that. It needs to look around.

What attention actually does

Attention lets every word look at every other word at once, and decide which ones matter for interpreting it.

That is genuinely it. Each word asks a question — roughly “what do I need to know to understand myself here?” — and every other word offers an answer. The strength of each answer becomes a weight. Words with high weights shape the meaning; words with low weights are largely ignored.

Figure 1 — which words does each word look at?
press to begin

The blue word is the one being interpreted. The bright words are the ones it is attending to.

Watch what happens at it. The model is not scanning backwards hoping to find a noun. It is weighing trophy and suitcase simultaneously against large, and the weights settle on the right one.

Why “transformer”

The architecture is called a transformer because each layer transforms every word’s representation using information from the others. Stack dozens of those layers and early ones settle grammar, later ones handle meaning and reference. Nobody designed that division of labour — it emerged from training, and researchers discovered it afterwards.

Two consequences you will feel

It reads everything at once. Unlike the old left-to-right approach, a transformer processes all the words in parallel. That parallelism is the reason these models could be trained on the scale they were — and it is why GPUs, which do thousands of things simultaneously, became the hardware of the field.

Comparing everything to everything is expensive. Ten words means a hundred comparisons. A thousand words means a million. The cost grows with the square of the length.

This is the real reason context windows are finite and why long conversations get slow and expensive. It is not an arbitrary limit a company chose. It is arithmetic.

Figure 2 — the four stages of one turn
1 · TokeniseYour text becomes tokens, then embeddings. Module 02.
2 · AttendEvery token weighs every other. Repeated through dozens of layers.
3 · PredictThe final layer produces a probability for every token in the vocabulary.
4 · SampleOne token is chosen, appended, and the whole thing runs again.
stage 0 of 4

Every single word you see generated is one full pass through all four stages.

Stage four is worth sitting with. The model produces one token, adds it to the text, and starts over — re-reading everything, including what it just wrote. A 500-word answer is 650-odd complete passes.

That is why responses stream in rather than appearing at once, and why a model can contradict itself mid-paragraph. It is not consulting a plan. At each step it is choosing the next token given everything so far.

What this explains

Why order matters in your prompts. Instructions buried in the middle of a long document get less weight than the same instructions at the start or end. This is a measured effect, not folklore — and it is why “put the important thing last” is common advice that actually works.

Why models lose the thread in long conversations. Attention is spread across everything. The more there is, the thinner it spreads.

Why they cannot revise. A token, once generated, is part of the input for every token after it. There is no going back to fix an earlier sentence — which is why asking a model to check its own work in the same response rarely helps, and asking in a fresh message often does.

Try it — 10 minutes

1. Give an assistant the trophy sentence with too large and ask what it refers to. Then again with too small. Both should be correct — you are watching attention resolve a reference no rule could.
2. Paste a long article and bury an instruction in the middle: “When summarising, mention the colour blue.” Ask for a summary. Then move the same instruction to the very end and try again. Compare compliance.
3. Ask for a 200-word story, then in the same message ask it to check its own work. Then start fresh, paste the story, and ask for a critique. The second is usually sharper — module 12 explains why.
4. Optional: search “Attention Is All You Need”. It is the 2017 paper that started all of this, and it is freely available. You will not follow the maths on a first read. Look at the diagrams and notice how small the idea is.

What to take away

Attention means every word can look at every other word and decide what matters. Everything else — the cost of long contexts, instructions getting lost in the middle, one token at a time with no revising — follows from that one mechanism.

Check yourself

1. Your extraction prompt works on short documents and gets unreliable on long ones. Which explanation best fits what you now know?

Attention dilution. The truncation answer is the tempting one because something clearly degrades — but if the document fits in the context window nothing is dropped. Everything is still there; the instructions simply hold a smaller share of the model’s attention. Which is why moving them to the end, or processing in chunks, tends to fix it.

2. Why do context windows have limits at all?

The quadratic cost. Commercial motives are a fair instinct in general, but here the constraint is genuinely arithmetic — doubling the input roughly quadruples the attention work. It is also why every meaningful jump in context length came from an architectural change, not a pricing decision.

3. A teammate says the model “plans its answer, then writes it.” What is the accurate correction?

One token at a time, no plan. The hidden-plan answer is seductive because outputs are so well-structured they feel planned — but that structure comes from having read millions of well-structured documents, not from an outline. This is exactly why “think step by step” works: it makes the model write reasoning into the text, where later tokens can actually attend to it. The thinking has to be on the page to exist at all.
← Module 02 Course outline