What Is a Transformer Model? Attention, Explained Without Math

A transformer is a network that, for every word in a sentence, works out how much every other word matters to it, then blends their information accordingly. In “the animal did not cross the street because it was too tired,” the word “it” has to be resolved against “animal” and not against “street,” and the only thing that decides this is a set of learned weights. No grammar rule is stored anywhere. The weights were tuned until the right pairing scored higher than the wrong one.

That is the whole idea, and the rest of this piece is the consequences: why the design replaced the networks that came before it, what the “weights” in that sentence actually are, and why attention maps are not the explanation of a model’s behaviour that people often assume they are.

The problem it solved was order without memory

Older sequence models read text one word at a time and carried a hidden state forward — a running summary of everything read so far. That summary is a bottleneck. By the end of a long paragraph, the early words survive only as a faded trace, and the model has no way to go back and look at them again. Ask it to connect a pronoun to a noun twenty words earlier and the connection is carried by a compressed memory that has been overwritten many times.

There is a second problem, and it is the one that mattered commercially. Because each step depends on the previous one, the work cannot be spread across a machine. A thousand sentences have to be processed in sequence, one after another, even though a graphics card has thousands of arithmetic units sitting idle. Training was slow for a reason that had nothing to do with how much data was available.

Attention fixes both. Instead of passing a summary forward, every word gets to look directly at every other word in the same pass. Distance stops being a gradient of forgetting and becomes just another thing the weights can encode.

Attention is a weighted average, chosen by the words themselves

Each word arrives as a vector — a long list of numbers standing in for its meaning in context. Three separate learned projections turn that vector into three new vectors, usually called query, key, and value.

The library analogy is the clearest one. Every book has a label on the spine; that is the key. You arrive with a question; that is the query. The book’s contents are the value. You compare your question with each label, and the closer the match, the more of that book you read. If two books are both relevant, you read both and merge what they say in proportion to how relevant each seemed.

In the network the comparison is a dot product, which is a measure of alignment between two vectors. Every query is compared with every key, producing a score for each pair. Those scores are passed through a softmax, which turns them into positive numbers summing to one. The output for that word is the weighted sum of all the value vectors, using those weights.

Make it concrete. Suppose the word “it” ends up with weights of 0.6 on “animal,” 0.3 on “tired,” and 0.1 spread over everything else. The new representation of “it” is mostly the representation of “animal,” slightly coloured by “tired,” and barely touched by the rest. That is how a pronoun acquires its referent: not by a rule, but by a weighted blend.

The weights are learned, not programmed. Nothing in the architecture says pronouns should attend to nouns. The training objective rewards whatever makes the next word more predictable, and pronoun resolution happens to be useful for that, so the weights drift toward it.

Position has to be added back

Here is the catch that surprises people: as described so far, attention has no idea what order the words are in. It computes a set of comparisons and merges values. Shuffle the sentence and every comparison still happens, just in a different arrangement — the operation is indifferent to sequence.

For a bag of words that would be fine. For language it is fatal, because “the dog bit the man” and “the man bit the dog” contain identical words. The fix is to inject position information into the vectors before attention runs, either by adding a fixed pattern of numbers keyed to each position or by learning a position signal. Either way, each word’s vector now carries a marker of where it sits, and the attention scores can depend on relative placement.

This is a small mechanical detail with a large consequence. It means the model can learn that words close together often form phrases, that the subject usually appears before the verb in English, and that a modifier applies to the nearest noun rather than a distant one.

Several heads watch different relationships at once

A single attention operation produces one blend per word, which is a narrow view. Transformers therefore run several of them in parallel — the heads — each with its own learned projections, and concatenate the results.

The useful way to think about heads is as separate subspaces of the same sentence. One may end up sensitive to which noun a pronoun refers to; another to repeated names; another to the syntactic role of the previous word; another to punctuation boundaries. Analyses of trained models do find heads with recognisable habits, but it is worth being careful: the division of labour is emergent and messy, individual heads often do several things, and many can be removed with little effect. “One head for syntax” is a tidy story, not a specification.

