Learning systems from first principles

Learning, generalisation and the shape of a task

A model generalises only across the changes its training and evaluation force it to survive; a random split can hide the rule it actually learned.

Rajesh Ranjan Mahapatra

Why a model can pass a random test split yet fail when the world changes, and how to design a train-test-shift contract that exposes the rule it learned.

© 2026 Rajesh Ranjan Mahapatra. 31 min read

Learning, generalisation and the shape of a taskAll Human–Machine Convergence

Learning systems from first principles

Learning, generalisation and the shape of a task

A model generalises only across the changes its training and evaluation force it to survive; a random split can hide the rule it actually learned.

TLDR

  • Generalisation is transport from observed examples to a declared family of environments.
  • An independent test split estimates performance under one sampling process, not resilience to every change.
  • Models can tie on benchmark accuracy while using different, incompatible decision rules.
  • Counterfactual stress tests expose shortcuts by changing nuisance features while preserving the target.
  • Release decisions need a task-shape contract, named shifts and an explicit risk rule.

Opening case

Imagine a parcel-inspection system trained to recognise damage from warehouse photographs. In the training site, an operator places a red sticker on every damaged parcel before the camera takes the picture. A random test split looks excellent. The images are new, the labels are hidden and the score is high.

At a second site, parcels are photographed before any sticker is applied. The model fails. It was not incompetent at the dataset’s task. It had learned that task efficiently: find the red patch. The failure began earlier, when the project treated “predict the label in this sample” as equivalent to “recognise physical damage wherever the system will operate”.

The familiar explanation is that the model overfit. That diagnosis is incomplete. It suggests the model memorised individual examples. In this case it may classify unseen images perfectly whenever the sticker convention remains. The deeper problem is that the training and test data support several rules, and the split does not distinguish them.

The score measured travel between samples drawn from one world. The intended task required travel between worlds. That difference is the shape of the task.

The generalisation terrain

A flat benchmark plateau can conceal steep failure ravines outside the sampled path.

Generalisation terrain with a benchmark path and hidden ravines A landscape shows a high flat training and random-test plateau. The deployment route bends into ravines labelled changed camera, changed site and changed policy. A shortcut model follows the plateau edge and falls, while a stable-rule route crosses the landscape. High score does not map the whole terrain Train Deployment shortcut route stable-rule route changed camera changed site changed policy random split samples a narrow path unseen ravines are properties of the task, not the chart
Illustrative. The practical question is not whether the model crossed the held-out sample. It is whether the evaluation path crossed the changes that matter.

The rule inside the score

Learning selects a rule from many rules that fit the observations. Generalisation depends on which one was selected and where it must travel.

A test set answers a conditional question

Let a model receive an input x, produce a prediction f(x), and incur loss when that prediction disagrees with a label y. Training minimises average loss on observed examples. A conventional test set asks whether performance remains similar on unseen examples drawn by roughly the same process.

Under independent and identically distributed sampling, this is a powerful question. The test result estimates expected loss for the population represented by that process. Classical learning theory studies how sample size, model capacity and the learning algorithm constrain the gap between empirical and expected risk. Those tools remain useful.

But the guarantee is conditional. It depends on the test population, the sampling unit, the label process and the loss. Change any of those, and a new question appears. “Unseen” does not mean “unlike training”. It often means only “not previously sampled”.

Three transfers are often folded into one score. The first is from a finite sample to the source population that could have produced it. The second is from that source population to the environments in which the system will be used. The third is from predictive performance to the consequences of a decision policy. A random hold-out is designed mainly for the first transfer. It provides no automatic bridge for the other two.

This distinction matters even when the statistics are impeccable. Suppose a test set contains ten thousand independently sampled parcels from the original warehouse. Its confidence interval may be narrow, and the estimate may be unbiased for that warehouse. None of this tells us whether sticker policy, lighting or camera placement can change. Precision about the wrong population is still precision.

Call the difference sample novelty versus environment novelty. Sample novelty asks whether the model has seen this particular row. Environment novelty asks whether the relation carrying the prediction has been challenged. The two can coincide, but they need not. A new photograph can be environmentally familiar. An edited copy of an old photograph can be environmentally novel if the edit breaks a suspected shortcut while preserving the target.

Worked example: two clues, one label

Suppose every object has a shape clue and a background clue. Shape predicts the label correctly 80 per cent of the time in every environment. Background predicts it correctly 95 per cent of the time in the training environment. On a random split from that environment, a background rule wins. When the background-label relation reverses, the same rule falls to 5 per cent while the shape rule remains near 80 per cent. Neither rule memorised individual examples. They learned different regularities.

Two predictive channels under intervention

Changing the environment leaves the target mechanism intact but breaks the shortcut channel.

