# Mission 3.2: Why does it answer differently every time?

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

Belongs to [Chapter 3: Tokens and next-token guessing](https://llm.yoga/en/03-tokens.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

**Mark**, Sales:

> “I asked our bot the same question three times and got three different answers. Is it broken? For ad copy that’s fine, but when it’s supposed to pull the notice period out of contracts, I want the same answer every time.”

As soon as a team uses AI for fixed details like deadlines or prices, this question comes to you. A language model writes token by token, that is, word or word piece by word piece. For every possible next token it produces a probability, and only then is one picked. Temperature is a setting for that pick, from 0 upward. A test on my test Mac, the MacBook I measure on: I had qwen3:8b, an openly available model, continue „Der Himmel ist“ (German for “the sky is”; I ran the test in German) by six tokens, four times with different random starting values.

**Question 1 (prediction):** At temperature 0: how many different continuations came out of four runs?

- A) One.
- B) Two.
- C) Four.

## What’s behind it

**The four runs at three temperatures (Measured on an M4 Mac (24 GB) on November 24, 2026)**

**0:** „blau, die Sonne“ (four times the same)

**0.7:** „blau, die Sonne“, „blau und die Sonne“, „blau, das Gras“, „blau, weil die Son“

**1.5:** „inzwischen blau,“, „so still Der Himmel“, „ein lebendiges Organ“, „blau, the sun is“

At 0.7 only the wording changes (“blue and the sun”, “blue, the grass”, “blue, because the su”). For every token in its vocabulary, the fixed list of all the pieces it knows, the model produces a raw score, the **logit**. A formula called **softmax** turns these into probabilities that add up to 100 percent. After „Der Himmel ist“, „ bl“, the start of „blau“, led for qwen3:8b with 30.4 percent.

Then exactly one token has to be picked. **Greedy** always takes the most likely one: predictable, but monotonous, and models fall into repetition loops more easily. **Sampling** draws as if from a raffle drum in which every token has as many tickets as its probability says. That’s why different answers come out.

**Temperature** bends the raffle drum. It divides all logits before softmax does its math. Below 1 the gaps grow, and the favorite wins even more often. Above 1 they shrink, and outsiders come up more often. At 1.5 the test falls apart: „ein lebendiges Organ“ (a living organ), a switch into English. That’s the long tail of unlikely tokens.

So nothing broke for Mark. If the model runs on your own computer, he can lower the temperature and set a fixed random starting value (seed); the same seed, the same settings and the same computer give the same text. With current cloud models that no longer works: Anthropic’s Claude models, Opus 4.7 and all newer ones, Sonnet 5.5 included, accept only the default values. If you send your own temperature, you get an error message instead of an answer. There, what helps is clear instructions, examples in the request, output in a fixed schema, and tests that check the result.

### In more detail: softmax by hand, with a number field

Formula: a token’s probability is e to the power of its logit, divided by the sum of e to the power of the logit over all tokens (e ≈ 2.718). With temperature T, each logit is first divided by T.

Example from chapter 3 with assumed logits: blau (blue) 3, grau (gray) 2, heute (today) 1, ein (a) 0. The e values are 20.086, 7.389, 2.718 and 1.000, together 31.193.

What percentage does blau get at temperature 1?

At T = 2 the logits are halved (1.5, 1, 0.5, 0) and grau reaches 27.6 percent; at T = 0.5 they are doubled (6, 4, 2, 0) and blau reaches 86.5 percent.

### In more detail: what the Claude API rejects

For Claude Opus 4.7 and newer models, the API answers non-default values for `temperature`, `top_p` or `top_k` with a 400 error. Starting with API version `2026-10-21`, merely sending them is rejected, even with the default value. Without the parameters, sampling runs at temperature 1.0. According to the migration guide for Claude Opus 5.5, temperature 0 never guaranteed identical outputs, not even with older models.

## Try it

**Temperature slider**

**Task:** Mark wants to see when outsiders come up more often. Get „grau“ (gray) above 25 percent and watch what happens to „heute“ (today) and „ein“ (a) along the way.

Without JavaScript, here are the values from chapter 3 (assumed logits 3, 2, 1, 0):

T = 0.5: blau 86.5%, grau 11.7%, heute 1.6%, ein 0.2%
T = 1: blau 64.4%, grau 23.7%, heute 8.7%, ein 3.2%
T = 2: blau 45.5%, grau 27.6%, heute 16.7%, ein 10.2%

