← Tokens, Context & Inference
05 · Tokens, Context & Inference · Topic 07

What are Sampling and Temperature?

Sampling controls how a model selects the next token from its predicted possibilities, while temperature is one setting that can change how concentrated those choices are.

What is it?

Sampling is the method used to choose a next token from the model's probability distribution.

Temperature is a generation setting that adjusts the shape of the token probability distribution before selection. Lower temperature usually makes higher-probability choices more dominant. Higher temperature usually spreads probability more broadly and can increase variation.

Think of it like...

Think of it like choosing food from a ranked menu.

At low temperature, you mostly choose from the top-ranked options. At higher temperature, lower-ranked options have a better chance of being selected.

How it works

1 · Next-token ProbabilitiesList possible choicesThe model assigns probabilities to possible next tokens.
2 · Apply Generation SettingsAdjust the distributionTemperature can make the distribution more or less concentrated.
3 · Adjusted DistributionRank the chancesThe possible tokens now have updated relative probabilities.
4 · Sampling MethodChoose by the ruleThe decoder uses sampling or another selection method.
5 · Selected TokenAdd one tokenThe chosen token becomes part of the growing output.
6 · Continue GenerationRepeat the loopThe model predicts and selects the next token again.

Real-world examples

Everyday example · Completing a message

Input: “I will meet you at the...”

System: compares likely next tokens such as “station” or “office”

Output: one selected continuation

AI product example · Chat assistant

Input: a user asks for several slogan ideas

System: samples tokens with a chosen temperature

Output: one generated response, with variation possible across runs

What it is NOT

Temperature ≠ Creativity

Temperature: changes how concentrated token choices are.

Creativity: a broader description of an output, not a direct model setting.

Sampling ≠ Prediction

Sampling: selects a token from available probabilities.

Prediction: produces the probability distribution for possible next tokens.

Temperature ≠ Accuracy Setting

Temperature: affects selection behavior and variation.

Accuracy: depends on the model, task, data, and evaluation.

Remember this

Prediction creates token probabilities; sampling chooses from them, and temperature can change how concentrated those choices are.

Video unavailable

Video

visual explainer

A video for this topic is not available yet.

↑