Causal diagram contrasting stable and shortcut features The target-generating state affects a stable feature and the label. Environment affects a shortcut feature and the data collection process. In training, shortcut and label are correlated. An intervention on environment breaks that correlation while preserving the target relation. Observed correlation can be carried by different mechanisms Target state what the decision is about Stable feature shape, lesion, structure Shortcut feature background, site, stamp Label observed target Environment site, time, policy correlation, not necessarily a stable path Intervene on environment: preserve target state, alter shortcut
Practitioner synthesis. The diagram is a design hypothesis, not proof that a feature is causal. Its purpose is to identify which relation a stress test should break.

Capacity does not tell the learner which rule you meant

A small model can overfit, and a large model can generalise. Model size alone does not settle the matter. Deep networks can fit random labels, showing that successful optimisation does not by itself explain why the learned rule works beyond the sample.[1] Modern test error can also follow non-classical curves as capacity increases, so a simple “larger means more overfit” story is unreliable.[2]

The important question is selection among fitting solutions. Data geometry, architecture, optimisation, regularisation and preprocessing all bias that selection. A model may prefer a visually simple texture, a frequent token, a site identifier or a proxy variable because it is easier to exploit than the structure a human considers relevant.

Shortcut learning names this pattern: a decision rule performs well under standard conditions but fails when the shortcut no longer tracks the intended target.[3] Underspecification names a related pipeline-level problem: several models satisfy the observed requirements yet behave differently in deployment-relevant conditions.[4] These are not exotic corner cases. They are the normal consequence of evidence that leaves multiple rules alive.

Same score, different rule

A benchmark tie is not behavioural equivalence once the environment changes.

Illustrative synthetic values. The ranking can reverse when the evaluation changes. The point is structural, not the particular percentages.
Thought experiment 1: the coloured badge

Train a classifier to distinguish two animal species. Every animal of species A wears a violet badge; every animal of species B wears a yellow badge. Now add one million more photographs without changing that convention. What should happen? Sampling error falls, confidence rises and the badge rule becomes better estimated. The extra data do not teach badge invariance because no example requires it. More samples from one world can make the wrong rule more certain.

Thought experiment 2: infinite copies of one world

Imagine an unlimited stream from a single camera, hospital, language community or policy regime. The stream contains no label noise and covers every local variation. Does infinite data guarantee the intended generalisation? No. It can identify the distribution of that world with extraordinary precision while saying nothing about which relationships persist after a site, instrument or policy intervention. Sample abundance answers uncertainty within the observed world. It cannot create missing counterfactual variation.

Mechanism: observational equivalence

Two decision rules are observationally equivalent for an evaluation when they make the same predictions on its examples. A targeted intervention makes them distinguishable by changing a feature on which only one rule depends. The intervention does not have to be physical. It may be a held-out site, a temporal split, a recomposed image, a masked field, a counterfactual edit or a deliberately rebalanced subgroup.

Worked example: memorisation is not the only failure

Consider three classifiers. The first stores a lookup table for every training image and guesses on anything else. The second detects the red sticker. The third detects torn cardboard and crushed corners. On training data, all three can be perfect. On a random test from the same warehouse, the lookup table fails, while the sticker and damage rules both succeed. On a sticker intervention, only the damage rule survives. A conventional train-test comparison detects memorisation but leaves the two generalising rules observationally tied.

This is why “the test score is close to the training score” is necessary but not sufficient. It shows that the model travelled beyond exact examples. It does not show that it travelled by the intended relation.

The argument in one pass
Chart · flow
flowchart TD
  A["Opening case"] --> B["The rule inside the score"]
  B --> C["Generalisation is transport<br/>across change"]
  C --> D["Make the hidden rule visible"]
  D -. "re-test" .-> A
  classDef first fill:#0a1424,stroke:#D95545,stroke-width:2px,color:#e6f3ff
  classDef step fill:#0a1424,stroke:#3f7da0,stroke-width:1px,color:#e6f3ff
  class A first
  class B,C,D step
A structural route through Learning, generalisation and the shape of a task: from Opening case to Define the task terrain before…. Reading use: follow the relation, then return to the surrounding argument for evidence and limits.

Generalisation is transport across change

A model does not generalise “in general”. It transports performance from one set of conditions to another, under assumptions about what may change and what should remain stable.

Name the environments before measuring the gap

Let e denote an environment: a site, time period, acquisition process, demographic mixture, interface, policy regime or intervention. Each environment induces a distribution over inputs and labels. The risk of model f in environment e is:

Re(f) = E(X,Y) ~ Pe[ L(f(X), Y) ]

