← CS Lab AI & Machine Learning / Temperature Sampling Open standalone ↗

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

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)

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

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

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)

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

Next up
AI & Machine LearningContext Window AI & Machine LearningNext-Token Prediction All concepts →