← Back to Glossary
Top-K & Top-P Sampling
Top-K and Top-P (Nucleus) Sampling
Phase 02 · LLM Fundamentalstechnique

Filtering methods that restrict next-word choices to either the K most likely words or the top pool adding up to cumulative probability P.

Why it exists

High temperature sampling can occasionally select nonsensical long-tail words. Top-K and Top-P prune bad choices before sampling.

How it works

Top-K caps the candidate pool to the top K tokens (e.g. 50). Top-P dynamically keeps tokens until their combined probability reaches P (e.g. 0.9).

Where you'll use this