Skip to the shortcut learning demo

Medical AI lab · Shortcut learning ·

Shortcut learning: interactive demo

Shortcut learning is when a model predicts the diagnosis from something that merely accompanies it in the training data, such as a hospital tag or the type of machine, instead of from the disease. In this demo the tag goes with the diagnosis in 90% of training images: the model scores an AUC of 0.94 at the same hospitals and 0.64 at a new hospital where the tag is unrelated to disease, with 70% of its weight on the tag. A model trained without the tag scores 0.77 in both places.

In one line: AUC 0.94 at the training hospitals and 0.64 at a new hospital, with 70% of the model’s weight on a tag in the corner; a model that never saw the tag scores 0.77.

SYNTHETIC DATA

These demos are illustrative. Every signal, image, patient and note is synthetic and fictional, generated and scored in your browser, and every number shown is computed from that synthetic data. They show general principles, not the performance of any real model, product or project, and none of them is a medical device.

Nothing is uploaded. No patient data is used.

12

Medical imaging AI / shortcut learning

It learned the hospital, not the disease.

What this shows: when something unrelated to the disease, such as a hospital tag in the corner of the image, goes with the diagnosis in the training data, a model can learn the tag. It tests well where the tag still goes with the disease and fails where it does not.

Change the training data

At 50% the tag says nothing about the diagnosis. At 90%, nine in ten diseased images carry it and nine in ten healthy images do not, as when most sick patients are imaged on one portable machine. At the new hospital the tag is unrelated to disease.

What the model relies on

3,000 synthetic images per set
Where the model’s weight is
The same model, tested in two places

Red glow: share of the model’s weightBlue: same hospitals as trainingAmber: new hospitalWhite: a model trained without the tag

AUC, same hospitals—
AUC, new hospital—
Weight on the tag—
AUC without the tag—

Synthetic data · illustrative · not a medical device

Where this matters

Imaging and signal models trained on data where acquisition differs by diagnosis: portable versus fixed machines, different sites for sicker patients, burned-in text, markers, tubes or rulers. Test on sites where those links are broken, and check what the model responds to.

What this experiment models

Each synthetic image is reduced to two inputs: a disease signal, a number that is higher on average in diseased cases by the chosen strength, and a tag that is present or absent. Half the images are diseased. In the training set and the same-hospital test set the tag is present in the chosen share of diseased images and absent in the same share of healthy ones; in the new-hospital test set it is present in half of each. The model is a logistic regression on the two inputs. Weight on the tag is the tag’s share of the two standardised weights. The schematic scan is an illustration of that share and is not itself classified.

The principle

How it works

Each synthetic image carries two things a model could use. One is a disease signal, which is real but weak: on its own it supports an AUC of 0.77. The other is a tag in the corner of the image that says nothing about the patient but, in the training hospitals, appears mostly on diseased cases. That happens in real data when sicker patients are imaged on a portable machine, at a different site or with different markers, tubes or burned-in text.

The model is free to use both, and the tag is the easier one. With the tag going with the diagnosis 90% of the time, most of the model’s weight lands on it. Tested on new patients from the same hospitals, the model looks better than the disease signal alone could make it, because the shortcut still works there. At a new hospital the tag appears on healthy and diseased patients alike, and the model’s reliance on it now adds errors.

An internal test set cannot reveal this, because it shares the shortcut. What reveals it is a test where the link is broken: another site, another machine, or the same images with the tag removed. Checking what the model responds to, and controlling how cases and controls are acquired, are the other defences. See medical imaging AI.

Worked example

A model that tested well at the hospitals it was trained in

Picture a team that collects chest images from two hospitals to train a detector. Most of the diseased cases come from an intensive-care unit, where patients are imaged in bed on a portable machine that stamps a tag in the corner. Most healthy cases come from an outpatient clinic with a fixed machine and no tag. The team splits the images at random into training and test sets.

The demo’s default settings reproduce that: the tag goes with the diagnosis 90% of the time and the disease signal is 1.0. AUC, same hospitals reads 0.94. That is better than the disease signal can support on its own: AUC without the tag reads 0.77. The extra performance comes from the tag, and Weight on the tag reads 70%.

Now the model is installed in a hospital where every patient is imaged on the same machine, so the tag has nothing to do with disease. AUC, new hospital reads 0.64. That is not only lower than the 0.94 from the internal test. It is lower than the 0.77 of a model that never saw the tag, because the model keeps reacting to a tag that now misleads it.

