Neural networks
Output Heads: Connecting a Network to a Task
Design neural output heads for regression, binary classification, multiclass, multilabel, ranking, and structured tasks without confusing logits with decisions.
By the end you can
- Match common task types to appropriate output shapes and transformations
- Distinguish logits, probabilities, predictions, and product decisions
- Explain the difference between multiclass and multilabel outputs
- Recognize when constraints or uncertainty require more than one scalar prediction
The head is an interface contract
A backbone produces a representation, and the output head converts that representation into values aligned with the task and loss.
Its shape and its semantics both must be explicit, because a single length-five vector could equally represent five class logits, five independent labels, five regression targets, or parameters of a distribution. Nothing in the tensor records which of those five things it is. That fact lives only in the loss, the target encoding, and the code that reads the output downstream.
A head can be asked to say much more than one number. One regression head emits an observation-noise term alongside the prediction. The loss then divides each squared error by a predicted variance, and pays a log-variance penalty for the privilege. Kendall and Gal, in 2017, called that “learned attenuation”: the model can declare a pixel intrinsically ambiguous and be charged less for missing it. They report that this “improve[s] model performance by 1 − 3% over non-Bayesian baselines”. They are equally clear about what the extra number does not cover. “Out-of-data examples, which can be identified with epistemic uncertainty, cannot be identified with aleatoric uncertainty alone.” The head can predict its own noise. It cannot predict what it has never seen.
Tensor shape alone never defines the meaning of a model output.
Visual
Common heads and what they emit
The final transformation should reflect relationships among targets.
Scalar regression emits one unrestricted or constrained numeric value. Binary classification emits one logit, often transformed with sigmoid for interpretation. Multiclass classification emits one logit per mutually exclusive class, often normalized with softmax. Multilabel classification emits one independent logit per label, because several labels may be true at once. A distributional output emits several values that parameterize uncertainty, mixtures, intervals, or quantiles.
The list is not really five layer types. It is five different claims about how the coordinates of one output vector relate to each other. Do they compete? Are they independent? Do they name an answer at all, or only describe a spread? The sections below take the two claims that are easiest to get wrong: exclusivity, and the assumption that a number between 0 and 1 is a probability.
Scalar regression
One unrestricted or constrained numeric value.
Binary classification
One logit, often transformed with sigmoid for interpretation.
Multiclass classification
One logit per mutually exclusive class, often normalized with softmax.
Multilabel classification
One independent logit per label because several labels may be true.
Distributional output
Several values parameterize uncertainty, mixtures, intervals, or quantiles.
Comparison
Multiclass and multilabel are different probability structures
Both can produce a vector. The relationship among the coordinates is what changes the head and the loss.
A softmax head asserts that exactly one coordinate is correct. The field's most-used benchmark does not honour that assertion. Tsipras and colleagues measured it in 2020: “While each image is associated with a single label, we find that more than one fifth of ImageNet images contain objects from multiple classes.” On exactly those images, top-1 accuracy “drops by more than 10% across all models”. And for 650 of 2,156 multi-object images, the ImageNet label is not the main object a human annotator would name. A second group re-annotated the same validation set that year and put the figure at approximately 29% of images — images that either contain multiple objects or fall in a category matching multiple synonym labels. Their re-annotation assigned 57,553 labels to 46,837 images and discarded 3,163 images that received none. Two independent groups, a fifth to a third of the data. The exclusivity is a property of the head, not of the pictures.
Where co-occurrence is the point, the head is built for it. CheXpert, published in 2019, is 224,316 chest radiographs of 65,240 patients labelled for 14 co-occurring observations. The model emits a probability per observation rather than one normalized vector. A patient may have cardiomegaly and a pleural effusion at the same time, and no amount of softmax temperature will let a competing head say so. Because each coordinate is its own decision, each is judged against its own human operating point: three radiologists, individually, on a 500-study test set. Irvin and colleagues report where the model lands. “On Cardiomegaly, Edema, and Pleural Effusion, the model ROC and PR curves lie above all 3 radiologist operating points.” The MIMIC-CXR team, describing CheXpert for their own readers, records the same dataset independently: “A total of 224,316 chest radiographs for 65,240 patients admitted to Stanford Hospital were released with the CheXpert labeler … released with 14 labels”. They adopt that 14-label vocabulary for their own data too.
So the contrast is concrete. Multiclass: classes compete, softmax couples the probabilities, and the target is usually one class index. One document language is a fair example. Multilabel: the labels are not one exclusive choice, and sigmoid is applied per coordinate. Thresholds may differ from label to label, as they must when each of 14 observations has its own radiologist operating point. An image containing a car and a person is the ordinary case, not the awkward one.
Multiclass
Exactly one category is intended for each example.
- Classes compete
- Softmax couples probabilities
- Targets often use one class index
- Example: one document language
Multilabel
Several labels may be independently present.
- Labels do not form one exclusive choice
- Sigmoid is applied per coordinate
- Thresholds may differ by label
- Example: image contains car and person
Key idea
Logits are scores before a probability transformation
A logit can be any real number. Softmax or sigmoid maps logits into bounded values, but those values are not necessarily calibrated probabilities.
Give the loss the logits directly. Numerical stability is usually best that way, and this is not folklore: both dominant frameworks wrote the reason into their own reference material. PyTorch folds the sigmoid into the loss and says why — “This loss combines a `Sigmoid` layer and the `BCELoss` in one single class. This version is more numerically stable than using a plain `Sigmoid` followed by a `BCELoss` as, by combining the operations into one layer, we take advantage of the log-sum-exp trick for numerical stability.” TensorFlow prints the algebra outright in the documentation for tf.nn.sigmoid_cross_entropy_with_logits: “Hence, to ensure stability and avoid overflow, the implementation uses this equivalent formulation max(x, 0) - x * z + log(1 + exp(-abs(x)))”. The multiclass case says the same thing in the type signature. PyTorch's CrossEntropyLoss states that its input “is expected to contain the unnormalized logits for each class (which do not need to be positive or sum to 1, in general)”. Handing such a loss a sigmoid or softmax output is not a stylistic choice. It re-derives, less stably, code that two framework teams already wrote.
Then there is the bounded number itself. Accuracy went up and calibration went down. Guo and colleagues opened with the finding in 2017: “While neural networks today are undoubtedly more accurate than they were a decade ago, we discover with great surprise that modern neural networks are no longer well-calibrated.” The measurement behind that sentence: 15-bin expected calibration error of 16.53% for a 110-layer ResNet on CIFAR-100, against 4.85% for a 5-layer LeNet on the same data. The more accurate model was the more misleading one. Temperature scaling — a single parameter — cut the ResNet's ECE to 1.26%, and on ImageNet took a ResNet-152 from 5.48% to 1.86%. Matrix scaling made matters worse, at 25.49%. Nor is the trend a law of scale. Minderer and colleagues re-ran the comparison on newer architectures in 2021 and found MLP-Mixer, ViT and BiT among the best calibrated. What was measured in 2017 was a generation of models, not a property of size.
Even the standard repair is less reliable than its own report suggests. Kumar and colleagues found in 2019 that “popular recalibration methods like Platt scaling and temperature scaling are (i) less calibrated than reported, and (ii) current techniques cannot estimate how miscalibrated they are”. The reason is measurement. Calibration error for a method that outputs a continuous range of values is estimated from binned outputs, and that estimate is biased downward. Histogram binning is measurable but sample-hungry: it “requires O(B/ε²) samples, compared to O(1/ε²) for scaling methods”. So the authors combine the two into a scaling-binning calibrator. A number between 0 and 1 is a claim. The audit of that claim has an error bar of its own.
Probability-shaped output is not proof of probability calibration.
Steps
Prediction and decision should remain separate
Product logic often belongs after the network head. The network emits scores — logits, values, or distribution parameters. A transformation gives them range: sigmoid, softmax, decoding, or constraint functions. A calibration check tests whether that range means anything on the data the system will actually see. A policy then applies thresholds, costs, abstention, ranking, or human review. Monitoring measures the consequences of those decisions rather than only the raw model metric.
A regulator has written that separation into law. On 11 April 2018 the FDA granted De Novo request DEN180001 for IDx-DR, the first autonomous AI diagnostic authorised in the United States. The order created a new device type, “retinal diagnostic software device”, and attached special controls to it. One is a labelling requirement covering “The type of imaging data used, what the device outputs to the user, and whether the output is qualitative or quantitative.” That is the shape-and-semantics contract of the first section, made a condition of marketing. A second control requires clinical testing of sensitivity, specificity, PPV and NPV “across the range of available device outcomes” — the whole curve, not one convenient operating point. The pivotal trial behind the authorisation enrolled 900 subjects and cleared its pre-specified superiority endpoints: sensitivity 87.2% (95% CI 81.8-91.2%), specificity 90.7% (95% CI 88.3-92.7%), imageability 96.1% (95% CI 94.6-97.3%).
And here is what happens when a threshold travels without that check. Epic's proprietary sepsis model was validated externally in 2021 by Wong and colleagues, on 38,455 hospitalisations of 27,697 patients at Michigan Medicine between 6 December 2018 and 20 October 2019. At the vendor-suggested alert threshold of 6, the model gave sensitivity 33%, specificity 83% and PPV 12%, with a hospitalisation-level area under the ROC curve of 0.63 (95% CI 0.62-0.64). It missed 1,709 of 2,552 sepsis patients while “generating alerts for an ESM score of 6 or higher for 6971 of all 38 455 hospitalized patients (18%)”. The abstract concludes that “the ESM has poor discrimination and calibration in predicting the onset of sepsis”. Move the same head and the same number 6 to two county emergency departments and the behaviour changes again. A separate group measured sensitivity 14.7% and specificity 95.3% at that threshold in 2024, noting that “Alerting occurred at an Epic recommended model threshold of 6.” Thirty-three percent sensitivity in one hospital system, 14.7% in another. Identical score, identical cut-off. The head was constant; the decision it produced was not. That is precisely why steps three to five belong outside it.
1. Emit scores
The network returns logits, values, or distribution parameters.
2. Transform if needed
Apply sigmoid, softmax, decoding, or constraint functions.
3. Calibrate or validate
Check whether score interpretation holds on relevant data.
4. Apply policy
Use thresholds, costs, abstention, ranking, or human review.
5. Monitor outcomes
Measure decision consequences rather than only raw model metrics.
Example
Heads that encode more than a point estimate
Some tasks need structure or uncertainty that one scalar cannot express.
AlphaFold 2 shipped such a head into production and then published the evidence for it. The architecture description is one sentence in Nature: “Predictions of side-chain χ angles as well as the final, per-residue accuracy of the structure (pLDDT) are computed with small per-residue networks on the final activations at the end of the network.” The model does not merely emit a structure. It emits a confidence for every residue of it. That extra number is checked rather than asserted — the 2021 paper reports a least-squares fit of lDDT-Cα = 0.997 × pLDDT − 1.17, with Pearson's r = 0.76 over n = 10,795 protein chains. It also ships with an operating rule attached. EMBL-EBI, which co-operates the AlphaFold Protein Structure Database, tells users that “The predicted local distance difference test (pLDDT) is a per-residue measure of local confidence. It is scaled from 0 to 100”, and publishes the four bands to read it by: very high above 90, confident 90-70, low 70-50, very low below 50. A distributional head, a calibration check against true accuracy, and a decision policy, in one worked example.
- Heteroscedastic regression: emit a location and scale that may vary by input, as Kendall and Gal's head does when it predicts its own observation noise.
- Quantile regression: emit selected conditional quantiles for asymmetric intervals.
- Mixture density: emit component weights and parameters for multimodal outcomes.
- Bounding-box prediction: emit coordinates plus class or objectness scores.
- Sequence generation: emit one vocabulary-logit vector at each decoding position.
- Ordinal prediction: encode ordered categories without treating gaps as equal numeric distances.
Analogy
An instrument panel before the operating rule
A cockpit panel reports altitude, speed, warnings, and confidence ranges. The panel supplies measurements; procedures determine what action follows.
Unlike cockpit instruments, neural outputs are learned statistical quantities whose meaning can shift with data. Physical sensors usually have stronger calibration and units. The four pLDDT bands EMBL-EBI publishes — very high above 90, confident 90-70, low 70-50, very low below 50 — are the procedure written beside the instrument, and they are authored separately from the network that emits the number. Epic's threshold of 6 is the same kind of object. The difference between 33% sensitivity at Michigan Medicine and 14.7% in two county emergency departments is what it costs to treat such a rule as though it travelled with the instrument.
The head reports evidence; the surrounding policy turns evidence into action.
Five output-head checks before training
Confirm target exclusivity, units, missing-target handling, feasible ranges, and the exact tensor shape, then test the head and loss together on a tiny batch with known targets.
Each of these has a documented failure behind it. Target exclusivity is the check ImageNet fails: more than one fifth of its images carry objects from several classes, while the head is built to name exactly one. Feasible ranges and declared semantics are the check the FDA turned into a marketing condition for IDx-DR, requiring the labelling to state what the device outputs and whether that output is qualitative or quantitative. Whether the loss is fed logits or probabilities is settled by reading the docstring. PyTorch's CrossEntropyLoss expects unnormalized logits, and passing it softmax output duplicates a transformation the loss already performs.
Also inspect whether constraints should be hard-coded or merely encouraged. The difference is not cosmetic. A soft penalty may still permit impossible outputs at inference.
Key takeaways
- An output head maps a learned representation into values whose shape and semantics match the task; the tensor alone records neither, so the contract lives in the loss, the targets, and the code downstream.
- Logits, transformed probabilities, decoded predictions, and product decisions are separate stages — PyTorch's BCEWithLogitsLoss and TensorFlow's sigmoid_cross_entropy_with_logits both fold the sigmoid into the loss rather than let the first two be confused.
- Multiclass outputs model competition while multilabel outputs permit several simultaneous labels: more than one fifth of ImageNet images break the exclusivity its softmax assumes, and CheXpert's 14 observations are scored one probability at a time against per-label human operating points.
- Probability-shaped outputs require calibration evidence before interpretation — a 110-layer ResNet reached 16.53% expected calibration error on CIFAR-100 where a 5-layer LeNet reached 4.85%, and temperature scaling brought it to 1.26%.
- Distributional heads can represent uncertainty, quantiles, mixtures, or structured outputs beyond one point estimate; AlphaFold's pLDDT tracks true accuracy with Pearson's r = 0.76 over n = 10,795 protein chains and is read through four published bands.
- The head, loss, target encoding, and decision policy must be designed as one coherent contract: Epic's sepsis score at the vendor threshold of 6 gave 33% sensitivity at Michigan Medicine and 14.7% at two county emergency departments.