X is the observed input, Y the target, L the cost of a prediction and Pe the data-generating distribution in environment e. A random split estimates risk for an environment similar to the source. A broader task might care about average risk across a deployment mixture, worst-group risk, maximum risk over named environments or cost after an action policy.

The task is partly encoded in the risk functional. Average accuracy says frequent cases matter in proportion to their frequency. Worst-group accuracy says no declared group may be sacrificed by aggregation. A cost-sensitive loss says some errors are more consequential than others. None is universally correct. Each states a decision.

Take two environments. Model A has losses of 4 per cent and 24 per cent. Model B has losses of 12 per cent and 13 per cent. If the first environment supplies 95 per cent of cases, Model A has lower average loss. If either environment must remain safe, Model B has lower maximum loss. The models have not changed. The preferred model changes because the decision rule changed.

This small example exposes a common reporting error. Teams select a model using average validation accuracy, then describe the result as robust because they also display subgroup metrics. Display is not selection. If the release decision refuses to sacrifice an environment, the selection objective or gate must encode that refusal.

Table 1. Four meanings often compressed into “generalisation”
MeaningWhat changesWhat is assumed stableUseful split or test
Sample generalisationIndividual examplesSampling process and target relationIndependent random hold-out
Group generalisationPrevalence of known subpopulationsGroup definitions and label semanticsPer-group and worst-group evaluation
Domain generalisationSite, time, instrument or styleEnough task structure to transferLeave-one-domain-out or prospective domain
Intervention generalisationA named causal or nuisance variableThe target mechanism under that interventionCounterfactual, perturbation or controlled change

The task has shape before it has data

A useful task description has at least five geometric features. It has a centre, the environments expected most often. It has an extent, the range of authorised variation. It has seams, where subgroups or sites meet. It has cliffs, where small input changes create large decision costs. It has moving ground, where labels or behaviour change after deployment.

Dataset design samples this shape. A random split samples densely near the centre. Leave-one-site-out evaluation probes a seam. A temporal hold-out follows moving ground. Counterfactual interventions approach a suspected cliff from both sides. No single split covers all of them, and adding every possible test is neither feasible nor necessary. The point is to align the sampled geometry with the decision.

The shape also limits what can be learned. If every training environment couples the same shortcut to the target, there is no observational evidence that the coupling is dispensable. An algorithm may still avoid the shortcut because of prior structure, pretraining or regularisation, but the dataset did not identify that choice. The claim should then acknowledge reliance on those priors.

Three journeys from the same training set

Random hold-out, future deployment and deliberate intervention are different routes, even when they begin with identical data.

Three evaluation trajectories from training data A training dataset branches into a random hold-out route, a temporal deployment route and an intervention route. Each route changes different properties and supports a different conclusion. One source, three different claims Training sample observed world Random hold-out same process, new samples Future deployment time and usage may drift Intervention set named relation deliberately broken sample claim operational claim mechanism clue
Practitioner synthesis. A result should inherit the scope of the route that produced it. A random hold-out cannot silently stand in for a future site or an intervention.

The unit of independence is part of the task

Consider medical images from repeated visits, audio clips from the same speaker, satellite tiles from adjacent coordinates or documents generated from the same template. If related observations are split across training and test sets, the nominally unseen examples may share identity, context or acquisition artefacts with training data. The split is independent at the row level but not at the decision-unit level.

This is more than “data leakage” in the narrow sense of copying the answer. It is a boundary error. The project has not decided what must be new at deployment. If the future decision concerns a new patient, patient identity should define the split. If it concerns a new hospital, hospital should define at least one stress environment. If it concerns future behaviour, time should move in one direction.

Thought experiment 3: move the preprocessing boundary

A document model receives text after a pipeline inserts a template identifier. When the identifier is present, accuracy is high. Now declare the preprocessor “outside the model” and report only the classifier architecture. Has the learned task changed? No. The configured system still depends on the identifier. Move the boundary again by removing that field at deployment and performance changes. The candidate being evaluated is the full transformation from raw input to decision, not only the weights.

Where the system boundary moves

A model-level test can miss dependencies introduced by collection, preprocessing and decision policy.

System-boundary view of data collection, preprocessing, model and action Raw world state passes through collection, preprocessing, model and action. Three nested boundaries show that evaluating only the model omits upstream shortcut sources and downstream costs. Which object is supposed to generalise? configured decision system learning pipeline model parameters + runtime collection camera, site, policy preprocess crop, fields, joins action threshold, review, cost A boundary that omits the shortcut source cannot certify the configured system.
Practitioner synthesis. Report the boundary of the evaluated system. A claim about weights is weaker than a claim about the configured pipeline that produces actions.

A realistic task-shape audit

