IT lexicon › AI & ML › Sampling

Sampling Decoding

AI & ML På svenska → Updated: 2026-07-29

How a language model picks the next token from the probability distribution it computed. The model is deterministic — sampling is what makes the answers vary.

The simplest approach is greedy decoding: always take the most likely word. That sounds sensible but produces flat, repetitive text that easily falls into loops. So logits are scaled by a temperature and a token is then drawn from the adjusted distribution. To avoid picking outright nonsense, the tail is truncated first: top-k keeps the k most likely, top-p (nucleus) keeps those that together reach probability mass p, min-p sets a floor relative to the top candidate. Repetition and frequency penalties counteract looping. For code and structured output you want temperature near zero; for creative text, higher.

← Back to the lexicon