Temperature is the knob that decides how boldly a language model gambles on its next word. Every step, the model has a probability for each candidate token; temperature reshapes those odds before a token is drawn — turning the same model from cautious and repetitive into loose and surprising.
Where you meet it
- The
temperatureandtop_pparameters in the OpenAI, Anthropic and Hugging Face generation APIs. - The slider behind "more precise ↔ more creative" in chat assistants and writing tools.
- Anywhere a model samples rather than always taking the single best token — code, prose, image captions, agents.
What it does
It rescales the model's raw scores so the probability curve gets sharper or flatter. A sharp curve concentrates almost all the mass on the top one or two tokens (safe, predictable). A flat curve spreads the mass out, giving long-shot tokens a real chance (diverse, riskier). Temperature changes nothing the model knows — only how decisively it commits.
Temperature changes nothing the model knows — only how boldly it bets on what it already thinks.
How it works
For each step the model emits a vector of logits z (raw, unnormalized scores). softmax turns them into a probability distribution. Temperature T simply divides the logits first:
p_i = softmax(z / T)_i = exp(z_i / T) / Σ_j exp(z_j / T)
- T < 1 — dividing by a small number stretches the gaps between logits → the curve sharpens, the model gets more deterministic.
- T > 1 — shrinks the gaps → the curve flattens, rarer tokens get more probability, output gets more random.
- T → 0 — the top logit dominates completely → equivalent to
argmax, i.e. greedy decoding.
top-k and top-p then prune the tail before sampling. top-k keeps only the k highest-probability tokens. top-p (nucleus sampling, Holtzman et al.) keeps the smallest set of tokens whose probabilities sum to p, so the cut adapts to how confident the model is. Everything else is zeroed and the survivors are re-normalized — then one token is drawn at random by weight.
Watch out
- High temperature degrades fast. Push T well above 1 and text drifts into incoherence and hallucination — the flat tail lets genuinely wrong tokens through.
- T = 0 is not "always identical". Tie-breaking, floating-point order, batching and backend non-determinism mean greedy decoding can still vary run to run; vendors (e.g. Anthropic) state outputs aren't fully deterministic even at temperature 0.
- Temperature and top-p interact. They stack — a hot temperature with a tight top-p is not the same as either alone. Tune one at a time; many teams fix top-p and only move temperature.
- It is not a magic "creativity dial". Higher T adds variance, not better ideas. For factual or structured tasks, low T (or greedy) is usually the right call.
Go deeper
- Hugging Face — Generation strategies (greedy, sampling, beam)
- Hugging Face blog — How to generate text (temperature, top-k, top-p, with plots)
- Holtzman et al. — The Curious Case of Neural Text Degeneration (nucleus / top-p, ICLR 2020)
- Anthropic — Messages API: temperature & top_p (and why T=0 isn't fully deterministic)
- Jurafsky & Martin — Speech and Language Processing (SLP3), LLM chapter on decoding
Die Temperatur ist der Regler, der bestimmt, wie mutig ein Sprachmodell auf sein nächstes Wort wettet. In jedem Schritt hat das Modell für jedes Kandidaten-Token eine Wahrscheinlichkeit; die Temperatur formt diese Chancen um, bevor ein Token gezogen wird — und macht aus demselben Modell wahlweise vorsichtig-repetitiv oder locker und überraschend.
Wo es vorkommt
- Die Parameter
temperatureundtop_pin den Generierungs-APIs von OpenAI, Anthropic und Hugging Face. - Der Schieberegler hinter "präziser ↔ kreativer" in Chat-Assistenten und Schreibtools.
- Überall, wo ein Modell samplet, statt immer das einzelne beste Token zu nehmen — Code, Prosa, Bildunterschriften, Agents.
Was es tut
Es skaliert die rohen Scores des Modells so um, dass die Wahrscheinlichkeitskurve schärfer oder flacher wird. Eine scharfe Kurve bündelt fast die gesamte Masse auf dem ein bis zwei Top-Token (sicher, vorhersehbar). Eine flache Kurve verteilt die Masse, sodass Außenseiter-Token eine echte Chance bekommen (vielfältig, riskanter). Die Temperatur ändert nichts am Wissen des Modells — nur, wie entschlossen es sich festlegt.
Die Temperatur ändert nichts am Wissen des Modells — nur, wie mutig es auf das wettet, was es ohnehin schon denkt.
Wie es funktioniert
Pro Schritt gibt das Modell einen Vektor von Logits z aus (rohe, nicht normierte Scores). softmax macht daraus eine Wahrscheinlichkeitsverteilung. Die Temperatur T teilt die Logits einfach zuvor:
p_i = softmax(z / T)_i = exp(z_i / T) / Σ_j exp(z_j / T)
- T < 1 — Teilen durch eine kleine Zahl spreizt die Abstände zwischen den Logits → die Kurve schärft, das Modell wird deterministischer.
- T > 1 — staucht die Abstände → die Kurve flacht ab, seltenere Token bekommen mehr Wahrscheinlichkeit, der Output wird zufälliger.
- T → 0 — das Top-Logit dominiert vollständig → äquivalent zu
argmax, also Greedy-Dekodierung.
top-k und top-p kappen danach den Schwanz, bevor gesamplet wird. top-k behält nur die k wahrscheinlichsten Token. top-p (Nucleus-Sampling, Holtzman et al.) behält die kleinste Menge an Token, deren Wahrscheinlichkeiten sich zu p summieren — der Schnitt passt sich also an, wie sicher das Modell ist. Alles andere wird auf 0 gesetzt, die Überlebenden werden neu normiert — dann wird ein Token zufällig nach Gewicht gezogen.
Worauf achten
- Hohe Temperatur kippt schnell. Schiebt man T deutlich über 1, driftet der Text in Inkohärenz und Halluzination — der flache Schwanz lässt echt falsche Token durch.
- T = 0 heißt nicht "immer identisch". Tie-Breaking, Fließkomma-Reihenfolge, Batching und Backend-Nichtdeterminismus führen dazu, dass Greedy-Dekodierung von Lauf zu Lauf variieren kann; Anbieter (z. B. Anthropic) weisen darauf hin, dass Outputs selbst bei Temperatur 0 nicht vollständig deterministisch sind.
- Temperatur und top-p wirken zusammen. Sie stapeln sich — eine heiße Temperatur mit engem top-p ist nicht dasselbe wie eines von beiden allein. Immer nur einen Wert drehen; viele Teams fixieren top-p und bewegen nur die Temperatur.
- Es ist kein magischer "Kreativitäts-Regler". Mehr T bringt mehr Varianz, nicht bessere Ideen. Für faktische oder strukturierte Aufgaben ist niedriges T (oder Greedy) meist die richtige Wahl.
Mehr dazu
- Hugging Face — Generation strategies (Greedy, Sampling, Beam)
- Hugging-Face-Blog — How to generate text (Temperatur, top-k, top-p, mit Plots)
- Holtzman et al. — The Curious Case of Neural Text Degeneration (Nucleus / top-p, ICLR 2020)
- Anthropic — Messages API: temperature & top_p (und warum T=0 nicht voll deterministisch ist)
- Jurafsky & Martin — Speech and Language Processing (SLP3), LLM-Kapitel zur Dekodierung