Consider a crop-disease classifier intended for field use. The raw input is a leaf photograph. The target is a disease state confirmed by an agreed diagnostic process. Training data arrive from three farms, each using a different camera and collection tray. Disease prevalence also differs by farm.

A random image split allows the model to use tray colour, camera processing or farm-specific background as proxies. A plant-level split prevents near-duplicate leaves from crossing the boundary. A farm-held-out split asks whether performance travels to a new collection environment. A time-held-out split tests seasonal change. A counterfactual edit that replaces the tray while preserving the leaf tests a particular shortcut. These tests do not compete. They correspond to different deployment changes.

A configured evaluation might therefore contain four datasets: an independent in-environment test set, a held-out farm, a later season and a synthetic tray intervention reviewed for label preservation. It would report average accuracy, per-farm accuracy, calibration and abstention. The release question becomes concrete: does the system meet the minimum risk across the environments it is authorised to face?

The audit should also follow errors into action. A false negative may delay field treatment; a false positive may trigger unnecessary spraying. If uncertain cases are routed to an agronomist, the relevant outcome is not raw classifier accuracy alone. It is residual error after abstention, reviewer workload and the time required to obtain a decision. Generalisation of a score can differ from generalisation of the configured policy.

Now imagine the new farm uses a camera outside the authorised range. Monitoring detects a change in colour response and increases abstention. This is not evidence that the model has generalised to the new device. It is evidence that the system recognised the edge of its envelope and failed safely. Detection and recovery are legitimate responses to unknown shift; confident prediction is not the only form of competence.

Benchmarks such as WILDS were created because real applications face shifts across hospitals, locations, time and other settings that ordinary datasets underrepresent.[5] Replicated test sets for major image benchmarks have also produced material accuracy drops even when collection procedures were carefully matched.[6] These findings do not imply that every benchmark is worthless. They show that the benchmark’s sampling route is part of the result.

Boundary condition: when stability is the wrong demand

Some changes alter the target mechanism itself. A new disease variant may change which visual features are diagnostic. A policy change may redefine the label. A market intervention may change behaviour because the model is deployed. In such cases, forcing one invariant predictor can preserve an obsolete relation. The correct response may be detection, abstention, re-labelling or adaptation rather than invariant prediction.

Optional depth: four common sources of distribution shift

Covariate shift changes the distribution of inputs while preserving the conditional target relation assumed by the model. Label shift changes class prevalence while preserving how inputs arise within each class. Concept shift changes the relation between inputs and labels. Selection shift changes which cases enter the dataset. These categories are modelling assumptions, not labels that can be read directly from a histogram. Several may occur together.

For an anti-causal prediction task, where the target state helps generate the observed features, an intervention on the target or measurement process can alter many features at once. “Use causal features” is therefore not a universal recipe. The useful question is narrower: which relationship is expected to remain stable under the authorised change?

Make the hidden rule visible

A stress test is useful when it separates rival rules. Random corruption is not enough. The change must preserve what should matter and alter what should not.

Cross the target with the suspected nuisance

A useful stress test begins with rival explanations. Write the intended rule and at least one shortcut rule in terms that could produce predictions. Then ask what change would make them disagree. This reverses the usual sequence, in which a team adds generic noise and hopes that robustness means something.

The intervention needs a preservation argument. Identify the target property that should remain unchanged, the nuisance property that will change, the method used to create or collect the case, and the evidence that the label is still valid. For images, a background edit can alter shadows or occlusion. For text, paraphrasing can change pragmatics. For tabular data, reweighting can create combinations that are impossible in the real process. A stress set that corrupts the target tests tolerance to damage, not invariance to nuisance.

Suppose the target is object shape and the suspected nuisance is background colour. The minimum revealing design contains all four combinations: target A with background 1, target A with background 2, target B with background 1, and target B with background 2. If training contains mostly the diagonal combinations, the off-diagonal cases become decisive.

This simple cross does three jobs. It shows whether the model has observed each combination. It measures the dependence of predictions on the nuisance. It also reveals an evaluation gap before a model is trained. If the project cannot construct or collect the off-diagonal cases, it should lower the strength of its generalisation claim.

Use paired cases when possible. Start from one instance, change only the suspected nuisance, and compare the prediction. Paired analysis reduces unrelated variation and supports a clearer causal interpretation. Then complement it with naturally collected environments, because synthetic edits can introduce artefacts of their own. Agreement between controlled and natural tests is stronger than either alone.

Finally, predefine the expected signature. A target-sensitive model should keep its class when only the nuisance changes. A shortcut-sensitive model should follow the nuisance. A model that abstains may be behaving appropriately if the edit moves the input outside its valid support. Without this prediction ledger, surprising results are too easy to explain after the fact.

The counterfactual cross

