# Chapter 4: The transformer in outline

Part of the course “AI from Zero to Autonomous Agents” (https://llm.yoga/en). Page for humans: https://llm.yoga/en/04-transformer

*Embeddings, attention, feed-forward: the parts of a language model, with numbers you can recalculate and the 8.2 billion parameters of Qwen3-8B, counted piece by piece.*

About 25 min to read · about 20 min hands-on exercise

**Start with the missions**

This chapter also comes as 3 short missions with a case, a decision and feedback, about 10 minutes each:

- [4.1 How does the model know that „sie“ means the cat?](https://llm.yoga/en/einsatz-4-1.md)
- [4.2 Where are the 8 billion parameters?](https://llm.yoga/en/einsatz-4-2.md)
- [4.3 Why doesn’t the model know our niche item number?](https://llm.yoga/en/einsatz-4-3.md)

For agents, this page is split into 3 parts so that each part can be fetched in full. Read the parts the question needs.

## Parts

### Part 1: https://llm.yoga/en/04-transformer-1.md

- **Getting started**: Picture a meeting where every word of a sentence is a participant.
- **The path of a token through the model**: The transformer was introduced in 2017 by Ashish Vaswani and seven co-authors, most of them at Google, in the paper “Attention Is All You Need”.
- **Embeddings: from token ID to vector**: A token ID like 5999 for „ ist“ (is) is just a house number.
- **Where is the token? Position information**: Attention, which we’ll get to in a moment, has a surprising weakness: it doesn’t see order.
- **Attention: query, key and value**: Now to the heart of it.
- **Multiple heads**: A single set of query, key and value can only search for one kind of relationship at a time.

### Part 2: https://llm.yoga/en/04-transformer-2.md

- **The feed-forward layer**: After attention, every layer has a feed-forward layer, often also called an MLP (multi-layer perceptron, a classic neural network as in chapter 1).
- **Stacking layers**: A layer of attention and feed-forward is the building block, and a language model is a stack of them.
- **The output layer: back to the logits**: At the end of the stack, the last token has a vector of 4,096 numbers.
- **Where the 8 billion parameters come from**: With all the parts in place, you can now work out where the 8.2 billion parameters of Qwen3-8B listed on the model card come from.
- **How the model learns, briefly**: All 8.19 billion numbers start out as random values.

### Part 3: https://llm.yoga/en/04-transformer-3.md

- **Exercise: count a model from its config.json**: Goal: you download a model’s configuration file, work out the parameters by component and compare with the model card.
- **Common misconceptions**: Most of a transformer’s parameters sit in the attention.
- **Review questions**: 1. A token has the query (2, 0).
- **Go further**: Vaswani et al.: Attention Is All You Need (2017), the transformer paper; section 3.2 on scaled dot-product attention, 3.5 on positional encodings.
