# Mission 4.1: How does the model know that „sie“ means the cat?

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

Belongs to [Chapter 4: The transformer in outline](https://llm.yoga/en/04-transformer.md).

Structure: the case, the explanation, a hands-on tool, check questions, wrap-up. The answers to all questions are collected at the end.

## The case

**Aylin**, product manager:

> “I gave our chatbot the sentence „Die Katze hat Durst und sieht die Milch. Jetzt trinkt sie.“ and asked who is drinking. Answer: the cat. Grammatically, „sie“ could just as well be the milk. So does the chatbot understand text like a person?”

The sentence is German for “The cat is thirsty and sees the milk. Now it drinks.” The German word „sie“ can mean “she” or “it”, and „Katze“ (cat) and „Milch“ (milk) are both grammatically feminine, so either one could be meant. How far a team trusts a chatbot often hinges on an observation like this, and the question lands on your desk. Behind the chatbot is a language model, a program that continues text piece by piece. These pieces are called **tokens**, usually whole words or parts of words. Before you read up on it: what do you suspect?

**Question 1 (prediction):** How does the model tell that „sie“ means the cat?

- A) From a built-in grammar rule: a pronoun refers to the subject.
- B) It compares „sie“ with the words before it and takes mostly from the best match.
- C) It knows exactly this sentence from training and remembers the answer.

## What’s behind it

Picture a meeting where every word of the sentence is a participant. Each one has a name tag and a notepad. The word „sie“ asks the room: “Which of you could I be referring to?” Everyone holds up their name tag. Whoever fits the question well passes on their notes; whoever doesn’t fit stays quiet.

In the model, this round is called **attention**. The question is called the query, the name tag the key, the note the value. All three are lists of numbers that the model forms anew for every word; it learned in training how to form them. „sie“ compares its query with the keys of all the words before it and with its own. The better a key fits, the bigger its share, and all the shares together add up to 100 percent. „sie“ mixes the notes using these shares. It never looks at words that come later.

In the worked example from the chapter, with made-up numbers, the cat gets 78.6 percent, the milk 2.3 and „sie“ itself 19.1. Afterward „sie“ mainly carries the cat’s information.

For Aylin this means: the reference comes from learned numbers and a calculation, not from a grammar rule. Whether you call that “understanding” is a question of definition, not of mechanics. What is certain: with ambiguous sentences, the comparison can also get it wrong.

### In more detail: calculation, heads and layers

Formula from the 2017 paper: Attention(Q, K, V) = softmax(Q · Kᵀ / √dk) · V. The comparison uses the dot product: number times number, all added up. dk is the length of the key vectors, here 2. The softmax function turns the results into shares that add up to 100 percent.

Query of „sie“: q = (1, 2). Keys: Katze (2, 1), Milch (1, −1), sie (0, 1). Values: Katze (1, 0), Milch (0, 1), sie (0.5, 0.5). All numbers are made up.

Dot products: Katze 1 × 2 + 2 × 1 = 4, Milch 1 × 1 + 2 × (−1) = −1, sie 1 × 0 + 2 × 1 = 2. Divide by √2 ≈ 1.414: 2.828, −0.707 and 1.414.

Exponential function: e to the 2.828 = 16.919, e to the −0.707 = 0.493, e to the 1.414 = 4.113, sum 21.525. Divide by the sum: Katze 78.6%, Milch 2.3%, sie 19.1%.

Mix the values: 0.786 × (1, 0) + 0.023 × (0, 1) + 0.191 × (0.5, 0.5) = (0.88, 0.12). Without dividing by √dk, the values would get very large with long vectors, and softmax would give almost everything to a single key.

A real model like Qwen3-8B computes this in 32 heads in parallel, each with its own weights, and in 36 layers one after the other. Because the comparison only sees contents, each token also gets its position; otherwise “dog bites man” and “man bites dog” would be the same to attention.

## Try it

**Hands-on attention**

**Task:** Aylin asks: “And what would it look like if the model got it wrong and had the milk drink?” Set the query of „sie“ so that the milk („Milch“) gets more than 80 percent of the weight.

This tool needs JavaScript. Calculation for the start: query (1, 2) gives Katze 78.6%, Milch 2.3%, „sie“ itself 19.1%. With the query (1, −2) the dot products are 0, 3 and −2, so divided by √2 they are 0, 2.121 and −1.414. The milk then gets 87.0%, the cat 10.4%, „sie“ itself 2.5%.

q is the query of „sie“, the large dot in the picture. The starting values come from the worked example, with two instead of 128 numbers per list. Each row shows how well a key fits the query, and the bar shows its share. The calculation behind it is under “In more detail” in the previous step.

