Deep Learning Intermediate ⏱ 45 min transformermulti-head attentionMLPresidual streamdepthlayer normalizationLLMarchitecturefoundations

The Tower: How a Transformer Turns Attention into Thought

Published 2026-07-20 — Dr Neal Aggarwal
📖 Chapter Four of a ground-up account of how large language models work. Chapter One made tokens; Chapter Two gave them meaning as geometry; Chapter Three built attention — the glance that lets a token read the room. We ended with a promise: attention is the heart, but a heart is not a body. This chapter assembles the whole engine around it.

The Tower: How a Transformer Turns Attention into Thought

At the end of the last chapter we had built something genuinely powerful and left it deliberately incomplete. We had attention: the mechanism by which a token issues a query, matches it against the keys of every earlier token, and updates itself with a weighted blend of their values. A word could finally read the room. The frozen vectors of Chapter Two had come alive to their context.

But I was careful to name two things attention cannot do on its own, because they are the exact shape of what we build now. First, a single attention operation tracks only one kind of relationship at a time — one notion of "relevant" — while real language is threaded with many relationships at once. Second, and more subtly, attention moves information around but does very little thinking with it; it is a superb librarian fetching the right passages onto the desk, but fetching is not the same as reasoning over what was fetched.

This chapter fixes both, and then does something more ambitious than either fix: it discovers that once you have a unit which gathers context and then thinks about it, the natural thing to do is stack that unit, deep — and that depth is where a transformer's apparent intelligence actually lives. We are going to build the block, and then build the tower.

There is also a small debt to settle before we begin — a gap I let you walk past in the last two chapters, and which you may already have felt nagging. Let us pay it first, because it is quick and it matters.

Part I — A debt: the machine does not know word order

Look back at the attention mechanism of Chapter Three and ask a sharp question: does it know which word came first?

Astonishingly, no. Attention compares every query to every key by content alone. Nothing in "query dotted against key" encodes where in the sentence each token sits. If you shuffled the words of a sentence, the set of queries, keys, and values would be exactly the same set — only reordered — and the attention machinery, which is blind to order, would compute essentially the same blend. But "the dog bit the man" and "the man bit the dog" contain identical words and mean opposite things. A mechanism that cannot tell them apart cannot possibly model language.

The fix is disarmingly direct. Since the token vectors carry no sense of position, we simply add position information into them before they ever enter the first attention layer. Alongside the embedding table from Chapter Two — which answers "what does this token mean?" — the model keeps a second source that answers "where does this token sit?", and the two are added together so that each token's starting vector encodes both its identity and its place in line. Position stops being invisible; it becomes part of what every query and key is built from, so a token can now attend not only by meaning but by where things are relative to it.

💡 Two facts, one vector. Before the first block, each token's vector is the sum of two things: what it is (its meaning-embedding) and where it is (its position). From that point on, everything — every query, key, and value in every layer — is computed from vectors that already carry both. Order is no longer lost; it is baked in at the door. Debt paid. Now we can build.

Part II — Many glances at once

Return to the first limitation: one attention operation can only follow one thread of relevance. In the sentence "the surgeon told the registrar that she had made an error," several questions hang in the air simultaneously. Who does "she" refer to — the surgeon or the registrar? Which verb governs "error"? What is the emotional and hierarchical relationship between the two people? A single query-key scheme has to commit to one notion of relevance, and cannot chase all of these at once.

So we do the obvious, generous thing: we run many attention operations in parallel, side by side, each with its own independent query, key, and value projections. Each one is called a head. Because their projections are learned separately, the heads are free to specialise — and, remarkably, when you inspect trained models they demonstrably do. Interpretability researchers, dissecting real networks, reliably find heads that have quietly taken up distinct jobs: one tracks which noun a pronoun refers to, another matches opening brackets to closing ones in code, another attends to the previous occurrence of the current word, another follows subject-verb agreement across long distances. Nobody assigned these roles. The heads discovered a division of labour, the way an experienced team settles, without discussion, into who watches what.

