How does temperature change token sampling?
Reveal the answer and explore the explanation.
03EasyCoreVisualHow does temperature change token sampling?
Answer
EasyCoreVisual
How does temperature change token sampling?
Answer
Rescales logits before sampling; lower positive values sharpen the distribution.
Deeper understanding
Sampling typically applies softmax(logits/T) for T > 0. Lower temperature concentrates probability on higher logits; higher temperature spreads probability. It changes sampling behavior rather than supplying new facts or improving retrieval.
Practical example
Make stochastic generation less varied.
PythonRelated concept example
import torch
logits = torch.tensor([1., 2., 3.])
for t in [0.5, 1., 2.]:
print((logits/t).softmax(0))Higher temperature flattens the distribution.
Reference: Further reading ↗