Move the first slider to 50%, where the tag is unrelated to the diagnosis in training as well. Weight on the tag falls to 3% and the two AUCs are 0.76 and 0.77. Move it to 98% and the same-hospital AUC is 0.99 with 82% of the weight on the tag, while the new-hospital AUC stays at 0.64. The more convenient the shortcut, the better the internal result looks and the worse the model is.

The correct practice is to look for shortcuts before trusting a result. Compare how cases and controls were acquired: site, machine, view, markers, text and time period. Test on data where those links are broken, ideally from another site. Check what the model responds to, for example by masking the corners or the text and scoring again. Where a shortcut is found, remove it from the images or balance the acquisition, then validate again.

Checklist

What to check in your own project

  • Do cases and controls come from the same sites, machines, views and time periods?
  • Do the images contain tags, text, markers, tubes or devices that go with the diagnosis?
  • Was the model tested on a site where those links do not hold?
  • Does performance survive masking the image borders, corners and burned-in text?
  • Do attribution maps point at anatomy, or at the edges of the image?
  • Is the internal result better than is plausible for the task?

Related: our medical imaging AI service, the wiki page on medical AI validation, and the demos on scanner shift and patient-level data leakage.

FAQ

Common questions

What is shortcut learning in medical AI?

It is when a model predicts the label from a feature that accompanies the diagnosis in the training data without being part of the disease, such as a hospital tag, a type of machine or a chest drain. The model scores well wherever that link holds and fails where it does not. In this demo the AUC is 0.94 at the training hospitals and 0.64 at a new one.

Why does my medical imaging model work in testing but fail at another hospital?

One common reason is that the test set came from the same hospitals as the training set and shares their shortcuts. If sicker patients were imaged differently, the model may have learned the difference in acquisition. In the demo a tag that goes with the diagnosis 90% of the time attracts 70% of the model’s weight, and the AUC falls by 0.30 at a hospital where the tag is uninformative.

How do I detect that a model is using a spurious feature?

Test it where the feature no longer goes with the diagnosis: another site, or the same images with the feature masked. Compare the result with the internal test. Attribution maps that highlight corners, borders or text instead of anatomy are a further sign, as is an internal result that looks too good for the task.

Can a shortcut make a model worse than a model without it?

Yes. In the demo the model that learned the tag scores 0.64 at a new hospital, while a model trained without the tag scores 0.77 there. The shortcut does not just stop helping: the weight placed on it turns into errors when the tag appears on healthy patients.

How do I prevent shortcut learning?

Control the data before training: acquire cases and controls in the same way where possible, or balance and match them by site and machine. Remove burned-in text, tags and borders from the images. Then validate externally. No training method guarantees that a model ignores a shortcut that is present in the data.

Medical AI lab

More demos

01 / Heart rate from ECGHeart rate from a noisy ECG – interactive demoMissed and false beats behind a correct average02 / Patient leakagePatient-level data leakage – interactive demoRecord-level vs patient-level train/test splits03 / Calibration & thresholdsCalibration and decision thresholds – interactive demoCalibration plot, decision curve and net benefit04 / Scanner shiftScanner shift in medical imaging – interactive demoSegmentation tuned on one scanner, tested on another05 / Dice vs clinical errorDice score vs clinical error – interactive demoDice, HD95 and lesions detected06 / Note de-identificationDe-identifying a clinical note – interactive demoEnglish, Hebrew and mixed notes vs a rule-based detector07 / Nodule volume 3DNodule volume and CT slice thickness – 3D interactive demoThe same nodule, measured on thin and thick slices08 / Sample sizeSample size for validating a clinical AI model – interactive demoHow wide the interval is around a measured sensitivity09 / SubgroupsHidden subgroup failure in clinical AI – interactive demoA good overall score next to a weak subgroup10 / Slice-by-slice 3DSlice-by-slice segmentation of a 3D lesion – 3D interactive demoA high per-slice Dice and a lesion reported in pieces11 / Predictive value 3DPositive predictive value and prevalence – 3D interactive demoWhat a positive result means when the condition is rare13 / DriftModel drift and performance monitoring – interactive demoHow late a monitoring rule notices a slow decline14 / Alert burdenAlert burden of a clinical early-warning model – interactive demoA threshold counted in alerts per nurse per shift

MLAIA DATA SCIENCE

Tell us what
you’re working on.

Share the problem, the data you have and what success would look like. We’ll discuss a practical next step.

Please don’t include confidential datasets, credentials or patient information.

yochai@mlaia.com
WhatsApp: +972 52 484 6282

Your inquiry is handled under our Privacy Policy.