Off-diagonal cases distinguish a target rule from a nuisance rule.

Illustrative. Filled circles mark familiar combinations; diamonds mark counterfactual combinations. A target-sensitive model should preserve the row label when the column changes.
Thought experiment 4: the same score from a different mechanism

Model A reads the object. Model B reads a watermark added by the labelling tool. Both score 98 per cent on a random test set. Remove the watermark and Model B fails. Blur the object while retaining the watermark and Model B succeeds. The original score did not identify the mechanism. The paired interventions do. The lesson is not that explanations replace evaluation. It is that mechanism claims require changes that rival mechanisms answer differently.

The smallest useful numerical example

Take 100 training examples. In 95, the shortcut agrees with the label. The stable feature is noisier and agrees in 80. A simple learner assigns weight 1.8 to the shortcut and 0.4 to the stable feature. On an identically sampled test set, it scores near the shortcut’s reliability.

Now create a shift set in which the stable feature is unchanged but the shortcut agrees only 10 per cent of the time. A prediction score of 0.4 × stable + 1.8 × shortcut is dominated by the shortcut and reverses on many cases. A stable-only score of 1.0 × stable keeps roughly the same accuracy. The exact values depend on noise and optimisation. The causal lesson does not: the original split rewarded a dependency that the deployment change broke.

Notice the assumption. We treated the stable feature’s relation to the label as invariant. If the shift also damages that feature, the stable-only model may fail too. Stress testing is not an oracle. It is a way to make assumptions executable.

More data can deepen wrong certainty

Within-environment accuracy rises with sample size while shifted accuracy plateaus or falls when the shortcut dominates.

Illustrative learning curves for random-test and shifted accuracy As training examples increase, random-test accuracy rises toward 96 percent. Shift accuracy initially rises then falls toward 25 percent. A stable-feature baseline remains near 80 percent across sample sizes. Data quantity cannot substitute for missing variation 0255075100% smalltraining exampleslarge random test shift test stable-feature reference Illustrative trajectory, not a universal learning law
Illustrative. The curve changes if the data introduce relevant environment diversity. The figure isolates the case where only the number of same-environment samples grows.

Build a task-shape contract

Before choosing a robustness method, write down the task’s change-set. A change-set is the collection of environment changes the system is expected or authorised to face. It need not contain every imaginable future. It should contain the plausible, consequential and testable changes that matter to the decision.

The following instrument turns that idea into a project artefact. It is deliberately stricter than a dataset card and narrower than a full safety case. Its purpose is to connect task definition, split design, stress tests and release criteria.

Complete the contract before the final model exists. Otherwise, the observed strengths of a favoured model tend to redefine the task. A system that performs poorly on one site may suddenly be described as “not intended” for that site, even when the site was part of the original need. Versioning the contract makes scope changes visible and reviewable.

The contract should also name unknowns. Some changes are plausible but not yet testable. Record them as unsupported environments rather than assigning a speculative score. This creates a research queue: collect data, build a simulator, design a proxy or constrain use until evidence exists.

The task-shape contract

Seven fields connect the intended decision to the changes a model must survive.

New practitioner instrument. The contract does not guarantee completeness. It prevents an unqualified benchmark score from becoming a broader operational claim without an explicit bridge.
Open research hypothesis: change-set coverage

Training examples improve shift performance when they vary along deployment-relevant nuisance dimensions while preserving the target relation, rather than only when their count increases. Evidence would strengthen this claim if adding a new environment improves worst-shift risk more than adding the same number of examples inside an existing environment. It would weaken the claim if equal gains appear without added variation. A rival explanation is that the extra environment merely supplies better regularisation or higher-quality examples. The proposal should not be applied when the target relation itself changes. The smallest useful study needs two training environments, one held-out shift and a matched same-size data addition.

Algorithms help only after the task is shaped

Invariant Risk Minimisation proposes learning a representation for which one classifier is optimal across training environments.[7] Group distributionally robust optimisation instead minimises the worst loss over predefined groups.[8] Both encode valuable ideas: seek relationships that persist, and do not let average performance hide a failing group.

Neither removes the need to define environments and groups. An invariance penalty cannot discover every relevant shift from one homogeneous environment. Group robustness cannot protect an unlabelled or absent group. Practical IRM formulations can fail to recover intuitive invariances, and theoretical critiques identify conditions under which the objective can select undesirable solutions.[9] Broad domain-generalisation comparisons have also found that carefully tuned empirical risk minimisation remains a strong baseline and many specialised methods do not consistently outperform it.[10]

The decision is therefore not “ERM or invariance”. It is a sequence. Declare the change-set. Construct environments that make rival rules disagree. Fit a strong baseline. Compare algorithms using a selection rule aligned to deployment risk. Preserve a hidden challenge set so repeated tuning does not turn the stress test into another familiar benchmark.

