Sampling

Sampling draws the next token from the model’s probability distribution (after optional shaping), introducing randomness into generation. Contrast with greedy decode or beam search, which are deterministic or search-based decoding.

Common knobs

  • Temperature — sharpen or flatten the softmax distribution
  • Top-$k$ — keep only the $k$ highest-probability tokens
  • Top-$p$ (nucleus) — keep the smallest set whose mass ≥ $p$

Practice

Low randomness → more deterministic, repetitive text. High randomness → more diverse, sometimes incoherent text. Prefer lower temperature / tighter nucleus for code and factual QA; allow more entropy for brainstorming. Fix seeds when you need reproducible evals.

← Back to AI Glossary