A model gives next-token probabilities for tokens A–E. What is the sampling distribution under top- with , and under nucleus (top-) sampling with ? Why is nucleus sampling often preferred to a fixed ?
Sequence models and transformers, Decoding
Level L2 Elementary. Length Medium. Nature Th+Mat Both.
What's being asked
Whether you can apply truncation and renormalisation and explain the adaptive size of the nucleus.
Key idea
Top- keeps a fixed number of tokens. Top- keeps the smallest set whose cumulative probability is at least . Both then renormalise the kept probabilities.
Steps
- Top-, : keep A and B, with total mass . Renormalise: . C, D and E get probability .
- Top-, : cumulative sums are , , . The smallest set reaching is .
- Renormalise by : .
- When the model is confident (for example ), the nucleus may contain one token, so output is nearly deterministic. When the model is unsure and probabilities are flat, the nucleus holds many tokens.
- A fixed cannot adapt: it may include many unlikely tokens in a confident step, or cut off reasonable tokens in an uncertain step.
- Both methods cut off the unreliable low-probability tail, which reduces incoherent text compared with pure sampling.
Common mistakes
- Forgetting to renormalise after truncation.
- Stopping at the token that stays just below instead of the first one that reaches or exceeds .
- Claiming top- and top- are equivalent for some fixed pair.
How long your answer should be
Worked solution; about 3 minutes.
Read this
Previous in Sequence models and transformers: An encoder gives hidden states , and . The decoder state is . Using Luong dot-product attention, compute the attention weights and the context vector. How does Bahdanau (additive) attention differ?
Next in Sequence models and transformers: In BERT's masked language modelling, of tokens are chosen for prediction. Of those, become [MASK], become a random token and stay unchanged. What fraction of all tokens are in each case? Why not simply use [MASK] every time?