Top-k sampling

Sampling only from the k most likely tokens, ignoring the rest.

Top-k sampling is a middle ground: only the k likeliest tokens are allowed, which cuts off the strangest choices even at a high temperature.
From Predicting the next word, step “One token at a time”

See it in action

Try top-k sampling hands-on in the lesson Predicting the next word, part of the AI fundamentals course.

Open the lesson