MULTI-HEAD ATTENTION the same tokens, examined by several independent heads at once the sentence's tokens Head 1 pronoun → its antecedent Head 2 subject ↔ verb agreement Head 3 bracket / quote matching Head 4 topic echo, far back in the text … and many more (real models: 12–100+) combine all heads concatenate + one learned projection Each head is the exact Chapter-Three mechanism — just narrower, and specialised. Their findings are stitched back together so the token leaves with every relationship gathered at once, not just one.
Figure 1. Multi-head attention. Rather than one glance, the model takes many simultaneously, each head a full copy of the Chapter-Three mechanism with its own projections and its own learned speciality. Their outputs are concatenated and passed through a single combining projection, so each token emerges having consulted the sentence along many independent lines of relevance at the same time.

That is the first limitation dissolved. A token no longer follows a single thread; it follows a whole braid of them, in parallel, and leaves with all of them woven into its updated representation.

Part III — The thinking step

Now the subtler limitation, and the part of the transformer that most explanations skate over even though it holds the majority of the model's substance.

Attention, even multi-headed, is fundamentally an act of gathering. It reaches out, collects the relevant values from around the sentence, and blends them in. But blending is not reasoning. Having assembled "this token is a pronoun, its antecedent is the surgeon, the mood is one of admitted fault," something must now do something with that assembled picture — transform it, draw an inference from it, turn the gathered ingredients into a new conclusion. Gathering sets the table; someone still has to cook.

That cooking is done by the second half of the block: a small, ordinary neural network applied to each token independently, once its context has been gathered. It is often called the feed-forward layer or the MLP, and mechanically it is the simplest thing in the whole architecture — take the token's vector, pass it through one expanding transformation and a nonlinearity and one contracting transformation, and out comes a new vector. No looking at other tokens; no attention. Each token, alone, thinks about what it has just gathered.

THE PER-TOKEN THINKING STEP applied to every token on its own — no attention here, pure computation token, having gathered context expand to ~4× width, then a nonlinearity contract back to normal width token, having thought Roughly two-thirds of a language model's parameters live in these layers. Current evidence suggests they act, in large part, as the model's learned store of facts and associations — a vast key-value memory that attention queries. Attention decides what is relevant; this is where much of what the model knows is kept.
Figure 2. The feed-forward step — the block's "compute" half. It is applied identically and independently to every token. Mechanically trivial, it is nonetheless where the majority of the model's parameters reside, and there is good evidence it functions substantially as an associative memory: the place where facts learned in training are stored and retrieved. Attention gathers; this thinks.

So the block has a rhythm, and it is worth naming because it is the whole design in four words: communicate, then compute. First the tokens talk to each other and gather what they need (multi-head attention); then each retreats and thinks about what it gathered (the feed-forward network). Reach out; reflect. Gather; digest. It is a rhythm any clinician will recognise from the ward round itself — first you collect the relevant information from everyone around the bed, then you step back and reason about the case on your own.

⚕️ Where the knowledge actually sits. It surprises people that attention — the celebrated part — holds relatively few of a model's parameters, while the humble feed-forward layers hold most of them. But it fits a clinical intuition. Your ability to gather the right facts about a patient is a skill; your store of medical knowledge is a vast, slowly-built library. The transformer separates these too: attention is the gathering skill, the feed-forward layers are the library. When a model "knows" that a particular drug prolongs the QT interval, that fact most likely lives, encoded, in these layers — retrieved when attention routes the right query to it.

Part IV — The stream that holds it all together

We now have the two working halves. But how are they wired together — and stacked, dozens of times, without the signal degrading into noise? The answer is one more idea, quiet but load-bearing, and it changes how you should picture the whole machine.

