Skip to content
Learn Motion
ExploreHow it worksMembership
Log in
Learn Motion

How Large Language Models Work: From Tokens to Inference

1From Text to Tokens2Embeddings: Turning Tokens into Vectors3The Transformer Block: Attention and Feed-Forward Processing4Stacking Blocks into a Language Model5Training: How the Model Learns to Predict6From Pretraining to Instruction Following7Inference: Generating Text Token by Token
The Transformer Block: Attention and Feed-Forward Processing

Why One Attention Pattern Is Not Enough

2 / 3
One attention pattern has to serve every purpose at once, which is a tight constraint. Multiple heads relax it: each head gets its own query, key, and value projections, so each can learn a different way of linking positions. Their outputs are concatenated and then mixed by an output projection, so the block still passes forward one vector per position. The practical effect is that a single layer can track several relationships at the same time instead of averaging them into one.
0:00 / 0:00

A single attention operation produces one weight distribution per position, which forces the model to compress every kind of relationship into one comparison. Multi-head attention instead runs several attention operations in parallel, each with its own learned projections \(W_Q^{(h)}\), \(W_K^{(h)}\), and \(W_V^{(h)}\). Head \(h\) computes its own weights and its own weighted sum, and the head outputs are concatenated and passed through an output projection \(W_O\). The projections are learned, so different heads can specialize: one may link a pronoun to its antecedent, another may track the previous word, another may connect a verb to a distant object. Because each head works in a smaller subspace of dimension \(d_k = d / H\), the total cost stays close to that of a single full-width head. The output projection mixes the heads back into one vector per position, so the rest of the block sees a single representation rather than a set of separate ones.

References

  1. [1]Attention Is All You Needarxiv.org
Previous2 / 3Next

Learn Motion

Generate a course. Learn it properly.

Operated by Wuhan Daoyin Technology Co., Ltd.

Contact: [email protected]
Privacy PolicyTerms of Service

© 2026 Learn Motion