Natural Language Processing · free preview

Decoding and Sampling Strategies

Greedy decoding and its failure mode, random sampling, temperature, and the top-k and top-p truncations that balance quality and diversity.

1. Decoding and Sampling Strategies

Decoding and Sampling Strategies

2. Temperature and truncation

Temperature and truncation

3. Four decoders in NumPy

Four decoders in NumPy

4. Greedy decoding

A model's next-token distribution is fog 0.330.33, tide 0.220.22, gulls 0.210.21, horn 0.240.24. Which word does greedy decoding emit? Answer with the word.

5. Which way does the temperature bend the distribution?

A decoder divides logits by τ=4\tau = 4 before the softmax. What happens to the probability of the leading token, and what generation quality changes with it?

6. Top-k renormalization

A distribution over four words is [0.5,0.3,0.15,0.05][0.5, 0.3, 0.15, 0.05]. Top-2 sampling keeps the 22 largest, discards the rest, and renormalizes. Compute the new probability of the top word, rounding to three decimals.

7. Why the nucleus adapts

Two contexts both decode with top-p at 0.6. In context A the top two tokens hold 0.85 of the mass together, in context B the top five hold 0.55. What does the nucleus keep in each?

8. When greedy fails

Which task and decoder pairing is most defensible?

Practice this interactively

Free account · instant grading · spaced review that schedules itself.

Start this course for free