The rest of the block is what makes it a network

Attention alone would be a sophisticated lookup. The transformer block wraps it in machinery that makes deep stacking possible.

  • A residual connection. The block’s output is added back to its input, so the network learns a correction rather than a replacement. This keeps gradients flowing through many layers, and it means a layer can, in principle, do almost nothing.
  • Normalisation. Activations are rescaled between sublayers so that values do not drift toward extremes as depth increases.
  • A feed-forward layer. Each position is passed through a small two-layer network independently. This is where a large share of the parameters live, and it appears to be where much of the model’s stored association between patterns and continuations sits.

Stack dozens of these blocks and the representation of each word becomes progressively less about the word and more about its role in the document. Early layers seem to handle local form; later layers carry information that looks semantic. The final layer turns the last position’s vector into a score for every token in the vocabulary, and one token is sampled. For how those layered features are learned in the first place, see what a neural network is.

Why the design spread so far

Training is parallel, generation is not

This asymmetry is the practical reason transformers won. To train on a document, the model can score every position at once: predict token two from token one, token three from tokens one and two, and so on, all in a single pass, because the correct earlier tokens are already known and can be fed in directly. One long sequence becomes one large matrix multiplication instead of a chain of dependent steps. That is why the architecture and the GPU boom arrived together — the workload became the shape that hardware likes.

At inference time the parallelism disappears, because the model’s own output becomes the next input. Generation is sequential again. This is why a chatbot types at a steady pace rather than appearing all at once, and why long outputs cost proportionally more time.

The same block works for pictures and sound

Nothing in the block assumes words. It assumes a sequence of vectors, a way to tell positions apart, and a target to predict. Split an image into patches, treat each patch as a token, and the same block applies. Do the same with audio frames or codec tokens, and it applies again. That generality is why one architecture now sits under text, image, and speech systems, and it is the substrate described in what generative AI is.

Scale matters too, in a way that was not obvious beforehand. Adding layers, width, and data kept improving results for longer than many expected, and the architecture degraded gracefully rather than hitting a wall. That combination — a block that is easy to stack, cheap to parallelise, and indifferent to modality — is why it became the default.

What attention is not

Because attention weights are numbers you can plot, there is a temptation to read them as an explanation. A heat map showing that “it” attended strongly to “animal” looks like a reason. It is a description of one step, in one head, in one layer, among many.

Scores are summed across heads and layers, then transformed by the feed-forward layers that follow. A high weight does not prove that the information was used, and a low weight does not prove it was ignored. Nor does attention imply understanding: it is a mechanism for routing information, and routing can be useful without any model of the world behind it. The consequences of that gap show up as confident invention, which is the subject of why AI models make things up.

It is also not memory in the database sense. There is no store of sentences to consult. The weights encode statistical regularities, and attention decides which parts of the current input get combined. Ask where a fact lives and the honest answer is: distributed across many parameters, in a form that cannot be read off directly.

What to check when someone explains a model with attention

  • Is the claim about a mechanism or about a mind? “This layer routes pronoun information” is a mechanism claim. “The model attends because it understands the sentence” is not supported by a weight matrix.
  • Is the evidence a single head? One head’s pattern is an anecdote. Reliable claims come from ablating components and measuring the effect on output.
  • Does the explanation survive the feed-forward layers? Attention is followed by per-position computation that can rewrite what was gathered. Skipping that step is the most common simplification error.
  • Would the same plot appear for a wrong answer? If attention looks identical when the model is right and when it is wrong, the plot is not explaining the answer.
  • Is “transformer” being used as a synonym for “AI”? It is one architecture among several. Plenty of working systems — older sequence models, recommender pipelines, classic vision networks — do not use it at all.

Keep exploring

Related: how large language models work for the loop this machinery serves, and the AI section for the rest of the series.