Data interventions often dominate objective changes. Rebalancing groups, collecting minority combinations, removing a proxy field or changing acquisition can make the intended rule easier to identify. Algorithmic penalties are most credible when they operate on environments whose differences are meaningful. A mathematically elegant penalty over arbitrary partitions may optimise stability that has no deployment interpretation.

Model inspection can help generate hypotheses, but it should not close the case. Feature attribution, probes and saliency may suggest a shortcut. The release evidence should include behavioural interventions that alter the suspected feature, because readable internal patterns need not be causally used. Conversely, a failed explanation method does not prove the model is robust. The test remains tied to predictions under change.

Table 2. Choose the release metric from the failure you refuse to hide
Risk ruleQuestion answeredMain blind spot
Average riskHow well does the model perform under the expected mixture?Rare or costly failures can disappear in aggregation.
Worst declared groupDoes any known subgroup fall below the floor?Unknown groups and within-group shifts remain hidden.
Maximum named-environment riskCan the model survive every environment in the contract?Only listed environments are covered.
Cost after policyWhat happens after thresholds, abstention and human review?Requires credible operational costs and reviewer behaviour.
How the claim changes under pressure
Chart · state
stateDiagram-v2
  [*] --> Claim
  state "A test set answers a<br/>conditional question" as Claim
  state "Capacity does not tell the<br/>learner which rule you meant" as Test
  state "Name the environments before<br/>measuring the gap" as Revision
  Claim --> Test: expose mechanism
  Test --> Decision: evidence survives
  Test --> Revision: rival survives
  Revision --> Claim: narrow or rebuild
  Decision --> [*]
The revision loop begins with A test set answers a conditional question and keeps counterexamples inside the reasoning path. Reading use: follow the relation, then return to the surrounding argument for evidence and limits.

The train-test-shift lab

The lab below makes the hidden rule observable. It creates one stable feature, one environment-specific shortcut and three evaluation worlds.

What the experiment tests

Each synthetic example has a binary label. The stable feature is a noisy measurement of that label and keeps the same relationship across environments. The shortcut feature is cleaner in training but its reliability can change. Ordinary ERM fits both features using only the training environment. A stress-selection procedure fits several candidate feature sets and regularisation strengths, then selects the candidate with the best worst accuracy across declared stress environments.

The experiment encodes a strong assumption: the stable feature truly remains stable and the specified stress environments resemble the changes we care about. A positive result permits a narrow conclusion. It supports lower shortcut dependence under those synthetic shifts. It does not prove causal correctness, general robustness or readiness for an unrelated real system.

There are three candidate feature families: stable only, shortcut only and both. Each is fitted with several regularisation strengths. Stress-selection chooses the candidate with the highest minimum accuracy across the familiar, neutral and reversed environments. This is a miniature form of model selection under a maximum named-environment risk rule.

The stable-only candidate is not privileged by code. It wins only when its worst-environment result exceeds the alternatives. Increase stable noise far enough and no candidate performs well. Make the shift mild and the combined model may remain competitive. These outcomes matter because they prevent the story from becoming “always discard the easy feature”. The correct rule is to select evidence that survives the declared changes.

Interactive train-test-shift laboratory

Change shortcut reliability and stable-feature noise, then compare familiar-test and shifted performance.

Run the synthetic shift

The browser uses deterministic synthetic data and logistic regression. Results are illustrative and reproducible for the displayed seed.

ERM, both features
Stress-selected
Train
0%
0%
Familiar test
0%
0%
Neutral stress
0%
0%
Reversed shift
0%
0%

Run the lab to generate results.

Executable synthetic experiment. The stress-selected model may choose only the stable feature when that choice improves the worst declared environment. The selection is evidence about this change-set, not a universal robustness certificate.

How to read a positive or negative result

When ERM remains strong on the familiar test but collapses on the reversed shortcut, the experiment demonstrates an evaluation blind spot. When stress-selection chooses the stable feature and preserves shifted accuracy, it demonstrates that the declared environment variation was sufficient to change model selection.

A negative result has several meanings. The stable feature may be too noisy. The candidate model family may not contain a stable solution. The stress set may be too small or may not isolate the shortcut. The alleged invariant may be false. The proper response is diagnosis, not relabelling the failed model as generally incapable.

The same logic scales to real systems. Replace synthetic shortcut reliability with environments defined by site, time, device, subgroup or a validated counterfactual generator. Replace feature subsets with candidate architectures, data strategies or checkpoints. Preserve the selection discipline: choose using the risk functional in the task-shape contract, then evaluate once on a protected challenge set.

