passdrill
AI & LLM Engineering · Building with LLM APIs · Card 011/012 medium

An LLM generation API exposes both a `top_p` (nucleus sampling) parameter and, in some APIs, a `top_k` parameter, in addition to `temperature`. How does nucleus sampling with `top_p` differ from `top_k` sampling in how it restricts the model's next-token choices?

  1. `top_p` and `top_k` are two names for the exact same mechanism, differing only in whether the cutoff value is expressed as a percentage or as a raw integer
  2. `top_k` restricts choices based on cumulative probability mass, so its cutoff point moves depending on how confident the model is at each step, while `top_p` always keeps exactly the same fixed number of candidates
  3. `top_p` restricts sampling to the smallest set of most-probable tokens whose cumulative probability reaches the threshold `p`, so the number of candidates varies step to step, while `top_k` always keeps a fixed number of the highest-probability tokens regardless of how the probability mass is distributed
  4. Both parameters only take effect when `temperature` is set to exactly 0, and have no effect on generation at any other temperature value
Next card → Shuffle