A language model can produce fluent text even when several continuations look similarly plausible to the model. Looking only at the selected token hides that ambiguity: a token chosen with probability 0.90 and one chosen from a nearly even 0.51 versus 0.49 split both appear as a single output token.
Token entropy summarizes how spread out the model’s next-token probability distribution is. It can help developers inspect uncertain generation steps, compare decoding behavior under controlled conditions, and build diagnostic signals for evaluation. But entropy is not a probability that the model is correct, and using it as one leads to unreliable decisions.
This article builds the metric from a two-token example, then explains how to use it responsibly with real language-model distributions and where the signal breaks down.
Start with the next-token distribution
At each generation step, an autoregressive language model assigns a probability to every token in its vocabulary, conditioned on the preceding context.
Consider a deliberately tiny vocabulary with only two possible next tokens. For one context, suppose the model produces:
"yes": 0.90
"no": 0.10For another context:
"yes": 0.50
"no": 0.50The first distribution is concentrated. The model strongly favors one continuation. The second is spread evenly, so the model does not prefer either token.
Entropy turns this idea of concentration into a number.
For token probabilities p_1 ... p_V, Shannon entropy is:
H = -sum(p_i * ln(p_i))where the sum covers the vocabulary and ln is the natural logarithm. With natural logarithms, entropy is measured in nats. Using base-2 logarithms instead measures it in bits; either convention is valid as long as comparisons use the same one.
For the 90/10 distribution:
H = -(0.90 * ln(0.90) + 0.10 * ln(0.10))
~= 0.325 natsFor the 50/50 distribution:
H = -(0.50 * ln(0.50) + 0.50 * ln(0.50))
~= 0.693 natsThe evenly split distribution has higher entropy because its probability mass is less concentrated.
What entropy actually measures
The useful mental model is simple:
probability concentrated on a few tokens -> lower entropy
probability spread across many tokens -> higher entropyFor a distribution over V possible tokens, entropy is zero when one token has probability 1. It reaches its maximum of ln(V) nats when all V tokens have equal probability.
That gives entropy a precise interpretation as a property of the model’s probability distribution. It does not give entropy a direct interpretation as factual confidence.
Suppose a model confidently predicts the wrong completion:
wrong token: 0.98
other tokens combined: 0.02This distribution has low entropy even though the dominant prediction is wrong. Conversely, a prompt may legitimately permit several synonymous continuations, creating high token entropy even though all of them would lead to acceptable answers.
Entropy therefore answers:
How concentrated is the model’s next-token distribution here?
It does not answer:
How likely is the generated statement to be true?
That distinction is the foundation for using the metric safely.
Compute entropy from logits
Language models commonly produce logits, which are unnormalized scores, before converting them into probabilities with softmax.
For logits z_i, the probability of token i is:
p_i = exp(z_i) / sum(exp(z_j))Entropy is then computed from those probabilities.
In pseudocode:
log_probs = log_softmax(logits)
probs = exp(log_probs)
entropy = -sum(probs * log_probs)Using log_softmax is a common numerically stable way to obtain log probabilities without separately taking the logarithm of very small softmax outputs.
The calculation should cover the distribution whose uncertainty you intend to measure. If generation has already masked tokens or changed logits with a decoding rule, entropy of that modified distribution describes the decoder’s current choice distribution, not necessarily the model’s original next-token distribution.
Temperature changes the entropy you observe
Temperature rescales logits before softmax:
p_i(T) = exp(z_i / T) / sum(exp(z_j / T))For positive temperature T, values below 1 generally sharpen a non-uniform distribution, while values above 1 flatten it. Sharpening usually lowers entropy; flattening usually raises it.
That means two entropy measurements are not directly comparable if they were produced under different temperature settings.
Imagine the same raw model logits evaluated twice:
raw logits -> temperature 0.7 -> sharper probabilities -> entropy A
raw logits -> temperature 1.2 -> flatter probabilities -> entropy BA larger B would partly reflect the decoding configuration rather than a change in what the underlying model learned.
For evaluation, decide whether you want entropy from the raw model distribution or from the post-processed sampling distribution, document that choice, and keep it consistent across examples.
Use token entropy as a diagnostic signal
A practical use is to record entropy at each generation step and inspect where it changes.
Suppose a model generates:
The capital of France is Paris .A diagnostic trace might conceptually look like:
The 2.4
capital 1.8
of 0.7
France 1.2
is 0.4
Paris 0.3
. 0.6These numbers are illustrative, not values from a real model. Their purpose is to show the shape of the data: each generated token can be paired with the entropy of the distribution from which that token was selected.
Such traces can help answer questions including:
- Where does a model face several plausible continuations?
- Does a prompt change uncertainty around a particular decision point?
- Are unexpectedly unstable outputs associated with high-entropy steps?
- Does a decoding change merely alter sampling behavior, or also affect the distributions being inspected?
The strongest use is diagnostic. Entropy can identify steps worth investigating, after which task-specific evaluation determines whether those steps correspond to actual errors.
Sequence-level summaries need care
Applications often want one uncertainty value for an entire generated answer rather than one value per token. A tempting approach is to sum token entropies:
sequence_entropy_score = H_1 + H_2 + ... + H_nThe problem is that longer sequences naturally contain more terms. A 100-token answer can accumulate a larger sum than a 10-token answer even if their typical per-token uncertainty is similar.
An average avoids that direct length scaling:
mean_token_entropy = (H_1 + H_2 + ... + H_n) / nBut the average also loses information. A sequence with one extremely uncertain decision and many predictable formatting tokens can have the same mean as a sequence with moderate uncertainty everywhere.
For diagnostics, it is often more informative to keep several features:
mean entropy
maximum entropy
high-entropy token positions
answer lengthThen evaluate whether any of those features predict the failure mode that matters to the application.
Importantly, averaging per-step entropies is not the same as computing the entropy of the full distribution over all possible generated sequences. Autoregressive sequence probabilities depend on branching continuations, and enumerating that complete sequence distribution is generally impractical for realistic generation lengths.
Do not reconstruct full entropy from a few returned tokens
Some inference interfaces expose only the most likely few token probabilities rather than the full vocabulary distribution. That is enough for many debugging tasks, but it is not enough to compute the exact full-distribution entropy unless the omitted probability mass and its distribution are also known.
Suppose an interface returns:
token A: 0.50
token B: 0.20
other vocabulary mass: 0.30The entropy contribution of that remaining 0.30 depends on how it is distributed. One omitted token holding all 0.30 is very different from thousands of omitted tokens each holding a tiny amount.
Renormalizing only A and B to sum to 1 computes the entropy of a different conditional distribution. It should not be labeled as the model’s full token entropy.
If only top-token probabilities are available, either use a clearly named partial diagnostic or choose a metric that the available data actually supports.
Tokenization affects comparisons
Entropy is defined over tokens, and token vocabularies differ across model families. The same text can be split into different numbers and kinds of tokens by different tokenizers.
As a result, raw token entropy is most straightforward to compare when the model, tokenizer, vocabulary, and probability-processing pipeline are held fixed. Cross-model comparisons require more care because a difference can reflect the representation as well as model behavior.
Normalizing entropy by ln(V) places a distribution between 0 and 1 for a fixed vocabulary of size V:
normalized_entropy = H / ln(V)This can describe concentration relative to that vocabulary’s theoretical maximum, but it does not make models with different tokenizations semantically equivalent. A tokenizer changes the prediction units themselves, not merely the scale of the entropy number.
Entropy is not a hallucination detector by itself
Low entropy can accompany a hallucination when a model has learned a strong but incorrect continuation. High entropy can appear in harmless places such as wording choices, punctuation, names with multiple valid spellings, or open-ended creative text.
For a factual question-answering system, stronger evaluation usually needs signals tied to the task. Depending on the application, those might include retrieval evidence, exact or semantic answer checks against labeled data, citation verification, consistency tests, or human review.
Entropy can complement those methods. For example, a team might investigate whether factual errors become more common above a particular entropy feature on a held-out evaluation set. If the relationship is useful, the threshold should be selected and validated on representative data rather than assumed from the entropy formula.
This also separates uncertainty measurement from calibration. A signal can rank some uncertain cases above confident ones without its numeric value representing a calibrated probability of correctness.
Common mistakes
Several mistakes make token-entropy dashboards look more meaningful than they are:
- Treating low entropy as correctness. A concentrated distribution can still favor the wrong token.
- Comparing different temperatures without accounting for them. Temperature directly changes probability concentration.
- Calling top-k renormalized entropy full entropy. Omitted probability mass can materially change the result.
- Ignoring tokenization across models. Different prediction units weaken direct cross-model comparisons.
- Using one universal threshold. Useful thresholds depend on the model, task, processing pipeline, and failure cost.
- Reducing every sequence to one mean. Local uncertainty spikes can disappear in an average.
- Measuring after decoding transformations without saying so. The resulting entropy may describe the sampling policy rather than the raw model distribution.
These are not reasons to avoid entropy. They are reasons to define precisely what was measured.
When token entropy is useful
Token entropy is a good fit when you can inspect model probabilities and need a compact measure of next-token concentration. It is especially useful for model debugging, controlled prompt comparisons, generation traces, and features inside a broader evaluation system.
A simpler signal may be sufficient when the decision concerns only the probability of one specific token or class. And when the real question is whether an answer is factually correct, safe, or supported by evidence, task-specific evaluation should remain the primary measurement.
The practical rule is to keep the metric attached to its meaning: token entropy measures how spread out a next-token distribution is. Use that signal to find ambiguity, then validate whether that ambiguity predicts the application outcome you actually care about.
Conclusion
Token entropy compresses a full next-token probability distribution into a useful measure of concentration. Low values indicate that probability mass is focused on fewer tokens; high values indicate that more alternatives remain competitive.
Its value comes from using that narrow meaning correctly. Compute it over a clearly defined distribution, keep decoding settings and tokenization in mind, avoid pretending partial probabilities are complete, and validate any sequence-level threshold against real task outcomes. Used this way, entropy becomes a practical diagnostic for language-model behavior without being mistaken for a correctness score.