LIVE · Thursday 3 December

Custom Text Classifier API With Calibrated Confidence Scores: Check the ECE on Your Own Hold-Out Set

Azure and Nyckel return a 0 to 1 confidence score but do not document it as calibrated, and raw LLM logprobs run overconfident. A labelled hold-out set, a reliability diagram and ECE settle it for any API.

By Nick10 min read

To get calibrated confidence scores from a custom text classifier API, pick an API that returns a numeric probability per class, then measure and correct it on a labelled hold-out set of your own. Microsoft's Azure custom text classification and Nyckel both return a confidence between 0 and 1, but neither vendor's documentation says that the score is calibrated. Raw LLM logprobs and the confidence that an LLM states in words are worse. In one 12-dataset study, both had an Expected Calibration Error (ECE) near 45% to 50% before correction and 5% to 8% after.

A score is calibrated when predictions at 0.8 are correct about 80% of the time

A classifier is calibrated when its confidence matches its accuracy. The scikit-learn documentation gives the standard example: among the predictions that receive a probability near 0.8, about 80% should turn out to be correct. The Ludwig project defines it the same way, as confidence scores that reflect empirical accuracy.

This matters as soon as a score drives an action. If an API returns 0.9 and you auto-approve everything above 0.9, you are assuming that those predictions fail about one time in ten. If the real failure rate is one in three, the threshold is wrong, and nothing in the response shows it.

Calibration is separate from accuracy. A model can be accurate and badly calibrated, and the reverse. Chuan Guo and colleagues showed in their ICML 2017 paper that modern neural networks are poorly calibrated, unlike the networks of a decade earlier. Their proposed fix, temperature scaling, changes the confidence without changing which class the model picks, so accuracy stays exactly the same.

Azure and Nyckel document a confidence score but not a calibrated probability

Microsoft's documentation for Azure custom text classification, updated in August 2026, describes the confidence score as "a decimal number between zero (0) and one (1)" that indicates how confident the system is. It adds that the score is directly affected by the data that you tagged, and that inputs similar to the training data should get higher scores. The page does not say that the score is calibrated.

Microsoft's advice is about thresholds instead. A higher threshold gives fewer false positives and more false negatives, which raises precision. Predictions below the threshold can be flagged for human review. Microsoft recommends testing the chosen threshold on the real data that the system will see in production.

Nyckel's pretrained text classifier returns a label with a confidence score. Its example response is short:

{
  "labelName": "Negative",
  "labelId": "label_...",
  "confidence": 0.92
}

Nyckel's classifier page does not say whether that 0.92 is calibrated. It recommends that customers measure accuracy on their own data.

A score between 0 and 1 is useful for ranking and thresholds even when it is not a probability. The word "confidence" in an API response names a number, but it does not guarantee how often that number is right.

Raw LLM logprobs and stated confidence are overconfident until they are corrected

Many teams now build classifiers on top of general LLMs instead of training a dedicated model. That route has two obvious sources of confidence, and both need correction.

The first source is the confidence that a model writes in its answer. Elena Merdjanovska, Omar Zaidan and Andreas Rücklé published a paper on this in the Findings of ACL 2026, in July. They found that Qwen3-32B used only eight distinct confidence values on the SST-2 sentiment set, and over half of its answers said exactly 95%. A score with eight possible values cannot separate an easy case from a hard one. The authors propose weighting the stated digits by their token probabilities, which gave a 2.3-point gain on their ranking metric at no extra inference cost.

The second source is token logprobs, the probability that the model gave to the label token that it produced. The GEPA project's guide to confidence scoring advises treating logprobs as "a confidence score rather than a true calibrated probability." It explains that constrained decoding, which forces the output into a fixed format, concentrates probability on the chosen token. In its example, GPT-4.1-mini with structured output tends to give 95% to 100% even when the prediction is wrong. OpenAI's own logprobs recipe makes a similar point: the confidence measures certainty, not correctness.