A practical run has six receipts. The data manifest states which unit is independent and how environments were assigned. The model manifest records architecture, preprocessing and training configuration. The stress manifest records every intervention and its label-preservation review. The selection receipt shows the metric used to choose the candidate. The effect receipt stores per-environment results with uncertainty. The release receipt names thresholds, unsupported environments and monitoring triggers.

These receipts prevent a common collapse of meaning. Without them, “test accuracy” can refer to the random hold-out in one report, the stress set in another and a post-threshold operational metric in a third. Typed evidence keeps the journey attached to the number.

Python · core experiment
from dataclasses import dataclass
import numpy as np

@dataclass(frozen=True)
class Env:
    name: str
    shortcut_p: float
    n: int
    seed: int

def make_env(spec, stable_noise=1.15, shortcut_noise=0.20):
    rng = np.random.default_rng(spec.seed)
    y = rng.choice([-1.0, 1.0], size=spec.n)
    stable = y + rng.normal(0, stable_noise, spec.n)
    agrees = rng.random(spec.n) < spec.shortcut_p
    shortcut = np.where(agrees, y, -y) + rng.normal(0, shortcut_noise, spec.n)
    return np.column_stack([stable, shortcut]), y

def fit_logistic(x, y, l2=0.01, steps=1200, lr=0.08):
    xb = np.column_stack([np.ones(len(x)), x])
    w = np.zeros(xb.shape[1])
    for _ in range(steps):
        margin = np.clip(y * (xb @ w), -40, 40)
        grad = xb.T @ (-y / (1 + np.exp(margin))) / len(xb)
        grad[1:] += l2 * w[1:]
        w -= lr * grad
    return w

def accuracy(w, x, y):
    xb = np.column_stack([np.ones(len(x)), x])
    return np.mean(np.where(xb @ w >= 0, 1.0, -1.0) == y)

# Complete runnable version, candidate search and typed checks:
# paper33_train_test_shift_lab.py

Run python paper33_train_test_shift_lab.py with NumPy installed. The complete file searches stable-only, shortcut-only and combined candidates across regularisation settings.

Optional depth: assumptions and invariants in the executable artefact

The generator enforces five invariants. Labels are balanced in expectation. The stable feature is produced by the same equation in every environment. Only shortcut reliability changes. Training and evaluation seeds are separate. Candidate selection never uses the final protected set in a real implementation, although the compact browser demonstration exposes all environments for teaching.

For operational use, split the stress environments into a development set and a challenge set. Version the generator, data, model, preprocessing and metric code. Record which candidate was selected and why. A result without these receipts can be difficult to reproduce and easy to reinterpret after the fact.

The stress test can become another shortcut

Repeatedly tuning against one public shift set turns that set into part of the training loop. Teams learn its quirks, choose augmentations that target it and report progress as though the evaluation remained independent. This is adaptive overfitting at the benchmark level.

The remedy is not permanent secrecy. It is layered evidence. Keep some stress generators visible so teams can reason about failure. Preserve a protected challenge set for model selection audits. Add prospective data after release. Rotate tests when the system, environment or decision policy changes. A mature programme evaluates the process that produces models, not only one frozen checkpoint.

How a benchmark becomes a shortcut

A clean hold-out loses independence when repeated inspection, tuning and reporting feed information back into development.

Failure path from clean benchmark to adaptive overfitting A sequence begins with a clean hold-out, then repeated evaluation, metric inspection, targeted tuning and leaderboard selection. Feedback arrows turn the hold-out into a development signal. A protected challenge set and prospective monitoring interrupt the path. Independence can be spent Clean hold-outone independent look Inspect errorslearn test quirks Targeted tuningoptimise to the set Select winnermany trials, one report Inflated claimscope silently expands feedback turns evaluation into development data Protected challenge set limited access, versioned release gate Prospective monitoring new data after the decision changes
Practitioner synthesis. Evaluation evidence has a lifecycle. Reuse is not forbidden, but every feedback path narrows the conclusion a score can support.
Release rule

Release only when the baseline and selected model are evaluated on the same protected change-set, every named environment meets its floor, the configured system boundary is fixed, and monitoring can detect when those conditions stop holding. A high average score cannot waive a failed non-negotiable environment.

The evidence conversation
Chart · sequence
sequenceDiagram
  participant Q as Question
  participant M as Mechanism
  participant E as Evidence
  participant D as Decision
  Q->>M: Opening case
  M->>E: A test set answers a conditional question
  E-->>M: compare rival explanations
  E->>D: Define the task terrain before celebrating the score
  D-->>Q: revise scope or act
Question, mechanism, evidence and decision exchange the burdens developed in Learning, generalisation and the shape of a task. Reading use: follow the relation, then return to the surrounding argument for evidence and limits.

