SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2602.18502 · 2026

Mitigating Shortcut Learning via Feature Disentanglement in Medical Imaging: A Benchmark Study

Sarah Müller, Philipp Berens

arXiv · PDF · Open in the Atlas

Code that ran

10 of 12 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 5 honoured the contract we drafted, 0 violated it and 0 have no contract verdict; 5 failures of our instrument; 2 no recorded run), measured 2026-11-22; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2602.18502.json · badge: /api/ran/2602.18502.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
berenslab/medical-shortcut-mitigation canonical (classifier label)
classifier basis: census
10 ran · 2 no recorded run
FunctionStatusWhere it lives
compute_contingency_and_examples_from_labels Ran
ran; our contract draft was wrong, not the code
berenslab/medical-shortcut-mitigation/src/shortcut/utils.py
code served (permissive licence) · get_code("f26234a89ba11bec")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned tuple. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import numpy as np
import pandas as pd

# Create a small contingency table scenario with 2x2 classes
np.random.seed(0)

# Create labels: shape (N, 2) where column 0 = y1, column 1 = y2
# y1 has values in {0, 1}, y2 has values in {0, 1}
N = 20
y1_vals = np.random.randint(0, 2, size=N)
y2_vals = np.random.randint(0, 2, size=N)
labels = np.column_stack([y1_vals, y2_vals])

# Define levels for explicit ordering
levels = {
    'y1': [0, 1],
    'y2': [0, 1]
}

# Define a simple sample selector function
def sample_selector(indices, n):
    """Select up to n indices from the given indices array."""
    if len(indices) <= n:
        return indices
    return np.random.choice(indices, size=n, replace=False)