The clearest measurement of both sources comes from Nyckel. In an August 2024 study, Oscar Beijbom ran GPT-4o on 12 of Nyckel's production text datasets. Each dataset had 1,000 to 10,000 labelled samples and 2 to 10 classes. He compared stated confidence, logprob confidence and a trained logistic regression on BERT features. He then corrected each one with scikit-learn's CalibratedClassifierCV on a separate 20% calibration split.

Confidence source ECE before calibration ECE after calibration
GPT-4o logprobs almost 50% 5%
GPT-4o stated confidence around 45% 8%
Logistic regression on BERT features 11% 6%

The figures are averages across the 12 datasets. Nyckel published the per-dataset values only as charts. The study also found that the trained baseline was more accurate than either LLM method. Calibrated logistic regression came out slightly worse than raw, which Beijbom attributes to calibration and test sets of only a few hundred samples each.

Fine-tuning an LLM as a classifier is a third route. A Fireworks blog post from December 2025 fine-tuned Qwen3-4B with LoRA on the four-class AG News set and read class probabilities from the label-token logprobs. Fireworks reports that its calibration ratio converged toward 1.0 without extra correction. The post gives no ECE or Brier score, and it is the vendor's own work, so it supports testing the method rather than skipping the test.

Temperature scaling is the standard fix when the API returns a full probability vector

Temperature scaling divides a model's logits by a single number, T, before the softmax. A value above 1 spreads probability out and lowers overconfidence. Guo and colleagues fit T by minimizing negative log-likelihood on a hold-out validation set, and they found it "surprisingly effective" on most of the datasets that they tested.

It needs one condition: the API has to return a probability for every class, not only for the winning one. If it does, the log of each probability can stand in for a logit, and T can be fitted on your side. Ludwig builds this in with calibration: temperature_scaling in the decoder configuration of a category output, and scikit-learn's documentation describes a method="temperature" option for multi-class problems.

When an API returns only the top label and its score, as in Nyckel's example, temperature scaling has nothing to rescale. The alternative is to fit a mapping from the top score to the chance of being correct. scikit-learn offers two such mappings:

  • Sigmoid scaling fits a smooth S-shaped curve, and scikit-learn describes it as most effective for small samples.
  • Isotonic regression fits any increasing curve, and it performs as well as or better than sigmoid once there are more than about 1,000 samples, but it is more prone to overfitting below that.

Parsec's TOD returns a probability for every option and passes low-confidence turns to another model

Parsec, a small language model lab, sells TOD, which it calls a "universal decision model." TOD ranks a supplied list of allowed options and generates no free text. Its open model card describes a predict(state, options, question, images) call that returns one probability per option, summing to 1, which is the full vector that temperature scaling needs. Parsec's TOD page describes a confidence gate that lets TOD handle a turn when it is confident and passes the turn unchanged to the customer's existing LLM otherwise. Parsec lists TOD at $0.30 per 1,000 decisions, with parent-model costs billed separately, and it publishes no price for tuning custom decision models. TOD is built for assistants choosing actions rather than as a general text classifier, and its probabilities warrant the same hold-out check as any other vendor's.

The right setup depends on what the API returns and what a wrong answer costs

The decision comes down to three situations:

  • If you need a managed classifier and can label data, Azure custom text classification or Nyckel will return a usable score. Treat it as uncalibrated, fit a sigmoid or isotonic curve on 1,000 or more hold-out examples, and set thresholds on the corrected value.
  • If you are building on an LLM, use logprobs rather than stated confidence, constrain the output to one token per label, and recalibrate. Nyckel's study shows that the corrected logprob score can reach 5% ECE.
  • If the API returns a full probability vector, as fine-tuned LLM classifiers and option-ranking models do, fit a single temperature and keep the accuracy that you already have.

In every case, a wrong automatic decision costs more than a deferred one, so start with a conservative threshold. Raise the threshold until the measured accuracy above it meets your bar on the hold-out set, and send everything below it to a person or a larger model.

A 1,000-example hold-out set and a short Python function measure calibration for any API

The check is the same whatever the vendor. You need labelled examples that the model has not seen, drawn from the traffic that you expect in production. Run them through the API, record the top class and its confidence, and compare.