Define the task terrain before celebrating the score

Stop asking whether a model generalises before asking where its performance must travel.

The standard workflow begins with a dataset, chooses a random split, trains several models and reports the best test score. The revised workflow begins with the decision. It names the unit that must be new, the target meaning, the changes the system may face and the relationships expected to survive. Only then does it design splits and stress tests.

This does not abolish ordinary generalisation testing. The random hold-out remains the right instrument for estimating performance on new samples from the source process. The change is one of scope. Keep that estimate, then add only the routes needed by the intended use. A narrow, well-supported envelope is more useful than a broad claim whose assumptions are invisible.

This changes model selection. A candidate is no longer preferred merely because it wins on the familiar distribution. It must satisfy the risk rule across the declared generalisation envelope. A simpler model may be chosen because its performance is stable. A larger model may still win if it demonstrates both higher average performance and acceptable shift behaviour. The decision follows evidence, not a prior preference for simplicity or scale.

It also changes data collection. When a shortcut is suspected, the first response should not always be a new loss function. Collect the missing combinations. Add environments that vary the nuisance while preserving the target. Hold out the unit that will truly be new. Record the configured pipeline that creates the model’s input.

Finally, it changes language. Say “the model generalised from these farms to this held-out farm”, “remained calibrated across these devices” or “survived this validated background intervention”. Do not convert those statements into “the model generalises” without qualification.

A benchmark score is a receipt for one journey through the task terrain. The responsible decision is to define the journey before celebrating the arrival.

Appendix A

Glossary

Change-set
The declared collection of environment changes a system is expected or authorised to face.
Environment
A condition such as site, time, device, population, interface, policy or intervention that induces a data distribution.
Empirical risk
Average loss on observed examples.
Generalisation envelope
The environments, thresholds and operational conditions for which evidence supports use.
Invariant relation
A relationship hypothesised to remain stable across specified environments. Stability is always relative to a change-set.
Shortcut
A decision rule that succeeds under the sampled conditions but fails when a non-essential correlation changes.
Stress set
An evaluation set designed to make plausible rival rules disagree.
Underspecification
A condition in which available requirements or tests admit multiple models with materially different downstream behaviour.
Worst-group risk
The largest loss among predefined groups, used when average performance must not hide a failing group.
Appendix B

References

  1. Zhang, C., Bengio, S., Hardt, M., Recht, B. and Vinyals, O. (2017). Understanding deep learning requires rethinking generalization. International Conference on Learning Representations.
  2. Belkin, M., Hsu, D., Ma, S. and Mandal, S. (2019). Reconciling modern machine-learning practice and the classical bias-variance trade-off. Proceedings of the National Academy of Sciences.
  3. Geirhos, R. et al. (2020). Shortcut learning in deep neural networks. Nature Machine Intelligence.
  4. D’Amour, A. et al. (2022). Underspecification presents challenges for credibility in modern machine learning. Journal of Machine Learning Research.
  5. Koh, P. W. et al. (2021). WILDS: A benchmark of in-the-wild distribution shifts. International Conference on Machine Learning.
  6. Recht, B., Roelofs, R., Schmidt, L. and Shankar, V. (2019). Do ImageNet classifiers generalize to ImageNet? International Conference on Machine Learning.
  7. Arjovsky, M., Bottou, L., Gulrajani, I. and Lopez-Paz, D. (2019). Invariant Risk Minimization.
  8. Sagawa, S., Koh, P. W., Hashimoto, T. B. and Liang, P. (2020). Distributionally robust neural networks for group shifts: On the importance of regularization for worst-case generalization. International Conference on Learning Representations.
  9. Rosenfeld, E., Ravikumar, P. and Risteski, A. (2021). The risks of Invariant Risk Minimization. International Conference on Learning Representations.
  10. Gulrajani, I. and Lopez-Paz, D. (2021). In search of lost domain generalization. International Conference on Learning Representations.
  11. Peters, J., Bühlmann, P. and Meinshausen, N. (2016). Causal inference by using invariant prediction: Identification and confidence intervals. Journal of the Royal Statistical Society: Series B.
  12. Taori, R. et al. (2020). Measuring robustness to natural distribution shifts in image classification. Advances in Neural Information Processing Systems.
  13. Sagawa, S., Raghunathan, A., Koh, P. W. and Liang, P. (2020). An investigation of why overparameterization exacerbates spurious correlations. International Conference on Machine Learning.
  14. Schölkopf, B. et al. (2021). Towards causal representation learning. Proceedings of the IEEE.
  15. Zhou, W. et al. (2025). Mitigating data bias and ensuring reliable evaluation of AI models with shortcut hull learning. Nature Communications.