## Check

**Question 2 (check question):** Mark has notice periods pulled from contracts on his own computer and wants the same result on every run. What does he set?

- A) A high temperature, so the model weighs things more thoroughly.
- B) Nothing, a language model always answers somewhat randomly.
- C) A low temperature and a fixed seed.

**Question 3 (check question):** The bot in the customer portal runs on Claude Sonnet 5.5 in the cloud. Mark wants to set the temperature to 0 there. What happens?

- A) From then on, the answers are the same for every request.
- B) The request is rejected with an error message.
- C) The model gets more accurate and makes up fewer facts.

## Done

**What you can do now**

- You can explain why the same question brings different answers: the model produces probabilities, and only drawing a token decides.
- You’ve seen on the slider what temperature does: below 1 the favorite wins more often, above 1 outsiders rise to the top.
- When a team complains about fluctuating answers, you first ask whether the model runs locally or in the cloud, and then suggest temperature and seed or, in the cloud, clear instructions, a fixed schema and tests.

### Two cards for review

**Card 1:** What does a temperature above 1 do to the distribution of the next tokens?

- A) It gets flatter, and outsiders come up more often.
- B) It gets more peaked, and the favorite wins more often.
- C) Nothing, temperature only affects the length of the answer.

**Card 2:** Why doesn’t “temperature 0” help with current Claude models, and what takes its place? What would work on your own computer?

- [Next mission: The bot made up a source](https://llm.yoga/en/einsatz-3-3.md)
- [Try it on your Mac](https://llm.yoga/en/mac-3-2.md)

## Read more in the chapter

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

- [Next-token guessing](https://llm.yoga/en/03-tokens-1.md)
- [From logits to probabilities: softmax](https://llm.yoga/en/03-tokens-2.md)
- [Picking: greedy, sampling, temperature](https://llm.yoga/en/03-tokens-2.md)
- [Top-k and top-p](https://llm.yoga/en/03-tokens-2.md)
- [Settings with cloud providers](https://llm.yoga/en/03-tokens-2.md)

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

**Question 1:** The correct answer is A.
- A, correct: Four times „ blau, die Sonne“ (blue, the sun). At temperature 0 the most likely token is always taken, so the random starting value plays no role.
- B: There was only one: four times „ blau, die Sonne“ (blue, the sun). At temperature 0 the model always takes the most likely token, so a different random starting value changes nothing either.
- C: Four different ones only came at a higher temperature. At 0 all four runs were the same: „ blau, die Sonne“ (blue, the sun).

**What percentage does blau get at temperature 1?** Answer: 20.086 / 31.193 = 64.4 percent.

**Question 2:** The correct answer is C.
- A: A high temperature doesn’t weigh anything; it makes unlikely tokens more likely. At 1.5 the test produced „ein lebendiges Organ“ (a living organ), the opposite of what Mark wants for deadlines.
- B: On his own computer, Mark has the dials in his hands. At temperature 0 all four runs were the same, and a fixed seed makes higher temperatures repeatable too.
- C, correct: At temperature 0 all four runs were the same. And with the same seed, the same settings and the same computer, the same text comes out locally, even at a temperature above 0.

**Question 3:** The correct answer is B.
- A: With Sonnet 5.5 the temperature can’t be changed at all. And according to Anthropic, temperature 0 never guaranteed identical outputs, even with older models.
- B, correct: Starting with Claude Opus 4.7, all models only accept the default values; the API rejects a custom temperature. Mark gets consistent results there with clear instructions, examples, a fixed schema and tests.
- C: Temperature 0 makes the model more predictable, not smarter: if the most likely token is wrong, you reliably get the wrong one. With Sonnet 5.5 the value can’t be set anyway.

**Card 1:** Correct: A, It gets flatter, and outsiders come up more often. Temperature divides the logits, the model’s raw scores, before softmax turns them into probabilities. Above 1 the gaps shrink and the distribution gets flatter. At 1.5 the test with qwen3:8b produced „ein lebendiges Organ“ (a living organ) and a switch into English.

**Card 2:** Starting with Claude Opus 4.7, the API rejects custom temperatures. Consistent results there come from clear instructions, examples, a fixed schema and tests. On your own computer, a low temperature and a fixed seed help: the same seed, the same settings and the same computer give the same text.
