Top-p: LLM Nucleus Sampling

“The sky is seldom wealthy.” 😱 This nonsense is what I got from the LLM after dialing up the Temperature! (see demo below)

All I wanted was creativity, but all I got was chaos!

✨ Part 3/5 of The Creative Shell – What Makes LLMs “Creative”? (see part 2 here)

In the previous parts of this series, we explored how temperature loads the dice 🎲. We dial it up… and our LLM goes wild.

Here’s what’s really going on … and the setting that fixes it:
πŸ”₯ High temperature = creativity + chaos.

That “seldom wealthy” line happens because the model rolled a word with a very low probability (low but not impossible).


This is where Top-p (Nucleus Sampling) comes to the rescue.
Top-p says: “Only let the dice include faces whose total probability adds up to p%.”
It literally removes sides from the dice before you roll! πŸŽ²βœ‚οΈ

Example (temperature = 0.5), the probabilities are as follow – check image below for reference πŸ‘‡ the blue bars = available, grey = filtered out):

  • “the” ➑️ (57.30%)
  • “blue” ➑️(18.20%) πŸ›‘ (Top-p = 0.75 stops here)
  • “falling” ➑️(13.09%)
  • “a” ➑️(6.36%) πŸ›‘ (Top-p = 0.95 includes all)

πŸ”‘ Why Top-p Is Brilliant?
It’s dynamic…
When the model is confident β†’ small dice (few faces)
When it’s uncertain β†’ large dice (many faces)

Think of it like this:
Temperature loads the dice 🎲
Top-p carves away the unlikely faces βœ‚οΈ

πŸ’‘ Secret sauce: High temperature + low top-p = controlled creativity.
You get a balanced dice… but only with the best sides still on it.

πŸ’¬ What’s your go-to top-p setting? Drop it in the comments πŸ‘‡

One thought on “Top-p: LLM Nucleus Sampling

Leave a comment