New Tool Radar

AI Concepts

How to Use Top-P Nucleus Sampling for Creative Writing

Shape creative output with top-p nucleus sampling, so the model stays varied without wandering into nonsense.

Schematic illustration with three step boxes: learn what top-p does, pick a value for the task, and test the variety.

Top-p, or nucleus sampling, limits the model’s choices to the smallest set of tokens whose probabilities add up to p. A top-p of 0.9 means the model considers the most likely tokens that add up to 90 percent probability. It is more dynamic than top-k, because the set grows and shrinks with the model’s confidence at each step. For creative writing, a top-p near 0.95 keeps variety while cutting the long tail of unlikely tokens.

Before you start

An API or local inference setup where you can set top-p, and a creative writing prompt you can run several times.

Learn what top-p does

At each step the model sorts the tokens by probability and keeps adding them until their probabilities sum to p. The rest are excluded. A low p keeps only the safest tokens; a high p admits more of the tail.

Unlike top-k, which keeps a fixed count, top-p keeps a fixed probability mass: when the model is confident, the set is small, and when it is unsure, the set grows.

Pick a value for the task

Use 0.9 to 0.95 for creative writing, 0.9 for general chat, and 1.0, which disables it, when you want the full range or when you are tuning temperature alone. Published guidance puts storytelling at 0.95 and technical writing at 0.9.

Change one setting at a time: if you change temperature and top-p together, you cannot tell which one changed the output.

Test the variety on repeats

Run the same prompt five times at your chosen top-p and read the five outputs. Good creative sampling gives five different openings with the same facts; bad sampling gives five near-copies or one wild departure.

If the outputs are too similar, raise top-p or the temperature. If they wander off topic, lower top-p first, because it cuts the tail directly.

Practice check: fictional Maple Corner product story prompt, 5 runs

The table below is fictional practice material, worked out by hand from the stated settings. It is the expected result for the practice prompt, not a run of any model.

Top-p Distinct openings of 5 Off-topic runs Verdict
0.5 2 of 5 0 Too repetitive
0.9 4 of 5 0 Best balance
0.95 5 of 5 1 Pass, one wanderer
1.0 5 of 5 2 Too wild

Top-p 0.9 gives 4 distinct openings with no off-topic runs, the best balance here. At 0.5 the outputs repeat, and at 1.0 two of five wander off topic.

Expected result. UNTESTED: the counts in the practice table are worked out by hand, not measured by running a model. Run your own creative prompt five times at top-p 0.9 and 0.95, count the distinct openings, and note any off-topic runs.

Limits

  • Most experts prefer tuning top-p over top-k: set one of them and leave the other at its default.
  • Top-p and temperature interact: a high temperature with a high top-p is the wildest combination, so change one at a time.

Sources

See all