AnyLearn
All lessons
AIadvanced

Causality in Modern Machine Learning

Why prediction systems fail when deployed, how invariance across environments becomes a training signal, and where causal reasoning enters bandits, reinforcement learning, and language models.

Updated · AI-authored, review-gated · how lessons are made

Not signed in: your progress and quiz score won't be saved.
Progress1 / 8

Why prediction systems fail on deployment

A recurring pattern in applied machine learning: a model performs well in validation and degrades badly in deployment, in ways that seem unrelated to overfitting.

A frequent explanation is that the model learned an association that was not causal, and the association did not survive the change of setting.

The standard illustration is a classifier distinguishing cows from camels which, having only ever seen cows on grass and camels on sand, has largely learned to classify background. It is not broken as a predictor. Within the training distribution the background is genuinely informative, and the model correctly exploited it.

The problem is that the relationship between background and animal is not a stable mechanism. It is an artefact of how the photographs were collected, and it changes when the collection process changes.

Causal relationships behave differently, and this is the property that makes them worth pursuing. The mechanism relating a shape to its label is invariant across settings; the correlation between background and label is not.

So a system relying on causal structure should degrade more gracefully under distribution shift than one exploiting whatever correlations happened to be strongest.

Full lesson text

All 8 steps on one page, for reading, reference, and search.

Show

1. Why prediction systems fail on deployment

A recurring pattern in applied machine learning: a model performs well in validation and degrades badly in deployment, in ways that seem unrelated to overfitting.

A frequent explanation is that the model learned an association that was not causal, and the association did not survive the change of setting.

The standard illustration is a classifier distinguishing cows from camels which, having only ever seen cows on grass and camels on sand, has largely learned to classify background. It is not broken as a predictor. Within the training distribution the background is genuinely informative, and the model correctly exploited it.

The problem is that the relationship between background and animal is not a stable mechanism. It is an artefact of how the photographs were collected, and it changes when the collection process changes.

Causal relationships behave differently, and this is the property that makes them worth pursuing. The mechanism relating a shape to its label is invariant across settings; the correlation between background and label is not.

So a system relying on causal structure should degrade more gracefully under distribution shift than one exploiting whatever correlations happened to be strongest.

2. Invariance as a training signal

That observation converts into an algorithm, and it is the most practically influential idea connecting causality to machine learning.

The reasoning runs in two steps. Causal mechanisms are stable across environments. Spurious correlations vary across environments. So if you have data from several environments, a feature whose predictive relationship holds in all of them is a candidate causal feature, and one whose relationship shifts is a candidate spurious one.

This reframes the training objective. Ordinary empirical risk minimisation asks for the predictor minimising average error over pooled data, which happily exploits whatever correlations dominate the pool. Invariance-based approaches instead search for a representation whose relationship to the outcome is the same in every environment.

The practical requirement is that you need multiple environments with genuine variation, and enough of it to distinguish stable relationships from unstable ones. Data from different hospitals, countries, time periods, or measurement devices all qualify.

Kiyavash's work uses this structure directly: causal effects can be identifiable under a latent confounder when data is available from multiple environments, provided the target effect remains invariant across them.

The idea is powerful and not a solved problem. How much environment variation is needed, and how reliably these methods work, remains actively researched.

3. Every decision system is causal

There is a sharper point about where causality is mandatory rather than merely helpful.

A system that only reports predictions can be evaluated on predictive accuracy. A system whose outputs drive actions cannot, because it is being used to answer an interventional question whatever it was trained on.

A model predicting which customers will churn is used to decide whom to contact. A model predicting readmission risk is used to decide whom to treat. A model scoring loan applications determines who receives a loan.

In each case the deployed question is not "what will happen?" but "what will happen if I act?", which is one rung up the ladder from what the training objective addressed.

The failure this produces is specific and worth naming. Suppose customers who receive a retention offer churn more in your historical data, because offers were sent to customers already showing signs of leaving. A predictive model learns that association correctly. Acting on it inverts the policy.