## Check

**Question 2 (check question):** Aylin’s colleague says: “Attention means the model understands the text like a person.” What do you say to that?

- A) He’s right, the model translates the sentence into meaning, just like we do.
- B) He’s wrong, the model only ever looks at the word directly before.
- C) Attention mixes information by shares that come from comparisons.

**Question 3 (check question):** Which words does „sie“ compare its query with?

- A) With all the words before it and with itself.
- B) Only with the word directly before it, „trinkt“ (drinks).
- C) With all the words in the sentence, including the ones after it.

**Question 4 (check question):** In the tool, the milk got over 80 percent as soon as the query pointed in a different direction. What does Aylin take away from that?

- A) The model rolls the dice for every sentence to decide who is meant.
- B) The reference depends on learned numbers and can get it wrong.
- C) The milk wins because it’s closer to „sie“ in the sentence.

## Done

**What you can do now**

- You explain attention with the picture of the meeting: query, key and value are question, name tag and note.
- You saw in the tool how comparing query and keys produces shares, and how they flip when the query points elsewhere.
- When someone in a product meeting says the chatbot understands text like a person, you explain in two sentences what attention computes, and suggest testing ambiguous sentences from your own daily work on purpose.

### Two cards for review

**Card 1:** Explain attention with the picture of the meeting: who does a word ask, and what does it get back?

**Card 2:** True or false? “A language model uses a built-in grammar rule to recognize what a pronoun refers to.”

- [Next mission: Where are the 8 billion parameters?](https://llm.yoga/en/einsatz-4-2.md)
- [Try it on your Mac](https://llm.yoga/en/mac-4-1.md)

## Read more in the chapter

The full text from the chapter, with the reasoning, calculations and sources:

- [Attention: query, key and value](https://llm.yoga/en/04-transformer-1.md)
- [Multiple heads](https://llm.yoga/en/04-transformer-1.md)
- [Position information](https://llm.yoga/en/04-transformer-1.md)

## Answers: only reveal them after the learner has answered or explicitly asks

**Question 1:** The correct answer is B.
- A: No such rules are written anywhere in the model; it consists only of learned numbers. Besides, grammatically „sie“ fits both, since „Katze“ and „Milch“ are both feminine. What tips the balance is a comparison the model computes for every word.
- B, correct: That’s attention. In the worked example, the cat gets 78.6 percent of the weight, the milk 2.3 percent. The model learned in training which words go well together.
- C: What’s stored isn’t sentences but learned numbers. From them, each word gets a question and a name tag, and comparing those resolves the reference, even in a sentence Aylin just made up.

**Question 2:** The correct answer is C.
- A: Mechanically, something else happens: lists of numbers are compared, the results become shares, and the notes are mixed accordingly. That „sie“ ends up at the cat is a learned pattern.
- B: „sie“ compares itself with all the words before it and with itself, not just with the last one. That’s exactly why it can end up at the cat, which comes several words earlier.
- C, correct: The shares come from comparing query and keys, and how those are formed was learned in training. Whether you call that understanding is a question of definition, not of mechanics.

**Question 3:** The correct answer is A.
- A, correct: That’s why „sie“ also gets a share itself in the example, 19.1 percent. Later words aren’t part of the comparison; after all, the model writes from left to right.
- B: Then the cat wouldn’t stand a chance; it comes several words earlier. The comparison includes all the words before, and each one gets its share.
- C: „sie“ never looks ahead: when the model processes „sie“, the later words don’t exist yet. The comparison is with the words before it and with itself.

**Question 4:** The correct answer is B.
- A: Nothing is rolled in the comparison: the same numbers always give the same shares. The direction of the query depends on the learned weights and on the sentence.
- B, correct: If the sentence gives the model unusual numbers, the weight ends up somewhere else. That’s why it pays to test ambiguous sentences from your own daily work instead of concluding from one successful example that all will work.
- C: Closeness alone doesn’t decide; in the starting picture the milk is closer too and gets only 2.3 percent. What tips the balance is how well its key fits the query.

**Card 1:** The word puts its question (query) to all the words before it and to itself, and each one holds up its name tag (key). The better a key fits, the bigger its share of the notes (values) the word receives; all shares together add up to 100 percent. Later words aren’t included.

**Card 2:** **False.** No rules are written anywhere in the model, only learned numbers. The reference comes from attention: the query of „sie“ (she, it) fits the key of „Katze“ (cat) best. Because this is learned, the comparison can also get it wrong with ambiguous sentences.
