/ module 07 · Inside the model
Sampling & Decoding
A model does not output a word. It outputs a score for every token in its vocabulary. Decoding is the step that turns those scores into one chosen token, and the knobs you set here decide whether answers feel precise, creative or unhinged.
- Explain logits and how softmax turns them into probabilities
- Predict the effect of temperature, top-k and top-p
- Say when greedy, sampling or beam search fits best
Try this first: Click the 'greedy' preset, sample 10 times, then try 'wild'.
concept
From logits to a token
The last layer produces logits. A softmax turns them into probabilities. Before sampling, we can reshape that distribution: temperature sharpens or flattens it, top-k and top-p cut off the unlikely tail, and a repetition penalty discourages words already used.
Press the button. Greedy settings give the same word ten times; wild settings give a mix, including odd choices.
search
Greedy is not always best
Greedy decoding grabs the single most likely token every step. Beam search keeps several partial answers alive and picks the sequence with the best total probability. In this two-step example, greedy picks "a" first (50%) but then has no strong follow-up, while "the dog" wins overall.
Chat models usually sample (temperature + top-p) because beam search tends to sound bland and repetitive in open-ended text. Beam search remains common in translation and speech recognition.
Check yourself
Tick each one you could explain to a friend. If you can't yet, scroll back up and replay the lab.