The practical rule: if a model's output changes what happens, it is being used causally, and it should be validated by intervention, meaning an experiment, rather than by held-out predictive accuracy alone.

4. Where causal reasoning is required

The question is not how sophisticated the model is but what its output is used for. Only the left branch is answerable by predictive validation alone.

flowchart TD
  A["A model produces an output"] --> B{"Does anyone act on it?"}
  B -- no --> C["Pure prediction"]
  C --> D["Validate on held-out accuracy"]
  B -- yes --> E["The output changes what happens"]
  E --> F["An interventional question is being asked"]
  F --> G{"Was the model trained on interventional data?"}
  G -- yes --> H["Experiments or logged policy with known assignment"]
  G -- no --> I["Observational: identification argument required"]
  I --> J["Validate by experiment, not accuracy"]

5. Bandits and reinforcement learning

Sequential decision-making is where the connection is tightest, because these settings are explicitly interventional by construction.

A multi-armed bandit chooses an action and observes a reward. That is intervention: the algorithm sets the action rather than observing one that was chosen for other reasons. Exploration exists precisely to generate interventional data where observational data would be confounded.

So bandits and reinforcement learning already do causal inference. The interesting questions arise where the clean assumption breaks.

Unobserved confounders in the environment. If something influences both the reward and the state you observe, standard methods can converge to a wrong policy.

Off-policy evaluation. Estimating how a new policy would perform using data logged under a different one is exactly a causal question about an intervention never taken, and it uses the same re-weighting machinery as observational causal inference.

Transfer. Moving a policy to a new environment is asking whether the learned relationships were mechanisms or artefacts.

This is where Kiyavash's recent direction sits. The European Research Council awarded her an ERC Advanced Grant in 2025 for the project CIEL, Causal Inference for Exploration and Learning, aimed at bridging causal inference and modern learning systems, with a focus on sequential decision-making including bandits, reinforcement learning, and large language models.

6. Language models and causal language

Large language models raise the question in an unusually slippery form, and precision matters here because claims in both directions are overstated.

What is established is that these models reproduce causal claims present in their training data fluently. Ask which of two variables causes the other in a well-documented domain and the answer is usually right, because it was written down many times.

That is retrieval of recorded causal knowledge, which is genuinely useful. It is not the same as inferring causal structure from data, and the distinction is easy to lose because the outputs look alike.

Two failure modes follow from the mechanism. The model has no way to distinguish a widely repeated causal claim from a well-established one, so a popular misconception is reproduced with the same confidence as a settled finding. And given an actual dataset, nothing in next-token prediction performs the identification analysis the second lesson described.

The more interesting research direction runs the other way: applying causal reasoning to language models. What in a prompt caused a particular output? Does a fine-tuning intervention change behaviour for the reason assumed? These connect naturally to interpretability, where intervention is already the standard for establishing a mechanism.

7. What causality realistically offers ML

An honest accounting, since this area attracts both overclaiming and dismissal.

ClaimStatus
Causal features generalise better under shiftWell motivated, empirically mixed
Invariance across environments is a usable signalYes, given genuine environment variation
Decision systems need interventional validationUncontroversial and widely ignored
Causal discovery can replace domain knowledgeNo, it generates hypotheses
Causality solves distribution shiftNo, only shifts that preserve mechanisms
LLMs perform causal inferenceNo, they retrieve recorded causal claims

Two points deserve emphasis.

Causality is not a robustness cure. It helps against shifts that leave causal mechanisms intact while changing spurious correlations. A shift that changes the mechanism itself is not addressed, and neither is a shift into a genuinely novel regime.

The costs are real. Causal methods need assumptions you must defend, multiple environments or experiments you must obtain, and they typically give worse in-distribution accuracy than a model free to exploit every available correlation. You are trading average-case performance for stability, and that trade is only worth making when the deployment distribution actually differs from the training one.

8. What this path establishes

Four claims, and the question to carry away.

