Example

Example of Top-k Sampling with k=3

This example illustrates the top-k sampling process with k=3. First, five candidate words are ranked by their initial probabilities: 'cute' (Pr=0.34), 'on' (Pr=0.32), 'sick' (Pr=0.21), 'are' (Pr=0.12), and '.' (Pr=0.01). Next, the top k=3 candidates ('cute', 'on', 'sick') are selected, and the rest are pruned. The probabilities of these selected candidates are then renormalized to sum to 1, yielding new probabilities: 'cute' (Pr=0.39), 'on' (Pr=0.36), and 'sick' (Pr=0.25). Finally, a token is chosen by sampling from this new distribution, resulting in 'on' being selected as the final output.

0

1

Updated 2025-10-10

Contributors are:

Who are from:

Tags

Ch.5 Inference - Foundations of Large Language Models

Foundations of Large Language Models

Foundations of Large Language Models Course

Computing Sciences