Logit Bias: Controlling Token Probabilities
Summary
Logit Bias is an API parameter that allows changing logits of individual tokens before sampling, enhancing or prohibiting their generation.
Definition
Logit Bias applies an additive bias to the logits of selected tokens before the softmax function is applied. Positive values increase the probability of a token, negative values decrease it; a sufficiently negative value effectively prohibits the token.
Unlike temperature and top-p/top-k, which redistribute probabilities globally, Logit Bias acts specifically on individual tokens.
Parameter Format
The parameter is passed as a dictionary of token identifiers to bias values:
{
"logit_bias": {
"50256": -100,
"12345": 5.0
}
}
Values are typically limited to the range of -100 to +100. A bias of -100 practically excludes the token from the selection.
Applications
| Scenario | Bias |
|---|---|
| Prohibiting special tokens | Negative |
| Forcing response format | Positive |
| Limiting domain dictionary | Negative for foreign terms |
| Eliminating unwanted lexicon | Negative |
graph LR
A[Model logits] --> B[Application of logit_bias]
B --> C[Softmax]
C --> D[Sampling]
D --> E[Token]
Limitations
- Requires knowledge of specific tokenizer token identifiers.
- Does not guarantee adherence to complex grammars; for this, use grammar-constrained generation.
- Support varies by API provider; local inference engines may not implement the parameter.
- Large biases may lead to degradation of text coherence.
Comparison with Alternatives
| Method | Level of Impact | Flexibility |
|---|---|---|
| Logit Bias | Individual Tokens | Point-specific |
| Temperature | Full Distribution | Global |
| Top-p / top-k | Distribution Tail | Global |
| Structured decoding | Grammar | Schema-based |
Logit Bias is used in classification tasks through generation, forced selection from a fixed set of answers, and in constructing structured output in combination with JSON Schema.