Do not picture the block as a pipe that transforms a token and passes on a replacement. Picture instead a residual stream: a running vector for each token that flows straight up through the entire model like a central highway, and onto which each sub-layer adds its contribution rather than overwriting what was there. Attention does not replace the token; it reads the current state of the stream and adds what it gathered back onto it. The feed-forward layer does not replace the token; it reads the stream and adds its computed refinement. The stream is never wiped and rewritten — it is a chart that each stage annotates and passes upward, thicker with meaning at every step.

ONE BLOCK: COMMUNICATE, THEN COMPUTE residual stream multi-head attention the tokens talk — gather context moves information between tokens read (normalised) add result back feed-forward network each token thinks — alone computes within each token · most parameters read (normalised) add result back Nothing overwrites the stream — each sub-layer only adds to it. That is what lets many blocks stack cleanly.
Figure 3. The complete transformer block. The residual stream runs straight up the middle; attention and the feed-forward network each read a normalised copy of it and add their contribution back. "Normalised" refers to layer normalization — a routine rescaling of each token's vector to a stable spread before it is used, the statistical hygiene that keeps very deep stacks trainable. The important shape is the addition: contributions accumulate, they do not replace.

Why addition, and why does it matter so much? Two reasons, one practical and one conceptual. Practically, adding rather than overwriting gives the training signal a clean, unobstructed path all the way down through even a hundred stacked blocks — the reason very deep networks became trainable at all, and a point we will feel the force of in the next chapter on training. Conceptually, the residual stream lets each block make a modest edit to a shared, evolving representation rather than reinventing it from scratch. A block does not have to solve the whole sentence; it just has to add one useful annotation and pass the chart along. Small edits, stacked deep, compound into something that looks remarkably like understanding.

Part V — Depth: the tower

And now the step that turns a clever unit into a mind-like thing. We take the block — attention, then feed-forward, both adding to the residual stream — and we stack it. The output stream of one block is the input stream of the next, unchanged in shape, so the blocks pile up cleanly: a dozen high in a small model, dozens in a large one, well past a hundred at the frontier. This is the tower, and depth is where the magic quietly happens.

Watch what accumulates as a token's vector rises through the stack. In the earliest blocks, the annotations are close to the surface — resolving a word's part of speech, binding a pronoun, noting simple local structure. A little higher, the edits grow more abstract — assembling phrases into clauses, tracking who did what to whom, registering tone. Higher still, the representation carries things no single word contains — the gist of an argument, the state of a story, the constraint that the next word must satisfy. Meaning is not computed in one heroic step. It is refined, layer upon layer, each block adding a slightly more abstract reading of the same underlying text, until near the top the stream holds a representation rich enough that the single most useful thing left to do is predict what comes next.

THE TOWER — MEANING REFINED LAYER BY LAYER token + position embeddings (Ch. 2 & Part I) raw meaning enters here block 1 · surface: parts of speech, local ties attention + feed-forward block 6 · phrases, who-did-what, tone attention + feed-forward block 20 · argument, story-state, intent attention + feed-forward ⋮ many more blocks ⋮ top of the stream — rich enough to predict the next token is now an easy read refinement, block by block concrete abstract
Figure 4. Depth as refinement. The same token vector rises through the stack, each block adding a slightly more abstract reading. The labels here are a useful cartoon, not a precise map — the division of labour across real layers is blurrier and is still being charted by interpretability research — but the direction of travel is real: concrete near the bottom, abstract near the top. Depth is not repetition; it is elaboration.
💡 Depth is the quiet source of the apparent intelligence. A single block is not smart. What makes a transformer capable is dozens of them in sequence, each permitted to gather afresh and think afresh on a representation the layers below have already enriched. "Reasoning," to whatever degree these models have it, is not a special module bolted on — it is what happens when you refine a representation deeply enough. This is also why bigger models, with more layers and width, tend to be more capable: more depth is more room to refine.

Part VI — Reading the answer, and closing the loop

We have built the tower. One final, almost anticlimactic step converts it back into the thing Chapter Two promised: a forecast.

