All posts

Logits

/AI/4 min read

Logits are a model's raw scores before they become probabilities. A logit of 0 is a coin flip, 2.2 is 90% and 4.6 is 99% — every 2.3 is another factor of ten in the odds. A language model produces 128,000 of them per token, and editing them directly is how constrained decoding works.

At the end of almost every neural network that makes a choice, there is a layer that produces one number per possible answer. A cat-or-dog classifier produces two; a language model produces one for every token in its vocabulary. Those numbers are logits: raw, unbounded scores, before anything turns them into probabilities.

They are worth understanding on their own, because a lot of practical work with models — sampling, constrained output, calibration, debugging — happens on logits rather than probabilities.

From logits to probabilities

For a single yes/no output, the logit becomes a probability through the sigmoid, p = 1 / (1 + e⁻ᶻ):

logitprobability
−2.210%
050%
173.1%
2.290%
4.699%

For many classes, the softmax does the same job across all of them at once: exponentiate each logit and divide by the total.

What a logit actually measures

The name comes from statistics, where the logit of a probability is its log-odds: log(p / (1 − p)). A probability of 90% is odds of 9 to 1, and log 9 ≈ 2.2. So a binary logit has a direct meaning:

  • 0 means even odds.
  • Each +2.3 multiplies the odds by 10 (because ln 10 ≈ 2.3): 2.2 is about 9:1, 4.6 about 99:1.
  • Negative logits favour "no" by the same amounts.

For softmax over many classes, only differences between logits matter. If one token's logit is 2.3 above another's, it is 10 times as likely, regardless of the logits' absolute values. That is why adding a constant to all logits changes nothing, and why logits are compared, not read in isolation.

EVERY 2.3 IS ANOTHER ×10 IN THE ODDS 0 → 50% 2.2 → 90% 4.6 → 99% −606 logit 10 logits are additive and unbounded; probabilities squash at both ends
Between 90% and 99% the probability barely moves; the logit moves a lot. Logits keep confidence readable.

Why models output logits, not probabilities

Numerical stability. Probabilities near 0 and 1 squash huge differences into tiny ones — 99% and 99.99% look similar but are odds of 99:1 and 9,999:1. Logits keep those differences on an even scale, and loss functions computed from logits directly (cross-entropy "with logits") avoid the rounding errors of taking the log of a near-zero probability.

Flexibility. The same logits can be turned into different distributions: divided by a temperature, filtered by top-k, biased, masked. All of these are simple operations on logits.

Logits in a language model

At each step, the final hidden vector — say 4,096 numbers — is multiplied by an output matrix with one row per vocabulary entry. For a 128,000-token vocabulary that is 524 million multiply-adds, producing 128,000 logits: 500 KB in 32-bit floats, every token. In an 8B-parameter model, that output projection alone is about 6.6% of the per-token arithmetic.

Everything about how the next token is chosen happens here:

  • Temperature divides every logit by T before the softmax.
  • Top-k and top-p discard the logits outside the chosen set.
  • Logit bias adds a fixed amount to specific tokens — +5 to encourage one, −100 to effectively ban it.
  • Constrained decoding sets the logits of every token that would break a required format — invalid JSON, a value not in a list — to −∞, so they have exactly zero probability. This is how structured outputs are guaranteed rather than requested.
  • Repetition penalties lower the logits of tokens that have already appeared.

Reading logits for insight

Because they are on an additive scale, logits are useful diagnostics:

  • The gap between the top two logits says how decisive a prediction was. A gap of 0.1 is a near coin flip between them; a gap of 7 is over a thousand to one.
  • Log-probabilities — logits after a log-softmax — are what APIs return as "logprobs", and are used to score answers, detect uncertainty, and estimate how surprising a piece of text is to the model.
  • Intermediate layers' logits — projecting a middle layer's vector through the output matrix — show what the model "would" predict partway through its computation, a common interpretability technique.

What to take away

Logits are the raw, unbounded scores a model produces before softmax or sigmoid turns them into probabilities. A binary logit is log-odds: 0 is 50%, 2.2 is 90%, 4.6 is 99%, and every 2.3 is another factor of ten. Only differences between logits matter.

Language models produce one logit per vocabulary token — 128,000 per step — and almost every decoding technique, from temperature to guaranteed JSON, is an operation on those numbers before a token is chosen.