Medical classifiers are usually trained to be accurate on average and then have their decision threshold adjusted afterwards. That habit fails in two known ways when the disease is rare. First, a model that sees 95% healthy cases can reach high accuracy while missing most sick patients. Second, when hospitals contribute different proportions of sick patients, the model learns which hospital an image came from, for example from a "PORTABLE" text stamp, and uses that as a stand-in for disease. This proposal treats the clinician's actual requirement as something the training procedure must satisfy. A typical requirement reads "catch at least 98% of pneumonia cases at every contributing hospital, and keep false alarms as low as possible." We compile it into a set of constraints enforced within each hospital during training, so the model gains nothing from recognizing the hospital. The clinician writes the requirement in a visual interface and the engineer writes the same object in code. Training reports back, per hospital, whether each requirement is met and how many positive cases stand behind that claim.
The opportunity comes from putting two findings side by side. Demonstrating The Risk of Imbalanced Datasets in Chest X-ray Image-based Diagnostics by Prototypical Relevance Propagation shows that differing disease prevalence across sites turns a pneumonia detector into a "hospital detector." Constrained Optimization to Train Neural Networks on Critical and Under-Represented Classes shows that forcing every critical positive to outrank the negatives during training lowers false alarms at the very high sensitivities clinicians require. That paper enforces its ranking constraint over the whole pooled dataset, and a pooled ranking constraint can be satisfied by learning the hospital. Our proposal restricts the comparison to pairs from the same hospital, which removes the payoff for learning it.
Core Claim
We claim three things. First, rank constraints restricted to each stratum (each hospital, or each scanner type) reduce shortcut use under inter-site imbalance. Second, they give lower false-positive rates at a clinician-specified sensitivity than two alternatives: a model trained with an imbalance-aware loss and then thresholded per site, and the same constraint applied to the pooled data. Third, the constraint specification is only trustworthy if it is tied to how many minority cases each stratum contains.
The software contribution follows from the second and third claims. The specification is a single object shared by a graphical interface and a programming interface, so a requirement a clinician approves is exactly what the optimizer enforces. Each requirement carries a statistical check of whether the available positives can verify it. We treat the software as a means of making the requirement precise and checkable, not as an end in itself.
Concretely, let $s$ index strata. Let $P_s$ and $N_s$ be the critical-class positives and negatives within stratum $s$. Let $f$ be the model's score and $\delta$ a margin. The constraint is
$$ f(x_i) \ge f(x_j) + \delta \quad \text{for all } s,\ i \in P_s,\ j \in N_s , $$
which we relax to a per-positive hinge and enforce with the augmented Lagrangian method, as in the constrained-optimization paper. The augmented Lagrangian method keeps one penalty weight per positive and raises it while that positive keeps losing its comparisons. The only change from that paper is that $j$ ranges over negatives from the same stratum as $i$. A constant per-site offset in $f$, which is exactly what a hospital marker supplies, therefore cannot help satisfy any constraint.
Research Program
The first component is the constrained trainer. We reimplement the method of Constrained Optimization to Train Neural Networks on Critical and Under-Represented Classes with stratum-aware mini-batch sampling, so that every batch contains positives and negatives from the same strata. We add the hybrid cross-entropy plus soft-F1 objective of Imbalance-aware loss functions improve medical image classification as the base loss. That paper supplies the base loss and also constrains the design: it reports that metric losses used alone can make whole classes disappear, so we never drop the cross-entropy term.
The second component is the requirement specification. It is a small declarative record containing the critical class, the target sensitivity, the strata over which the target must hold, and the margin. The same record is editable in a browser panel and constructible in Python. The panel is built on the reactive shared-state design of Symphony: Composing Interactive Interfaces for Machine Learning, which composes notebook widgets and exported dashboards over one live state but only displays model behavior and never writes decisions back into training. We add that write-back path. Following Symphony's stated scalability limit, the browser receives only per-stratum summaries and sampled thumbnails, never the full image set.
For each stratum, the report shows three things: the achieved sensitivity, a one-sided exact binomial lower bound on that sensitivity given the number of positives, and the false-positive rate. If a requirement of 98% sensitivity rests on 30 positives, the lower bound falls well below 98% and the panel flags the requirement as unverifiable. The clinician can then pool strata or relax the target. This addresses the problem, noted for the augmented Lagrangian method and for AdaFocal: Calibration-aware Adaptive Focal Loss, that these methods rely on clean validation data that rare conditions rarely provide.
The role split borrows the idea from Development of an Open-source and Lightweight Sensor Recording Software System for Conducting Biomedical Research: Technical Report, which separates engineer-facing command-line setup from a role-governed clinical dashboard. That system does no learning; here the clinician's role governs the specification rather than data capture.
The third component is the shortcut measurement. We use the ProtoPNet-plus-relevance-propagation analysis from the chest X-ray study. For each model, we measure the fraction of attribution mass that falls on text-marker regions and on tube or drain regions rather than on lung fields. We also run two counterfactual tests: one swaps the markers between sites, and one reverses site prevalence at test time.
Baselines
The naive reference point is a network trained with plain cross-entropy on the merged multi-source data, with one global threshold chosen on validation data to reach the target sensitivity. The PRP study reports that even its best model, trained on perfectly balanced data, reached only 63.89% accuracy on a balanced pneumonia test set. That tells us how low the floor sits on this benchmark.
The strongest existing imbalance method on this question is the pooled augmented-Lagrangian constraint of Constrained Optimization to Train Neural Networks on Critical and Under-Represented Classes. It is the only method in the file that directly targets false alarms at a fixed high sensitivity. It reports reducing the false-positive rate at 95% sensitivity from 45.0% to 34.0%, and at 98% sensitivity from 56.0% to 52.0%, on binary CIFAR-10 at 1:100 imbalance. On its in-house prostate MRI cohort the file gives only a qualitative claim of "significantly lower FPRs." We found no reported result on Lacuna for this method on chest radiographs or on multi-site data.
The strongest loss-level competitor is cross-entropy plus soft F1 with oversampling from Imbalance-aware loss functions improve medical image classification. It reports up to 12.7% relative improvement in balanced accuracy on glioma MRI and up to +51.3% class-wise F1 for early glaucoma. We run it with per-site post-hoc thresholds, which is the most favorable way to use it here.
The key ablation keeps everything identical except the comparison set, pooled pairs versus same-stratum pairs. It isolates whether the stratification itself does the work.
All methods share the same backbone and data splits. Each gets the same number of hyperparameter trials, chosen by random search over its own knobs; the augmented Lagrangian method has four interacting ones. All use the same validation data to set thresholds. Our method beats the baselines if it meets three conditions:
- it lowers the worst-site false-positive rate at the required sensitivity by more than the seed-to-seed spread;
- it raises accuracy on the balanced, prevalence-reversed test set above the pooled constraint;
- it moves attribution mass away from marker regions.
It should achieve this while matching or beating average-site false-positive rates.
Why not just…?
Why not just set a separate threshold for each hospital after training? This is the most serious threat. If the model's ranking within each hospital is already good, per-site thresholds recover everything, and our training-time change is unnecessary. The PRP finding suggests otherwise: a model that spends capacity on hospital markers and chest tubes should rank poorly within a hospital. That is an empirical question, and the ablation comparing per-site thresholding of the cross-entropy and soft-F1 models against same-stratum constrained training settles it. If per-site thresholds match our method, we will report that the contribution reduces to the specification-and-verification interface.
Why not just mask the corner text before training? Masking removes one known shortcut. It leaves the chest drains that the PRP study found even in balanced cohorts, and it requires knowing each artifact in advance. We include a masked-input cross-entropy baseline. The drain-region attribution measurement shows whether masking alone is enough.
Why not just rebalance each site to equal prevalence by oversampling? Equalizing prevalence per site does remove the site-prevalence signal in principle. However, the soft-loss paper reports that oversampling leads models to memorize the few positives, and the PRP study found shortcuts persisting under balance. We run per-site oversampling as a baseline, both with and without our constraint.
Why not skip the interface and let engineers write the specification in a config file? For the ML claim, a config file would do. The interface earns its place only if clinicians write different requirements than engineers would, and only if the verifiability check changes their decisions. We test this directly in a small study, described in the next section.
Proposed Experiments
Main benchmark. The main benchmark is the NIH ChestX-ray14 plus CheXpert multi-source pneumonia setup from the PRP study, with its controlled 90/10 and 60/40 source-label splits. We add a prevalence-reversed test split in which each site's marker is paired with the opposite prevalence. We report four measures, each over five seeds:
- per-site and worst-site false-positive rate at 95% and 98% sensitivity;
- balanced accuracy;
- attribution mass on marker and tube regions;
- the Average Drop and Average Increase faithfulness scores used in that study.
External check. A second check uses the 500-image expert-consensus test set of CheXpert: A Large Chest Radiograph Dataset with Uncertainty Labels and Expert Comparison. There we confirm that stratified training does not cost discrimination on the competition pathologies, where that paper reports an AUC of 0.97 for pleural effusion and 0.94 for edema.
Three-class generalization. To test whether the method extends beyond binary tasks, we run the glioma MRI task. Glioblastoma makes up about 80% of cases, astrocytoma about 12%, and oligodendroglioma about 8%, with TCGA held out. We treat each minority subtype in turn as the critical class and use acquisition site as the stratum wherever the metadata allows. Glaucoma fundus staging, which has no site variable, serves as a control. There, stratified and pooled constraints coincide, so any difference points to an implementation artifact.
Verification-bound check. We subsample positives per site to 20, 50, and 200. We then test whether the flagged requirements are exactly those whose held-out sensitivity actually falls below target.
Specification study. Radiologists and ML engineers independently write requirements for the same chest X-ray task. One group uses the panel with the verification bound shown, and the other uses a config file without it. We record how often each group's requirements are met on held-out data and whether the bound changes the targets they choose.
References
- Demonstrating the Risk of Imbalanced Datasets in Chest X-Ray Image-Based Diagnostics by Prototypical Relevance Propagation
- Constrained Optimization to Train Neural Networks on Critical and Under-Represented Classes
- Imbalance-aware loss functions improve medical image classification
- Symphony: Composing Interactive Interfaces for Machine Learning
- AdaFocal: Calibration-aware Adaptive Focal Loss
- Development of an Open-source and Lightweight Sensor Recording Software System for Conducting Biomedical Research: Technical Report
- CheXpert: A Large Chest Radiograph Dataset with Uncertainty Labels and Expert Comparison