The following steps produce a reliability diagram and an ECE figure:

  1. Collect at least 1,000 labelled examples from production-like traffic, and keep them out of any training or fine-tuning data.
  2. Split them in half: one half to fit a calibrator, the other half to measure the result.
  3. Call the API on every example and store the predicted label, its confidence and, where available, the full probability vector.
  4. Compute ECE and the reliability table on the measurement half, before and after calibration.
  5. Plot accuracy against mean confidence for each bin. A calibrated model sits on the diagonal.

This function computes ECE with equal-width bins, following the definition in Guo and colleagues' paper:

import numpy as np

def ece_table(confidence, correct, n_bins=10):
    confidence = np.asarray(confidence, dtype=float)
    correct = np.asarray(correct, dtype=float)
    edges = np.linspace(0.0, 1.0, n_bins + 1)
    ece, rows = 0.0, []
    for lo, hi in zip(edges[:-1], edges[1:]):
        in_bin = (confidence > lo) & (confidence <= hi)
        if in_bin.any():
            acc, conf = correct[in_bin].mean(), confidence[in_bin].mean()
            ece += in_bin.mean() * abs(acc - conf)
            rows.append((round(lo, 2), round(hi, 2), int(in_bin.sum()), conf, acc))
    return ece, rows

Each row gives a bin's range, its count, its mean confidence and its accuracy. Plotting the last two columns gives the reliability diagram. Guo and colleagues point out that the diagram hides how many samples sit in each bin, so keep the count column next to it.

If the API returns a full probability vector, this fits a temperature on the calibration half:

import numpy as np
from scipy.optimize import minimize_scalar

def fit_temperature(probs, labels):
    logits = np.log(np.clip(probs, 1e-12, 1.0))
    def nll(t):
        z = logits / t
        z = z - z.max(axis=1, keepdims=True)
        logp = z - np.log(np.exp(z).sum(axis=1, keepdims=True))
        return -logp[np.arange(len(labels)), labels].mean()
    return minimize_scalar(nll, bounds=(0.05, 20.0), method="bounded").x

For a top-label-only API, fit sklearn.isotonic.IsotonicRegression or a one-feature logistic regression that maps the returned confidence to the 0 or 1 "was it correct" outcome.

The size of the hold-out set sets the precision of the answer. For a bin whose true accuracy is 90%, the standard error of the measured accuracy is about 3 points with 100 examples, 1.5 points with 400 and under 1 point with 1,000. When scores bunch near 1, as GEPA and Nyckel both report for raw logprobs, the lower bins hold far fewer examples than the total suggests. The scikit-learn function calibration_curve defaults to five bins, and its documentation warns that more bins need more data. Its strategy="quantile" option gives every bin the same number of samples, which helps when the scores bunch near 1.

Calibration has to be redone whenever the model or the data changes

A calibrator fitted on one model and one dataset applies to that pair only. Retraining or fine-tuning produces a new model, so the old temperature or curve no longer applies. Microsoft makes a related point about evaluation: scores from models trained on different random splits cannot be directly compared.

Shifts in the input data cause the same problem more slowly. Yaniv Ovadia and colleagues tested uncertainty methods under dataset shift at NeurIPS 2019 and concluded that "traditional post-hoc calibration does indeed fall short" once the data moves away from the calibration set. In practice, that means two habits:

  • Recalibrate after every retraining or fine-tuning run, on a fresh hold-out set from current traffic.
  • Re-run the ECE check on a monthly sample of newly labelled production cases, and recalibrate when the figure rises.

Some limits remain even after both habits are in place. Classes with few training examples tend to have the least reliable scores, and Microsoft notes that underrepresented classes also weaken the evaluation itself. Nyckel's study found that calibration can "collapse" scores to a near-constant value when accuracy does not vary with confidence, which leaves a calibrated but uninformative number. A calibrated score is also an average over many cases. It measures how often 0.9 is right across the hold-out set, not whether one particular high-stakes decision is right.

Sources

More in Products

All Products →