At the very top of the stack, we take the residual-stream vector — but only at the last position, the token after which we want to predict — and we project it, through one more learned transformation, out to a list of scores with one entry for every token in the vocabulary from Chapter One. Softmax turns that list of scores into a probability distribution, and there it is: antibiotics 41%, steroids 12%, the whole forecast we drew in Chapter Two, now actually computed, from the bottom of the tower to the top. The machine has read the tokens, refined their meaning through dozens of layers of communicate-then-compute, and read off, at the summit, its best guess at what comes next.

THE SUMMIT: READING OFF A PREDICTION top of stream last position's refined vector project a score for every token in the ~100k vocabulary softmax antibiotics 0.41 steroids 0.12 treatment 0.09 … long tail This is exactly Chapter Two's forecast — no longer asserted, but produced, from tokens at the bottom to probabilities at the top. Sample one token, append it, and run the whole tower again. That loop is generation. tokens (Ch.1) → meaning (Ch.2) → attention (Ch.3) → the tower (Ch.4) → the next token
Figure 5. The loop closes. The refined vector at the top of the tower is projected to one score per vocabulary token and softmaxed into the next-token distribution — the very forecast Chapter Two described. Sample from it, append the chosen token, and the entire tower runs again for the next word. Four chapters, and the full path from raw text to generated text now stands complete.

Take a moment with what we have assembled, because it is the whole thing. Text becomes tokens (Chapter One). Tokens become vectors in a space of meaning, carrying their positions (Chapter Two, and Part I here). Those vectors flow up a deep tower, and at every level they gather context from one another through many-headed attention (Chapter Three) and then think privately in the feed-forward layers (this chapter), adding refinement after refinement to a residual stream that is never overwritten, only enriched. At the summit, the enriched vector is read off as a forecast of the next token. That is a large language model. There is no other secret ingredient. Everything else — the scale, the training, the polish — is in service of this architecture, not in addition to it.

🔭 Now go and see it whole. In Chapter One I asked you to bookmark an interactive 3-D visualiser of a working language model and warned that most of it would look like beautiful nonsense until we had built up to it. Open it again now. The embeddings at the bottom, the attention heads with their query-key-value projections, the feed-forward layers, the residual stream running up the middle, the stack of blocks, the final projection to logits at the top — every stage in that visualisation is now something you can name and explain. That is not a small thing. Most people who use these tools daily could not label a single box. You can label all of them.

Part VII — The machine is built, but it is empty

And yet — for all that we have assembled — we have not actually explained the most important thing.

Go back and count the pieces that were simply given to us, fully formed, throughout these four chapters. The embedding table that places aspirin near ibuprofen. The query, key, and value projections that let attention know what is relevant. The feed-forward layers that hold the model's knowledge. The combining projections, the output projection, every last one of the millions or billions of numbers that make this tower do anything at all. Where did they come from? Who set them?

We already glimpsed the unsettling answer back in Chapter Two: nobody set them. They all begin as random noise. The magnificent engine we have just built, if you constructed it today and ran a sentence through it, would produce pure gibberish — a confident forecast of an entirely random next token — because every projection in every head, every weight in every feed-forward layer, is meaningless static. We have built the body in exquisite detail. It has no mind in it yet.

What fills it — what turns billions of random numbers into an embedding space that knows medicine and attention heads that track pronouns and feed-forward layers that store facts — is training: the relentless process by which the single pressure to predict the next token, applied across a large fraction of everything humans have written, reaches back through this entire tower and nudges every one of those numbers, billions of times, until gibberish becomes fluency. We have deferred the mechanism of that "reaching back" three times now. We can defer it no longer.

How a guess at a single next token can reach all the way down through a hundred layers and correct every parameter that contributed to it — how noise becomes knowledge — is the subject, at last, of Chapter Five.

— Neal

📖 Next chapter: How Noise Becomes Knowledge — training. The loss that measures a wrong guess, and the astonishing procedure that turns that single number into a correction spread across every weight in the tower. We watch an empty machine teach itself to understand.
tags: transformer multi-head attention MLP residual stream depth layer normalization LLM architecture foundations