Shortcut Learning & Spurious Correlations
Texture bias, group robustness and models that are right for the wrong reasons.
A pneumonia detector learned to recognize which hospital took the X-ray; an image tagger missed cows standing on a beach; in a popular language-inference dataset, the word "nobody" in a hypothesis was a strong hint of contradiction. Each model was right for the wrong reason, and each looked excellent on its own test set. Shortcut learning is what training does by default when a simple cue predicts the label. This lesson shows why gradient descent prefers such cues, how to measure the damage group by group, why the fix that works needs strong regularization, and how far one can get without labels for the groups.
What you’ll learn
- Define shortcut learning and spurious correlations, and recognize them in images (backgrounds, texture) and in language (annotation artifacts, syntactic heuristics).
- Explain why training picks simple predictive features: extreme simplicity bias, the max-margin geometry of a spurious feature, and the geometric and statistical skews that defeat the max-margin argument.
- Measure worst-group accuracy, derive group DRO and its exponentiated-gradient algorithm, and explain why it needs strong regularization in overparameterized networks.
- Compare fixes that need fewer group labels (JTT, last-layer retraining, subsampling), and assess what invariance-based objectives such as IRM can promise.
Right for the wrong reasons
Geirhos et al. (2020) define shortcuts as decision rules that perform well on test data drawn like the training data but fail on out-of-distribution tests, revealing a mismatch between the intended solution and the learned one. The usual raw material is a spurious correlation: a feature that predicts the label in the training data without being part of what the label means. Shortcuts turn up wherever data are collected:
| Task | Shortcut | Evidence |
|---|---|---|
| Pneumonia from chest X-rays | Which hospital system took the scan | Networks identified the hospital system almost perfectly, could exploit its pneumonia rate, and often did worse on hospital systems not seen in training (Zech et al., 2018) |
| Animals in photos | The background | An off-the-shelf image tagger recognized cows in Alpine pastures but missed cows on a beach (Beery, Van Horn & Perona, 2018) |
| ImageNet objects | Texture instead of shape | On cue-conflict images an ImageNet ResNet-50 chose the texture's class in 77.9% of the answers that matched either cue; people chose the shape's in 95.9% (Geirhos et al., 2019) |
| Natural language inference | Words in the hypothesis alone | A classifier that never sees the premise is right on 67.0% of SNLI, against 34.3% for the majority class (Gururangan et al., 2018) |
| Natural language inference | Word overlap between premise and hypothesis | Models trained on MultiNLI, BERT included, scored below 10% in most of HANS's non-entailment cases, where chance is 50% (McCoy, Pavlick & Linzen, 2019) |
Texture bias. Geirhos et al. (2019) made cue-conflict images by style transfer, such as a cat's shape covered in elephant skin. ImageNet-trained networks mostly went by texture (texture bias): among the answers that matched either cue, ResNet-50 chose the shape's class in only 22.1% and VGG-16 in 17.2%, their shape bias. Trained on Stylized-ImageNet, where style transfer gives every image the texture of a random painting so that local texture no longer predicts the class, the same ResNet-50 reached a shape bias of 81% and became more robust to many image distortions. Hermann, Chen and Kornblith (2020) traced much of the bias to the data rather than the architecture: trained on images whose shape and texture conflict, networks learn to classify by shape at least as easily as by texture, and taking less aggressive random crops while adding naturalistic augmentation (color distortion, noise, blur) produced models that classify ambiguous images by shape most of the time.
Annotation artifacts. Crowd workers asked to write a hypothesis that contradicts a premise often added a negation such as "nobody", "no" or "never"; neutral hypotheses often gained a purpose clause, and entailed ones used generic words. HANS was built so that a different shortcut fails: models that assume a premise entails every hypothesis made of its words, or of its contiguous phrases, get almost every entailment right and almost every non-entailment wrong.
On SNLI, a text classifier that sees only the hypothesis labels 67% of examples correctly, against 34% for always predicting the most common class. What does this show?
- The classifier must have seen the test premises during training
- Hypothesis-only models are better than models that read both sentences
- SNLI's labels are mostly wrong
- The way annotators wrote hypotheses left cues that predict the label, so a model can score well without relating the hypothesis to the premise at all
Show the answer
D. The way annotators wrote hypotheses left cues that predict the label, so a model can score well without relating the hypothesis to the premise at all
Negations for contradictions, purpose clauses for neutral statements and generic words for entailments let a model guess the label from the hypothesis alone. Part of what full models score may come from the same cues, which is why such baselines are run as diagnostics, and why harder test sets remove the cues.
Why networks take shortcuts
Empirical risk minimization has no reason to avoid a spurious feature: any feature that predicts the label lowers the training loss. Which of several predictive features a network ends up using depends on its inductive biases, and one of them is a preference for simple features. Shah, Tamuly, Raghunathan, Jain and Netrapalli (2020) made this vivid with MNIST-CIFAR images, an MNIST digit stacked on a CIFAR-10 image, with 0s paired with cars and 1s with trucks, so that each half alone predicts the label. MobileNetV2, GoogLeNet, ResNet-50 and DenseNet-121 all reached 100% accuracy using the MNIST half alone. Randomizing the MNIST half shuffled their outputs; randomizing the CIFAR half changed essentially nothing, although that half alone supports about 95% accuracy. Simplicity bias can be extreme: the network ignores the complex feature entirely, which is exactly what makes it brittle when the simple one shifts.
For linear models trained by gradient descent there is a sharper account. When a linear classifier without a bias term can fit the training data perfectly, gradient descent with a small enough step on the logistic loss never settles in the usual sense: the weights grow without bound, but their direction approaches, slowly, that of the hard-margin support vector machine (Soudry et al., 2018). Maximum margin is the optimizer's implicit bias, so ask what the max-margin classifier does with a spurious feature:
Give each example a core feature and a spurious feature with , where in the majority group and in a minority group where the correlation is reversed. The max-margin classifier (without bias) solves
No minority in training. Every point gives the same constraint, , so . When the classifier leans mostly on the spurious feature, and on a minority test point every example comes out wrong:
A few minority points in training. Now both and must hold, so , and the norm is smallest at , . In this low-dimensional picture, a single minority example is enough for the max-margin classifier to ignore the spurious feature entirely.
Real networks use spurious features even when minority examples are present and the core feature fully predicts the label. Nagarajan, Andreassen and Neyshabur (2021) identified two reasons. Geometric skew: in high dimension the norm needed to fit points with the core features grows with their number, so fitting the few minority points that way costs far less than fitting everyone, and the max-margin solution uses the spurious feature for the majority and spends a little norm on the minority. Statistical skew: gradient descent approaches the max-margin direction only logarithmically fast, so after finite training the spurious weight can still decay as slowly as , more slowly the stronger the correlation.
Overparameterization makes this worse. Sagawa, Raghunathan, Koh and Liang (2020) found that increasing model size well beyond zero training error can raise the minority groups' error even as average error falls, driven by the ratio of majority to minority examples and by the signal-to-noise ratio of the spurious correlation. In a linear model they traced it to an inductive bias toward memorizing as few examples as possible: a large model can memorize the minority and keep the shortcut for everyone else (Memorization & the Long Tail). Counterintuitively, subsampling the majority group then helped, while the standard fix, upweighting the minority, did not.
Measuring and training for the worst group
Averages hide all of this. Define groups by class and spurious attribute, , and report worst-group accuracy, the minimum over groups. Two standard benchmarks come from Sagawa, Koh, Hashimoto and Liang (2020). Waterbirds pastes photographs of birds onto land or water backgrounds, with 95% of the waterbirds on water and 95% of the landbirds on land in training: 4,795 training images, only 56 of them waterbirds on land. CelebA asks for hair color, with gender as the spurious attribute: 162,770 training images, of which 1,387 show blond men.
A hypothetical model on Waterbirds-style data has these accuracies, with each group's share of the test data:
- landbirds on land: 72% of the data, 99% accuracy
- landbirds on water: 4% of the data, 80% accuracy
- waterbirds on land: 1% of the data, 60% accuracy
- waterbirds on water: 23% of the data, 97% accuracy
What average accuracy does it report, in percent?
Show the answer
97.4 %
. The worst group, waterbirds on land, sits at 60%, and its 1% share moves the average by less than half a point: 95% of the data come from the two groups in which the background agrees with the label.
Group DRO (group distributionally robust optimization) minimizes the worst group's average loss instead of the overall average. A linear function on the probability simplex peaks at a vertex, so the worst mixture of groups is a single group:
Treat the objective as a game: the model descends on , an adversary ascends on . The natural ascent step on the simplex is exponentiated gradient, mirror ascent with the entropy, and the gradient with respect to is just :
Then take a gradient step on the reweighted loss. Groups with high loss gain weight multiplicatively, so the model is pushed hardest where it does worst:
For convex losses the averaged iterate approaches the saddle point at the rate , by the standard analysis of stochastic mirror descent, and each step costs about as much as an ordinary SGD step. Picking the single worst group at every step instead would be less stable.
import torch
import torch.nn.functional as F
def group_dro_step(model, opt, x, y, g, q, eta_q=0.01):
losses = F.cross_entropy(model(x), y, reduction='none')
m = q.numel()
counts = torch.bincount(g, minlength=m).clamp(min=1)
group_loss = torch.zeros(m).index_add(0, g, losses) / counts # mean loss of each group in the batch
q = q * torch.exp(eta_q * group_loss.detach()) # exponentiated-gradient ascent on q
q = q / q.sum()
loss = (q * group_loss).sum() # descend on the q-weighted loss
opt.zero_grad(); loss.backward(); opt.step()
return q # keep q across stepsg holds each example's group index, and q starts uniform. The weights persist across mini-batches, so a group that keeps losing gains influence over many steps.
The twist: regularization. With standard training, ERM and group DRO both drove every group's training accuracy to nearly 100%: an overparameterized network that fits all of its training data also has a vanishing worst-group training loss, so DRO has nothing left to reweight. ERM's worst-group test accuracy was 60.0% on Waterbirds and 41.1% on CelebA, and group DRO's 76.9% and 41.1%: the failure is one of worst-group generalization. Sagawa et al. therefore raised the penalty by orders of magnitude, from the default to 1 on Waterbirds and 0.1 on CelebA, so that no model could fit the training data perfectly. ERM then gave up the rare groups (worst-group test accuracy 21.3% and 37.8%), while group DRO kept them: 84.6% and 86.7%. Early stopping worked too: on Waterbirds, DRO reached 86.0% against ERM's 6.7%. Regularization matters for worst-group generalization even where it is not needed for average generalization (Weight Decay, Dropout & Early Stopping).
Fixes with fewer labels, and the limits of invariance
Group DRO needs a group label for every training example. Just Train Twice (JTT; Liu et al., 2021) needs them only on a small validation set, to tune its hyperparameters. Train an ERM model for a few epochs, collect the training examples it misclassifies into an error set , then train a second model with those examples upweighted by a factor :
Last-layer retraining. Kirichenko, Izmailov and Wilson (2023) found that ERM-trained networks often learn the core features anyway; the trouble is mostly in how the last layer weighs them. Deep feature reweighting (DFR) keeps the trained feature extractor and refits only the final linear layer, by -regularized logistic regression on a small group-balanced held-out set. At a fraction of the cost it matched far more elaborate methods: worst-group accuracy 92.9% on Waterbirds and 88.3% on CelebA, against 91.4% and 88.9% for group DRO. Simply balancing the data, by subsampling the large groups or classes, is also competitive with many of these methods (Idrissi, Arjovsky, Pezeshki & Lopez-Paz, 2022), in line with the subsampling result above.
Invariance. A more ambitious goal is to learn only features whose relation to the label is the same in every training environment, with no group labels at test time and no shortcut to exploit. Invariant risk minimization (IRM; Arjovsky, Bottou, Gulrajani & Lopez-Paz, 2019) asks for features on which one and the same last layer is the best classifier in every environment at once. Its guarantees proved fragile. In a linear model, Rosenfeld, Ravikumar and Risteski (2021) found that with no more training environments than environment-specific features, a solution built only from those features can satisfy IRM's constraint and even have lower risk than the invariant predictor; with nonlinear features, IRM can fail badly unless the test data resemble the training distribution, the very situation it was meant to escape. Benchmarks agree: carefully tuned ERM matched the specialized methods on DomainBed (Gulrajani & Lopez-Paz, 2021). The Machine Learning course's Covariate, Label & Concept Shift states these results in full.
Key takeaways
- Shortcuts are decision rules that work on test data drawn like the training data and fail out of distribution; backgrounds, textures, hospital markers, annotation artifacts and word overlap have all served.
- Training uses any predictive feature and favors simple ones, sometimes to the exclusion of all others, as in MNIST-CIFAR. A max-margin linear classifier ignores a spurious feature once a few minority points are present in low dimension, but geometric and statistical skews and overparameterization bring the spurious feature back.
- Worst-group accuracy exposes what averages hide. Group DRO minimizes the worst group's loss with exponentiated-gradient weights, but in overparameterized networks it needs strong regularization or early stopping to help reliably, because otherwise every group's training loss is already near zero.
- With few group labels, upweighting ERM's errors (JTT), refitting only the last layer on balanced held-out data (DFR) and subsampling recover most of the gap; invariance objectives such as IRM have fragile guarantees, and carefully tuned ERM is hard to beat on domain-generalization benchmarks.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
A classifier has 97% average accuracy on Waterbirds-style data but 60% on waterbirds photographed on land. Why does the average hide the problem?
- The average is computed on the training data only
- Worst-group accuracy is always about 37 points below the average
- The two numbers come from different models
- The average weights each group by its share of the data, so a group that makes up 1% of the data barely moves it
Show the answer
D. The average weights each group by its share of the data, so a group that makes up 1% of the data barely moves it
Most of the data come from groups in which the background agrees with the label, where the shortcut works. A rare group can be failed badly at almost no cost to the average, which is why robustness to spurious correlations is reported as worst-group accuracy.
With standard weight decay and training to convergence, group DRO and ERM reached exactly the same worst-group test accuracy on CelebA, 41.1%. Why didn't DRO help?
- The overparameterized networks fitted every training example, so every group's training loss was already near zero and there was nothing to reweight; the failure was in worst-group generalization, which strong regularization or early stopping fixed
- Group DRO's algorithm does not converge for neural networks
- The groups were defined incorrectly
- CelebA's training set has no spurious correlation between hair color and gender
Show the answer
A. The overparameterized networks fitted every training example, so every group's training loss was already near zero and there was nothing to reweight; the failure was in worst-group generalization, which strong regularization or early stopping fixed
A model with vanishing average training loss also has vanishing worst-group training loss, so minimizing the worst group's training loss changes nothing. Once a strong penalty (or early stopping) kept the networks from fitting everything, ERM sacrificed the rare groups and DRO protected them: on CelebA, 37.8% against 86.7% worst-group test accuracy.
Networks trained on MNIST-CIFAR images reach 100% accuracy. What happens to their predictions if the CIFAR half of each test image is replaced by a random CIFAR image, keeping the MNIST half?
- Accuracy falls to chance
- Accuracy falls to about 95%
- Essentially nothing: the networks ignore the CIFAR half
- Accuracy rises, since the network no longer sees conflicting evidence
Show the answer
C. Essentially nothing: the networks ignore the CIFAR half
Shah et al. found extreme simplicity bias: the networks relied exclusively on the simpler MNIST half. Randomizing it shuffled their outputs, while randomizing the CIFAR half left them essentially unchanged, even though the CIFAR half alone supports about 95% accuracy.
Just Train Twice improves worst-group accuracy without group labels on the training set. What does it use as a stand-in for them?
- Random subsets of the training data
- The training examples that an ERM model misclassifies after a few epochs, which are then upweighted
- The examples with the largest input gradients
- Clusters of the input images found without labels
Show the answer
B. The training examples that an ERM model misclassifies after a few epochs, which are then upweighted
Shortcuts make the minority examples the ones a briefly trained ERM model gets wrong, so its error set is a proxy for the hard groups. Group labels are still needed on a small validation set, to tune the number of epochs and the upweighting factor.
Further reading
- R. Geirhos, J.-H. Jacobsen, C. Michaelis, R. Zemel, W. Brendel, M. Bethge & F. A. Wichmann, "Shortcut learning in deep neural networks," Nature Machine Intelligence (2020).
- R. Geirhos, P. Rubisch, C. Michaelis, M. Bethge, F. A. Wichmann & W. Brendel, "ImageNet-trained CNNs are biased towards texture; increasing shape bias improves accuracy and robustness," ICLR (2019).
- H. Shah, K. Tamuly, A. Raghunathan, P. Jain & P. Netrapalli, "The pitfalls of simplicity bias in neural networks," NeurIPS (2020).
- S. Sagawa, P. W. Koh, T. B. Hashimoto & P. Liang, "Distributionally robust neural networks for group shifts: on the importance of regularization for worst-case generalization," ICLR (2020).
- P. Kirichenko, P. Izmailov & A. G. Wilson, "Last layer re-training is sufficient for robustness to spurious correlations," ICLR (2023).