Sampling Settings — Temperature, Top-p, Penalties and Length
Tripmate writes the arguments for book_ticket a little differently each time, and once it picks the wrong train. Meanwhile, its trip descriptions for Asha read like the same sentence over and over. Both problems come from the same place: the settings that control how the model picks each next token.
The rule
Tools want low randomness; writing can afford a little more.
At every step the model scores every possible next token, and those scores become probabilities. Sampling settings shape how the next token is chosen from them:
- Temperature — sharpens or flattens the probabilities. Low (near 0) almost always takes the most likely token: steady and repeatable. Higher values give unlikely tokens more chance: more varied, and more error-prone.
- Top-p — keeps only the smallest group of top tokens whose probabilities add up to p, then samples among them. With
top_p = 0.8, rare long-shot tokens are never picked. - Frequency penalty — lowers a token's chance more each time it has already appeared. Cuts repeated words and phrases.
- Presence penalty — lowers a token's chance by a flat amount once it has appeared at all. Nudges the model toward new words and topics.
- Max length (max output tokens) — a hard cap on how much the model may write. When it is hit, the answer is simply cut off.
Providers name and support these a little differently, and a common piece of advice is to tune temperature or top-p, not both at once.