Prediction and intervention are different problems. The ladder of causation separates them formally, and a higher rung cannot in general be answered from lower-rung data without an assumption about the data-generating process. Structural causal models are how those assumptions get stated precisely enough to check.

Identification comes before estimation. Given a graph, the backdoor and front-door criteria and instrumental variables say exactly when a causal effect is computable from observational data, and by what formula. When nothing identifies it, more data and more model capacity do not help, and bounds with sensitivity analysis are the honest response.

Discovery has a hard limit. Conditional independencies determine a graph only up to a Markov equivalence class, because chains and forks are observationally identical and only colliders break the symmetry. Allowing latent confounders makes the output less determinate and more honest.

Machine learning needs this wherever outputs drive actions. Invariance across environments turns causal stability into a training signal, sequential decision-making is interventional by construction, and any deployed model that changes what happens is answering a causal question whatever it was trained on.

The durable habit: before trusting a number, ask what assumption makes this causal, and would I defend it?

Check your understanding

The lesson ends with a 5-question quiz. Take it in the player above to see your score.

  1. Why does a classifier that learned background rather than animal shape fail on deployment?
    • The background association is not a stable mechanism, so it does not survive a change in how data is collected
    • Background pixels contain more noise than foreground pixels
    • The model overfitted to the training set and memorised examples
    • Backgrounds are harder to represent than object shapes
  2. How does invariance across environments become a training signal?
    • By averaging predictions from models trained separately per environment
    • By upweighting environments where accuracy is lowest
    • By searching for a representation whose relationship to the outcome holds in every environment, since causal mechanisms are stable while spurious correlations shift
    • By removing features with high variance across the pooled dataset
  3. When is a predictive model necessarily being used causally?
    • Whenever it uses more than one input feature
    • Whenever its training data came from observational sources
    • Whenever it is deployed on a distribution different from training
    • Whenever its output changes what happens, since the deployed question becomes what will happen if I act
  4. Why are bandits and reinforcement learning already doing causal inference?
    • They estimate conditional independencies during exploration
    • The algorithm sets the action rather than observing one chosen for other reasons, which is intervention by construction
    • They require a causal graph as an input
    • Their reward functions encode counterfactual outcomes
  5. What do large language models actually do when asked causal questions?
    • They perform identification analysis on the described variables
    • They run causal discovery over the entities mentioned in the prompt
    • They reproduce causal claims present in their training data, without distinguishing widely repeated from well-established ones
    • They estimate conditional independencies from memorised datasets

Related lessons

AI
intermediate

Streams, Actions, Rewards, and Thinking That Is Not Ours

The paper is concrete about what an experiential agent would differ on, and names four: it lives in a continuous stream rather than episodes, acts in the world rather than emitting text, takes rewards from grounded signals rather than human judgement, and plans in terms it worked out rather than imitating human chain of thought. This lesson works through each.

8 steps·~12 min
AI
intermediate

The Argument: Why Learning From Us Runs Out

David Silver and Richard Sutton argue that the current approach has a ceiling built into it, because a system trained to predict what humans wrote is aiming at human performance by construction. This lesson works through their three eras, the claim about data exhaustion, why they think superhuman performance needs a different learning signal, and the honest counter-arguments.

8 steps·~12 min
AI
intermediate

What This Teaches About Measuring Anything

The exchange is a case study with transferable rules. A conclusion resting on failures needs a failure taxonomy. Every instance must be verified solvable before anyone is scored against it. Output format is a confound whenever answers get long. And when two explanations fit the same data, the productive move is to find the prediction on which they differ, then test it.

8 steps·~12 min
AI
intermediate

The Rebuttal: Three Ways to Score Zero Without Failing

The response disputed none of the data and argued the experiment measured something other than reasoning. Models had to print move lists exceeding their output limits, and said so in the transcripts. Some instances had no solution and were scored as failures anyway. And asking for a program instead of a move list produced high accuracy on instances reported as total collapse.

8 steps·~12 min