logit bias (sometimes exposed as the logit_bias JSON object in the OpenAI API)
Definition
A mechanism that lets you directly nudge the probability of specific tokens by adding an arbitrary bias to their raw logits before the soft-max is taken. In practice you pass a map like
"logit_bias": {
"626": 100, // “🦄“ — make almost certain
"198": -100, // “\n” — virtually ban newline
"50256": -100 // <|endoftext|> — prevent premature EOS
}
How it works
- The model produces a vector of logits L (one per token in the vocabulary).
- For any token
t present in the logit_bias map, its logit is updated:
Lₜ ← Lₜ + biasₜ
- The soft-max converts the tweaked logits into the final probability distribution from which the next token is sampled.
Intuition
• A positive bias (e.g., +20 … +100) pushes the token toward certainty.
• A negative bias (e.g., −5 … −100) suppresses or even bans the token.
• Bias values in OpenAI’s implementation are clamped to the range [−100, 100].
Typical use-cases
• Make sure an answer is “Yes” or “No” (heavily bias those tokens).
• Prevent specific profanities, markdown, or the end-of-text token.
• Force units (“°C”, “$”, “kg”) when generating structured data.
• Gently steer style by boosting “therefore”, “hence”, etc.
Relationship to other knobs
• Unlike temperature, top_p, etc., logit_bias targets named tokens only.
• Works well in tandem with presence_ / frequency_penalty when you want both global stylistic variety and precise token control.
That’s it—logit bias is your fine-grained “manual override” on the model’s vocabulary!