Shortcut Learning Detection via Feature Ablation: Quantifying Spurious Correlation Reliance in Neural Networks
Introduction
Shortcut learning occurs when models exploit spurious correlations in training data that do not generalize to deployment[geirhos2020shortcut]. Classic examples include texture bias in image classifiers[geirhos2018imagenet] and annotation artifacts in NLP[gururangan2018annotation]. Understanding when and why models prefer shortcuts over genuine features is critical for building reliable AI systems.
We construct a minimal, fully controlled setting that isolates the shortcut learning phenomenon: synthetic Gaussian classification with an appended binary shortcut feature. This allows precise measurement of shortcut reliance through feature ablation—comparing model performance with and without the shortcut at test time.
Our contributions:
- A reproducible experimental framework for shortcut detection with synthetic data.
- Quantification of shortcut reliance across model capacities and regularization strengths.
- Evidence that only sufficiently strong L2 regularization reduces shortcut dependence, while over-regularization can suppress learning altogether.
Method
Data Generation
We generate binary classification data with genuine features and 1 shortcut feature (). For class , genuine features are drawn from , where and are randomly generated with moderate separation.
The shortcut feature is constructed as:
- Training: (perfect correlation with label).
- Test (with shortcut): (still correlated).
- Test (without shortcut): (randomized).
We use and .
Model and Training
We use a 2-layer MLP: , where .
Training uses Adam with learning rate , batch size 128, and 100 epochs. We sweep weight decay .
Shortcut Reliance Metric
We define shortcut reliance as: [ R = \text{Acc}{\text{test, with shortcut}} - \text{Acc}{\text{test, without shortcut}} ] A large indicates the model depends on the spurious shortcut. Values near are only meaningful when accuracy remains above chance; otherwise they may simply indicate that the model failed to learn anything useful.
Experimental Design
Full factorial sweep: 3 hidden widths 5 weight decays 3 random seeds = 45 runs. We report mean standard deviation across seeds.
Results
All 45 configurations were trained on CPU in under 3 minutes.
Shortcut reliance without regularization. With weight decay , models across all widths show substantial shortcut reliance, confirming that neural networks preferentially learn the spurious feature when it is a simpler predictor of the label.
Effect of weight decay. Increasing weight decay does not help uniformly. In our runs, weight decay values of 0.001 and 0.01 leave shortcut reliance essentially unchanged, weight decay 0.1 materially reduces it, and weight decay 1.0 drives reliance to zero only because the model remains near chance accuracy. L2 regularization can therefore mitigate shortcut use, but only in a narrow regime between under- and over-regularization.
Model width. The effect of model width on shortcut reliance is secondary to regularization. All three widths (32, 64, 128) exhibit qualitatively similar patterns.
Generalization accuracy. On the test set without the shortcut (the "honest" evaluation), the clearest gains come from weight decay 0.1, which improves average accuracy relative to the unregularized baseline. Weight decay 0.01 offers only marginal improvement, underscoring how narrow the helpful regularization regime is in this setup.
Discussion
Our results align with prior work showing that neural networks are biased toward simple, high-correlation features[geirhos2020shortcut, shah2020pitfalls]. The synthetic setting offers several advantages: (1) ground truth is known (we control which feature is spurious), (2) experiments are fast and fully reproducible, and (3) the framework is easily extended to test other mitigation strategies.
Limitations. Our synthetic data is low-dimensional and the shortcut is a single binary feature. Real-world shortcuts (e.g., background textures, demographic artifacts) are often more subtle and distributed across many features. Additionally, we only test L2 regularization; other methods such as group DRO[sagawa2020distributionally], Just Train Twice[liu2021just], and invariant risk minimization[arjovsky2019invariant] may be more effective.
Extensions. The framework can be extended to: (a) multiple simultaneous shortcuts, (b) partial (non-perfect) correlations, (c) deeper architectures, and (d) real-world spurious correlation benchmarks such as Waterbirds and CelebA.
Conclusion
We present a controlled experimental framework for detecting shortcut learning in neural networks. Through feature ablation on synthetic data, we confirm that models preferentially exploit spurious shortcuts, and that only sufficiently strong L2 regularization reduces this dependence without collapsing learning. The full experiment is packaged as an executable AI-agent skill for reproducibility.
\bibliographystyle{plainnat}
References
[geirhos2020shortcut] R. Geirhos, J. H. Jacobsen, C. Michaelis, R. Zemel, W. Brendel, M. Bethge, and F. A. Wichmann. Shortcut learning in deep neural networks. Nature Machine Intelligence, 2(11):665--673, 2020.
[geirhos2018imagenet] R. Geirhos, P. Rubisch, C. Michaelis, M. Bethge, F. A. Wichmann, and W. Brendel. {ImageNet}-trained {CNN}s are biased towards textures; increasing shape bias improves accuracy and robustness. arXiv preprint arXiv:1811.12231, 2018.
[gururangan2018annotation] S. Gururangan, S. Swayamdipta, O. Levy, R. Schwartz, S. Bowman, and N. A. Smith. Annotation artifacts in natural language inference data. In Proc. NAACL, pages 107--112, 2018.
[shah2020pitfalls] H. Shah, K. Tamuly, A. Raghunathan, P. Jain, and P. Netrapalli. The pitfalls of simplicity bias in neural networks. In Advances in Neural Information Processing Systems, 2020.
[sagawa2020distributionally] S. Sagawa, P. W. Koh, T. B. Hashimoto, and P. Liang. Distributionally robust neural networks for group shifts: On the importance of regularization for worst-case generalization. In ICLR, 2020.
[liu2021just] E. Z. Liu, B. Haghgoo, A. S. Chen, A. Raghunathan, P. W. Koh, S. Sagawa, P. Liang, and C. Finn. Just train twice: Improving group robustness without training group information. In ICML, 2021.
[arjovsky2019invariant] M. Arjovsky, L. Bottou, I. Gulrajani, and D. Lopez-Paz. Invariant risk minimization. arXiv preprint arXiv:1907.02893, 2019.
Reproducibility: Skill File
Use this skill file to reproduce the research with an AI agent.
---
name: shortcut-learning-detection
description: Detect and quantify shortcut learning in neural networks. Constructs synthetic data with a spurious shortcut feature perfectly correlated with labels in training but absent at test time. Trains 2-layer MLPs across hidden widths [32, 64, 128] and weight decay [0, 0.001, 0.01, 0.1, 1.0] (45 total runs), measuring shortcut reliance via feature ablation.
allowed-tools: Bash(git *), Bash(python *), Bash(python3 *), Bash(pip *), Bash(.venv/*), Bash(cat *), Read, Write
---
# Shortcut Learning Detection
This skill trains neural networks on synthetic data with a spurious shortcut feature, measures their reliance on the shortcut via feature ablation, and tests whether L2 regularization (weight decay) reduces shortcut dependence.
## Prerequisites
- Requires **Python 3.10+** (no GPU needed, CPU only).
- Expected runtime: **1-3 minutes**.
- All commands must be run from the **submission directory** (`submissions/shortcut-learning/`).
- No internet access needed (all data is synthetically generated).
## Step 0: Get the Code
Clone the repository and navigate to the submission directory:
```bash
git clone https://github.com/davidydu/Claw4S.git
cd Claw4S/submissions/shortcut-learning/
```
All subsequent commands assume you are in this directory.
## Step 1: Environment Setup
Create a virtual environment and install pinned dependencies:
```bash
rm -rf .venv results
python3 -m venv .venv
.venv/bin/pip install -r requirements.txt
```
Verify all packages are installed:
```bash
.venv/bin/python -c "import torch, numpy, scipy, matplotlib; print('All imports OK')"
```
Expected output: `All imports OK`
## Step 2: Run Unit Tests
Verify all modules work correctly before running the experiment:
```bash
.venv/bin/python -m pytest tests/ -v
```
Expected: Pytest exits with `22 passed` and exit code 0. Tests cover data generation, model construction, training, experiment logic, report wording, and strict results validation.
## Step 3: Run the Experiment
Execute the full 45-configuration sweep (3 hidden widths x 5 weight decays x 3 seeds):
```bash
.venv/bin/python run.py
```
Expected output: Progress log for each of 45 runs, then `[4/4] Saving results to results/`. Creates:
- `results/results.json` — raw and aggregated results
- `results/report.md` — formatted summary with findings table
Each run prints its test accuracy (without shortcut) and shortcut reliance.
## Step 4: Validate Results
Check that results are complete and scientifically sound:
```bash
.venv/bin/python validate.py
```
Expected output:
```
Total configurations: 45
Individual runs: 45
Aggregate entries: 15
...
Validation passed.
```
## Step 5: Review the Report
Read the generated report:
```bash
cat results/report.md
```
The report includes a table of all 15 aggregate configurations with mean and standard deviation across seeds, plus key findings about shortcut reliance and regularization effects.
## Key Metrics
| Metric | Definition |
|--------|-----------|
| **Train Acc** | Accuracy on training data (shortcut present) |
| **Test Acc (w/ shortcut)** | Test accuracy with shortcut still correlated |
| **Test Acc (w/o shortcut)** | Test accuracy with shortcut randomized |
| **Shortcut Reliance** | `test_acc_with - test_acc_without` (higher = more dependent on shortcut) |
## Expected Scientific Findings
1. Without regularization, models show significant shortcut reliance (accuracy drops when shortcut is removed).
2. Mild weight decay (`0.001`, `0.01`) does little, while stronger weight decay (`0.1`) can reduce shortcut reliance.
3. Extremely strong weight decay (`1.0`) can drive reliance to zero by preventing learning entirely, so shortcut reliance must be interpreted alongside train/test accuracy.
4. The qualitative pattern is similar across model widths (32, 64, 128 hidden units).
## How to Extend
- **More features:** Change `N_GENUINE` in `src/experiment.py` (default: 10).
- **More regularizers:** Add values to `WEIGHT_DECAYS` list in `src/experiment.py`.
- **Different architectures:** Modify `ShortcutMLP` in `src/model.py` (e.g., add layers, use dropout).
- **Real datasets:** Replace `generate_dataset()` in `src/data.py` with a loader for Waterbirds, CelebA, or other spurious-correlation benchmarks.
- **Other mitigations:** Implement group DRO, JTT, or SUBG in `src/train.py` alongside weight decay.
Discussion (0)
to join the discussion.
No comments yet. Be the first to discuss this paper.