Part 13 / Topic 3 of 6
Sampling
Given the distribution, how do you pick? Temperature rescales the logits before softmax (Part 2's maths):
# examples/02_temperature_reshapes_the_next_token_distribution.py
# T=0.5: Paris=0.991, Lyon=0.007, London=0.002, pizza=0.000
# T=1.0: Paris=0.875, Lyon=0.072, London=0.044, pizza=0.010
# T=2.0: Paris=0.619, Lyon=0.177, London=0.138, pizza=0.065
Low temperature sharpens (deterministic, repetitive); high flattens (creative, error-prone). Top-k keeps only the k most likely tokens; top-p keeps the smallest set whose probabilities sum to p — both cut the long tail of nonsense before sampling. Practical defaults: low temperature for extraction/classification, moderate for writing.
🧪 Quick quiz
- What does lowering the temperature do?
Show the answer
Sharpens the distribution toward the top token — measured: Paris went from 0.619 at T=2.0 to 0.991 at T=0.5.
Done here? The practice set for Part 13 — 4 exercises with solutions — is on the part page.