The one honest number
Ask a model how confident it is and it produces text: the word “95%” generated the same way as any other word, with no connection to anything internal. But the model does expose a real number: the probability it assigned to each token it chose, and to the alternatives it did not.
Most APIs return this on request, and every local library gives it to you for free.
resp = client.chat.completions.create(
model="...", messages=msgs, logprobs=True, top_logprobs=5,
)
for t in resp.choices[0].logprobs.content:
print(t.token, round(t.logprob, 2),
[(a.token, round(a.logprob, 2)) for a in t.top_logprobs])Log-probabilities are negative. Zero means certainty; −0.02 is about 98 per cent; −2.3 is about 10 per cent. Exponentiate to get back to a probability.
Four things you can actually do with them
1. Classification with a real score. Constrain the model to answer with one token (yes or no, or a single category label) and read the probabilities of the candidates at that position. Now you have a graded score instead of a word, so you can set a threshold, rank items for review, and route only the uncertain ones to a human. This is the single most useful application, and it converts a chat model into something you can tune.
2. Finding where a generation went wrong. Print the per-token log-probabilities of a long answer and look for the low points. A confidently generated sentence containing an invented citation will often show a sharp dip exactly at the fabricated name: the model had many plausible options and low probability on each. It is not a reliable detector on its own, but as a triage signal for review it earns its cost.
3. Scoring candidates you already have. You can ask for the log-probability of a given text rather than generating one, which lets you rank several rewrites, pick between two translations, or measure whether one phrasing is more natural under the model than another.
4. Perplexity. The exponential of the average negative log-probability. It is the standard measure of how surprised a model is by text, and you will meet it again in module five as the training objective’s direct readout.
The calibration problem, stated honestly
Now the caveat, which is important enough that ignoring it produces bad systems.
A base model (pretrained only) tends to be reasonably well calibrated. When it says 70 per cent, the answer is right about 70 per cent of the time, because that is precisely what its training objective rewarded.
Preference training damages this. The published evidence is clear on the direction: models tuned to be helpful and agreeable become overconfident, pushing probability mass toward whichever answer reads as decisive. Some of the calibration can be recovered by rescaling, and some cannot.
So: log-probabilities are good for ranking and unreliable as absolute confidence. “Item A scored higher than item B” is usable. “The model is 91 per cent sure” is not, unless you have measured the calibration on your own data, which means bucketing your predictions by claimed confidence and checking the actual accuracy in each bucket. That is an afternoon of work and it is the only way to earn the right to use the number as a probability.
Two practical traps
Tokenisation interferes. If your category labels tokenise into different numbers of tokens (yes is one token, maybe not is three) the comparison is unfair, because you are comparing a single probability against a product of three. Choose single-token labels, or normalise by length.
Not every provider exposes them. Some reasoning-oriented endpoints withhold log-probabilities entirely. If a confidence signal is load-bearing in your design, confirm availability before you build on it, and keep an open-weights fallback where you always have access.
Why this belongs in a mechanics course
Everything else about confidence is inference from behaviour. This is the one place where you can read a number that the model actually computed. Knowing it exists, knowing what it is good for, and knowing exactly where it stops being trustworthy is the difference between a system that routes uncertain cases sensibly and one that trusts a sentence saying “I am confident”.
Every lesson here is open. Your progress is recorded once you pass the AI, Actually Explained exam.
Check your understanding
A team uses a model’s stated “I am 95% confident” text as a threshold for auto-approving claims, and finds the accuracy at that level is nearer 70 per cent. What would fix the signal?
Pick the one you would defend. Your answer stays private.
Stuck on something?Ask Anjali, your AI tutor