ARGS = {
    'labels': labels,
    'want_examples_per_cell': 2,
    'levels': levels,
    'sample_selector': sample_selector
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, pandas — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple — a tuple output has no array shape of its own; none is stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
extract_argument_keys Ran
ran; our contract draft was wrong, not the code
berenslab/medical-shortcut-mitigation/src/shortcut/config.py
code served (permissive licence) · get_code("45ad2e86a6f8caa7")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned list. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import numpy as np
from typing import Any, Optional

torch.manual_seed(0)

# Test case 1: Simple flat config
cfg_flat = {
    'learning_rate': 0.001,
    'batch_size': 32,
    'epochs': 10
}

# Test case 2: Nested config
cfg_nested = {
    'model': {
        'hidden_dim': 128,
        'num_layers': 3,
        'dropout': 0.1
    },
    'training': {
        'optimizer': 'adam',
        'lr': 0.0001
    },
    'data': {
        'path': '/data',
        'split': 0.8
    }
}

# Test case 3: Mixed nested and flat
cfg_mixed = {
    'name': 'experiment',
    'seed': 42,
    'params': {
        'alpha': 0.5,
        'beta': 0.3
    }
}

ARGS = {
    'cfg': cfg_nested,
    'prefix': None
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list — a list output has no array shape of its own; none is stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
extract_epoch Ran
ran, honoured the contract we drafted
berenslab/medical-shortcut-mitigation/src/shortcut/evaluation/aggregate_epochs.py
code served (permissive licence) · get_code("e6d1708dda25d1d0")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned int, ndim 0, dtype family int, shape () as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import re

def extract_epoch(ckpt_path: str) -> int:
    """Extracts the epoch number from a checkpoint filename of the form epoch=17.ckpt.
    
    Returns an integer epoch.
    """
    match = re.search('epoch=(\\d+)\\.ckpt', ckpt_path)
    if match:
        return int(match.group(1))
    else:
        raise ValueError(f'Could not parse epoch from checkpoint path: {ckpt_path}')


# Setup code to construct valid arguments
ARGS = {
    'ckpt_path': 'epoch=42.ckpt'
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type int, ndim 0, dtype family int, shape () — shape () as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
flatten Ran
ran, honoured the contract we drafted
berenslab/medical-shortcut-mitigation/src/shortcut/config.py
code served (permissive licence) · get_code("e0d2ff890c92b27e")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned list, ndim 1, dtype family int; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import numpy as np

# The function flatten takes a list parameter xs and recursively flattens it
# It checks if each element is a list, and if so, recursively flattens it
# Otherwise it appends the element to the result

# Construct a nested list with mixed depths
nested_list = [
    1,
    [2, 3],
    [4, [5, 6]],
    7,
    [[8, 9], 10],
    [[[11]], 12]
]

ARGS = {
    "xs": nested_list
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list, ndim 1, dtype family int — a list output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
flatten_list Ran
ran, honoured the contract we drafted
berenslab/medical-shortcut-mitigation/src/shortcut/utils.py
code served (permissive licence) · get_code("797a7d17ce5b8687")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned list, ndim 1, dtype family int; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import numpy as np

torch.manual_seed(0)

# The function takes a list of lists and flattens it
# We need to construct a valid list of lists argument

ARGS = {
    "lsts": [
        [1, 2, 3],
        [4, 5],
        [6, 7, 8, 9],
        []
    ]
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list, ndim 1, dtype family int — a list output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
get_criterion Ran
ran; our contract draft was wrong, not the code
berenslab/medical-shortcut-mitigation/src/shortcut/criterion.py
code served (permissive licence) · get_code("d0f1cf7101a32e07")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned BinaryFocalLoss. The image it ran in was not recorded. The code mentions cuda, and the harness aliases cuda to the CPU for every sample; whether this run needed that is not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

# Test case 1: Binary Cross Entropy with pos_weight
ARGS = {
    "criterion": "binary_focal",
    "kwargs": {
        "alpha": 0.75,
        "gamma": 0.2,
        "reduction": "mean",
        "eps": 1e-6
    }
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type BinaryFocalLoss — a BinaryFocalLoss output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a BinaryFocalLoss output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
get_mean_epoch Ran
ran, honoured the contract we drafted
berenslab/medical-shortcut-mitigation/src/shortcut/evaluation/aggregate_epochs.py
code served (permissive licence) · get_code("ba3e37a95dd31982")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned float, ndim 0, dtype family float, shape () as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import os
import tempfile
import shutil

# Create a temporary directory structure that matches what get_mean_epoch expects
temp_root = tempfile.mkdtemp()

# Create fold0 directory
fold0_dir = os.path.join(temp_root, 'fold0')
os.makedirs(fold0_dir)

# Create the latest_log_dir.txt file in fold0
latest_log_file = os.path.join(fold0_dir, 'latest_log_dir.txt')
log_dir = os.path.join(fold0_dir, 'logs')
os.makedirs(log_dir)
with open(latest_log_file, 'w') as f:
    f.write(log_dir)

# Create the best_ckpt.txt file in the log directory
best_ckpt_file = os.path.join(log_dir, 'best_ckpt.txt')
with open(best_ckpt_file, 'w') as f:
    f.write('epoch=5.ckpt')

# Create fold1 directory
fold1_dir = os.path.join(temp_root, 'fold1')
os.makedirs(fold1_dir)

# Create the latest_log_dir.txt file in fold1
latest_log_file = os.path.join(fold1_dir, 'latest_log_dir.txt')
log_dir = os.path.join(fold1_dir, 'logs')
os.makedirs(log_dir)
with open(latest_log_file, 'w') as f:
    f.write(log_dir)

# Create the best_ckpt.txt file in the log directory
best_ckpt_file = os.path.join(log_dir, 'best_ckpt.txt')
with open(best_ckpt_file, 'w') as f:
    f.write('epoch=7.ckpt')

ARGS = {
    'experiment_root': temp_root
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type float, ndim 0, dtype family float, shape () — shape () as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
load_epoch_times Ran
ran, honoured the contract we drafted
berenslab/medical-shortcut-mitigation/src/shortcut/evaluation/measure_compute_time.py
code served (permissive licence) · get_code("4a21195997a6a6b4")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned float64, ndim 0, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import numpy as np
from pathlib import Path
import tempfile
import os

# Create a temporary directory and epoch_times.txt file
temp_dir = tempfile.mkdtemp()
version_path = Path(temp_dir)

# Create a valid epoch_times.txt file with sample data
# First line is a header/metadata, subsequent lines are epoch times
epoch_data = np.array([0.0, 1.5, 2.3, 1.8, 2.1])
epoch_file = version_path / 'epoch_times.txt'
np.savetxt(epoch_file, epoch_data)

ARGS = {
    'version_path': version_path,
    'benchmark_epochs_file': 'epoch_times.txt'
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type float64, ndim 0, dtype family float — no output shape is stated: observe_signature.py recorded float ndim 0, which disagrees with the fixture run
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
nest_dict Ran
ran; our contract draft was wrong, not the code
berenslab/medical-shortcut-mitigation/src/shortcut/config.py
code served (permissive licence) · get_code("db1d257707c615ac")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned dict. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

torch.manual_seed(0)

# The function nest_dict takes a single parameter: x (a dict)
# It processes a flat dict with '/' separated keys and converts it to a nested dict
# The function only requires that x is a dict where:
# - keys are strings (they get split by '/')
# - values can be any type

ARGS = {
    "x": {
        "a/b/c": 1,
        "a/b/d": 2,
        "a/e": 3,
        "f": 4,
        "g/h/i/j": 5,
    }
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
prepare_config_for_benchmarking Ran
ran; our contract draft was wrong, not the code
berenslab/medical-shortcut-mitigation/src/shortcut/evaluation/measure_compute_time.py
code served (permissive licence) · get_code("205c9e57716f9722")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned tuple, ndim 1, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import tempfile
from pathlib import Path
import yaml

# Create a temporary YAML file with valid hparams structure
temp_hparams = tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.yaml')

hparams_dict = {
    'cfg': {
        'out_dir': tempfile.gettempdir(),
        'training': {
            'fold': 0,
            'check_val_every_n_epoch': 1,
            'warmup_epochs': 1,
            'start_saving_epoch': 1
        },
        'max_epochs': 10,
        'devices': [0],
        'benchmark_timing': False,
        'data': {}
    }
}

yaml.safe_dump(hparams_dict, temp_hparams)
temp_hparams.close()

ARGS = {
    'hparams_file': temp_hparams.name,
    'fold_index': 0,
    'max_epochs': 5,
    'devices': '0',
    'dataset_path': None
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
yaml — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple, ndim 1, dtype family float — a tuple output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
plot_data_overview Not yet run
unverified (harvested, no recorded run)
berenslab/medical-shortcut-mitigation/src/shortcut/utils.py
code served (permissive licence) · get_code("170b7a6188f312ff")
How it ran

no invocation recorded.

run_training Not yet run
unverified (harvested, no recorded run)
berenslab/medical-shortcut-mitigation/src/shortcut/evaluation/measure_compute_time.py
code served (permissive licence) · get_code("5ac524479b74f0a7")
How it ran

no invocation recorded.

Also present in other papers' code

Of 12 samples lifted from this paper's linked repositories, 12 carry a function identity and 0 do not. Of the 12 distinct functions with an identity, 0 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 0 later) and 12 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-22.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

Although deep learning models in medical imaging often achieve excellent classification performance, they can rely on shortcut learning, exploiting spurious correlations or confounding factors that are not causally related to the target task. This poses risks in clinical settings, where models must generalize across institutions, populations, and acquisition conditions. Feature disentanglement is a promising approach to mitigate shortcut learning by separating task-relevant information from confounder-related features in latent representations. In this study, we systematically evaluated feature disentanglement methods for mitigating shortcuts in medical imaging, including adversarial learning and latent space splitting based on dependence minimization. We assessed classification performance and disentanglement quality using latent space analyses across one artificial and two medical datasets with natural and synthetic confounders. We also examined robustness under varying levels of confounding and compared computational efficiency across methods. We found that shortcut mitigation methods improved classification performance under strong spurious correlations during training. Latent space analyses revealed differences in representation quality not captured by classification metrics, highlighting the strengths and limitations of each method. Model reliance on shortcuts depended on the degree of confounding in the training data. The best-performing models combine data-centric rebalancing with model-centric disentanglement, achieving stronger and more robust shortcut mitigation than rebalancing alone while maintaining similar computational efficiency. The project code is publicly available: https://github.com/berenslab/medical-shortcut-mitigation.

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2602.18502")
get_code_for_paper("2602.18502")
have("2602.18502")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2602.18502.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2602.18502.svg)](https://syntology.ai/paper/2602.18502)

Connect an agent — have() is free.