# What Does Temperature Control?

> What temperature does to an AI model's word choices, why zero is still not fully fixed, and when to turn it up or down, for your AI interview.

**In short:** Temperature is a setting that controls how random a model's word choices are. A low setting makes the most likely word win, so answers stay steady. A high setting lets less likely words through, so answers vary more.

AI and LLM interview question Q010, LLM fundamentals. Beginner, very common (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/what-does-temperature-control

## Say it in 30 seconds

Temperature controls how random the model's word choices are. For each word it writes, the model gives every candidate a chance. A low temperature makes the likely words much more likely, so answers are steady, which suits pulling out fields or sorting tickets. A high temperature spreads the chances out, so the wording varies more. Even at zero, results are not fully fixed between calls, so I never rely on temperature for accuracy. I check figures in code.

## Say it in 2 minutes

A language model writes text one token at a time. A token is a small piece of text, often part of a word. Before each token, the model scores every candidate next token, and those scores become chances. Temperature decides how closely the model sticks to those chances. Think of a call centre agent reading from a script. At a low setting, they read the approved line every time. At a high setting, they pick from a wider set of phrasings, so two calls sound different.

Take a support assistant at a mid-size bank that drafts replies about declined cards. At a low setting, the reply is nearly the same each time, which is what the compliance team wants. At a high setting, the wording changes on every run, and one version may quote the wrong daily limit. The setting only changes which words get picked. The model's knowledge stays the same.

Technically, the scores are divided by the temperature before they are turned into chances. A number below one sharpens the top choice, and a number above one flattens the spread. Even at zero, results are not fully deterministic across calls, so I would never trust temperature alone for an exact figure.

In an interview, show you know the setting's job and its limits. Low for extraction and routing, higher for drafts, and checks in code for anything exact. That answer shows judgement, and it is what the interviewer wants to hear.

## What does temperature mean, in plain words?

A language model writes text one token at a time. A token is a small piece of text, often part of a word. Before each token, the model gives every possible next token a score, and those scores turn into chances.

Temperature is the dial that decides how strictly the model follows those chances. Turn it down and the likeliest choice wins most of the time. Turn it up and the model is more willing to try a less likely word.

Think of a call centre agent reading from a script. At a low setting, they read the approved line every time. At a high setting, they choose from a wider set of phrasings, so two calls sound different. A wider choice also means a poor phrasing can come out. In the model, the same choice happens for every word, so a bank's drafted reply can vary from run to run.

- **Chance:** The score turned into a percentage. The chances for all candidate words add up to 100%.
- **Softmax:** The step that turns raw scores into chances. Temperature acts just before it.
- **Sampling:** Picking one word at random, weighted by its chance.
- **Greedy decoding:** Always taking the single most likely word.

## How does temperature change the chances?

The model first gives every candidate a raw score. A step called softmax turns those scores into chances. Temperature is applied to the scores before that step, so it reshapes the chances without touching the model's knowledge.

*Diagram, How one word gets picked: The model scores every candidate, the settings reshape those scores, and one word is drawn from what is left. Temperature is one of the settings in the middle.*
1. Every candidate word gets a score from the model.
2. The scores are reshaped, then one word is drawn from what is left.
3. The chosen word joins the text, and the loop starts again.

Here is a worked example. A made-up model has just read a refund policy for a bank and must finish a policy sentence that starts with refunds over $500 needing a manager's. Its own chances are 62% for approval, 18% for sign-off, 10% for review, 6% for check and 4% for form.

*Diagram, Five candidates for one word: The model's own chances come first, then the same five candidates at two temperatures. At 0.5 the top word takes 89% of picks. At 1.5 the lower words get a real share.*
1. The prompt goes to the model, which scores five candidate words.
2. A temperature of 0.5 sharpens those chances, so the top word takes most picks.
3. A temperature of 1.5 flattens them, so the lower words get a real share.

A temperature below one makes the top choice pull further ahead. A temperature above one flattens the spread, so more words get a turn. Geoffrey Hinton and his co-authors used a higher temperature to produce softer training signals, so a small model could learn from a large one.

Here is the same maths in a short Python program. It starts from the same five chances and prints what each setting does.

```python
import math

WORDS = [" approval", " sign-off", " review", " check", " form"]
SCORES = [math.log(p) for p in (0.62, 0.18, 0.10, 0.06, 0.04)]

def chances(scores, temperature):
    scaled = [s / temperature for s in scores]
    top = max(scaled)
    exps = [math.exp(s - top) for s in scaled]
    total = sum(exps)
    return [e / total for e in exps]

for t in (0.5, 1.0, 1.5):
    row = chances(SCORES, t)
    shown = "  ".join(f"{w.strip()} {p:.0%}" for w, p in zip(WORDS, row))
    print(f"temperature {t}: {shown}")
```

Output:

```text
temperature 0.5: approval 89%  sign-off 8%  review 2%  check 1%  form 0%
temperature 1.0: approval 62%  sign-off 18%  review 10%  check 6%  form 4%
temperature 1.5: approval 47%  sign-off 21%  review 14%  check 10%  form 8%
```

Some tools also offer top-k and top-p. These two settings cut the list of candidate words before one is picked. Top-k keeps only the k most likely words. Top-p keeps the fewest likely words whose chances add up to p. Check your provider's guidance before you change more than one of these at once.

## Which setting should you use, and when?

Pick the setting for the job at hand. Low settings suit jobs with one right answer, such as pulling fields out of a form or routing a ticket. Higher settings suit drafts and options, where variety is the point.

- **Lower: Extraction and routing.** Claim numbers, ticket labels and fields copied from a form. The same input should give the same answer, and code checks it.
- **Higher: Drafts and options.** Subject lines, five ways to open a complaint letter, or names for a new product. A person reviews every one.
- **Watch out: Higher adds no facts.** Turning it up only changes which words are picked. A wrong figure can still come out in smooth, fluent text.

1. **Start low for routing:** A complaint about a fee gets the same label each run, so the queue stays right.
2. **Check the output in code:** The label must be one of the six known labels. Anything else goes to a person, not the customer.
3. **Raise it only for wording:** Drafted replies can use a higher setting, and an agent signs off before anything is sent.

> "Even with temperature set to 0, the results will not be fully deterministic, and identical inputs might produce different outputs across API calls." (Anthropic)
>
> "Temperature is a parameter that controls the randomness of a model's predictions during text generation." (Anthropic)

> **Tip:** If asked how to make output repeatable, say a low setting helps. It is still not a guarantee. Anthropic's glossary warns that identical inputs can still produce different outputs, even at zero.

## What does the interviewer want to hear?

**A strong answer covers**

- [ ] A plain definition: temperature reshapes the chances the model picks from.
- [ ] What a low and a high setting do, with a chance example.
- [ ] Why zero is still not a guarantee of identical output.
- [ ] Temperature changes which words get picked, so it cannot fix wrong facts.
- [ ] Low for extraction and routing, higher for drafts.
- [ ] Code checks anything that must be exact.

**Common traps**

- Trap: "Set the temperature to 0 and the answers are always correct." Better: Zero makes the output steadier, but it does not make facts correct. Check figures in code.
- Trap: "A higher temperature makes the model smarter." Better: It only changes which words get picked.
- Trap: "Temperature 0 gives identical output every time." Better: Not guaranteed. Results are not fully deterministic across calls.

## Can you spot the problem?

**Spot the setting:** A claims team wants one setting for a model that reads claim forms and writes 12 fields into the claims database. Which config is right?

A. temperature = 1.4  # more natural wording for the customer
B. temperature = 0.2  # steady field values, and code checks each one
C. temperature = 0.0  # guarantees the same fields on every run

**Answer:** B. Low temperature keeps the values steady, and code still checks each field. Zero is not a guarantee, since results can vary between calls. Wording for customers is not what a database needs.

**Quick check:** A discharge-note tool gives different wording on each run, and a nurse says a dose line changed. What do you do first?

A. Raise the temperature so the model tries new wording
B. Lower the temperature, and check each dose in code against the chart
C. Switch to a bigger model and see if the dose changes
D. Set the temperature to 1.0 so the dose line comes out accurate

**Answer:** B. A lower setting steadies the wording. No setting guarantees a correct dose. The check belongs in code, against the source chart. A bigger model or a different setting does not replace that check.

## Can you answer these from memory?

**Flash cards**

- **What does temperature control?** How random the model's word choices are. It reshapes the chances the model picks from.
- **What does a low setting do?** The most likely word wins more often, so answers are steadier and easier to repeat.
- **What does a high setting do?** Less likely words get picked more often, so wording varies and errors can slip in.
- **Is temperature 0 fully deterministic?** No. Results can still vary between calls, so do not assume identical output.
- **Does temperature add knowledge?** No. It only changes how words are picked.
- **What is softmax?** The step that turns raw scores into chances that add up to 100%.

## Likely follow-up questions

- Q011 What is top-k sampling? https://designervenkat.online/interview/ai/what-is-top-k-sampling
- Q012 What is top-p (nucleus) sampling? https://designervenkat.online/interview/ai/what-is-top-p-nucleus-sampling
- Q013 Greedy vs beam search vs sampling? https://designervenkat.online/interview/ai/greedy-vs-beam-search-vs-sampling
- Q014 Why can one prompt give different answers? https://designervenkat.online/interview/ai/why-can-one-prompt-give-different-answers
- Q022 What are logits, and what does softmax do? https://designervenkat.online/interview/ai/what-are-logits-and-what-does-softmax-do
- Q023 What is a hallucination, and why does it happen? https://designervenkat.online/interview/ai/what-is-an-ai-hallucination

## Learn it in depth

- [Sampling Parameters](https://designervenkat.online/learn/ai-engineering/sampling-parameters)
