Dec 2025 · Causal Learning · NeurIPS 2025 Workshop on CauScien

Transformer Is Inherently a Causal Learner

We reveal that transformers trained autoregressively naturally encode causal structures — gradient attributions directly recover underlying causal graphs without any explicit causal objectives.

Xinyue Wang* · Stephen Wang · Biwei Huang
Data generation and transformer-based causal discovery.
Data generation and transformer-based causal discovery. Left: a decoder-only transformer trained for next-step prediction; tokens are lagged observations, and the model predicts X_t from past values. Right: a lagged data-generating process, where each variable depends on selected past values per the true causal graph. The trained transformer learns the process, and relevance attribution helps recover the causal structure.

What if the foundation models we use every day are secretly learning the causal structure of the world? We show that transformers trained for prediction are inherently causal learners — their gradient sensitivities reveal the true cause-and-effect relationships in data, without any explicit causal training objectives.

The big picture

Causal discovery — figuring out what causes what — is fundamental to science. Traditional methods require specialized algorithms with strong assumptions. Meanwhile, transformers have become the backbone of modern AI, excelling at prediction tasks across domains.

Our key insight: these two worlds are deeply connected. When a transformer learns to predict the future from the past, it must implicitly learn which past variables actually matter for each prediction. This is exactly what causal discovery aims to find.

From prediction to causation

Consider a p-variate time series X_t = (X_1,t, …, X_p,t) and a lag window L ≥ 1. Each variable follows X_i,t = f_i(Pa(i,t), U_t, N_i,t), where Pa(i,t) are the lagged parents, U_t are unobserved processes and N_i,t are mutually independent noises.

  • A1 — Conditional exogeneity. Latent confounders are allowed as long as they don’t create spurious dependencies.
  • A2 — No instantaneous effects. All parents occur at lags ℓ ≥ 1.
  • A3 — Lag-window coverage. The chosen L includes all true parents.
  • A4 — Faithfulness. The distribution is faithful to the causal graph.

Theorem · causal identifiability via prediction. Under A1–A4 and regularity conditions, the lagged causal graph G* is uniquely identifiable via the score gradient energy: edge j → i at lag ℓ exists if and only if H^ℓ_j,i := 𝔼[(∂_x_j,t−ℓ log p(X_i,t | X_<t))²] > 0.

Unlike classical Granger causality, which tests mean prediction, the score gradient energy captures influence on the entire conditional distribution. Gradient sensitivity = causal relevance.

Why transformers are natural causal learners

Alignment with identifiability. Causal masking enforces temporal precedence (A2); the window L bounds maximum lag (A3); autoregressive training naturally fits conditional distributions.

Scalable sparsity. Finite capacity and weight decay compress observations into generalizable parameters; softmax attention induces competitive selection among candidates; multi-head context supports selecting complementary parents.

Contextual parameters. Attention matrices are input-conditioned, adapting to heterogeneity and non-stationarity — different contexts induce distinct dependency patterns, enabling a mixture-of-graphs view.

Gradient-based extraction. Layer-wise Relevance Propagation computes how much each past variable contributes to each prediction; we aggregate and threshold to recover the causal graph.

Results

We evaluate decoder-only transformers against PCMCI, DYNOTEARS, VAR-LiNGAM, NTS-NOTEARS, TCDF and Granger causality tests. The transformer recovers lagged parents accurately and consistently across settings, reaching 0.62 average F1 — nearly doubling the best baseline (DYNOTEARS at 0.37) — and stays robust as dynamics and dimension grow, without sensitive hyperparameter tuning.

Additional analysis

To validate that gradient attributions truly capture causal relationships, we compare them with intervention-based effects — the gold standard in causal inference — by intervening on inputs by one standard deviation and measuring the average effect on outputs. The strong correlation confirms that the transformer’s internal representation genuinely captures causal structure, not just statistical association.

We also ask whether existing time-series foundation models can discover structure zero-shot. Forecasting accuracy is reasonable but structure recovery is suboptimal; finetuning on domain-specific data significantly improves both, and adding node embeddings — even randomly initialized — helps the model distinguish variables.

Implications

For causal discovery. A new paradigm: instead of hand-crafting discovery algorithms, leverage the representation learning of foundation models. The transformer becomes a universal causal structure extractor that scales with data.

For foundation models. Gradient attributions reveal learned dependencies (interpretability); hallucinations may arise when insufficient data prevents accurate structure learning; causal priors such as sparsity and modularity could guide better architectures.

F1 score analysis across regimes.
F1 score analysis across regimes. (A) Mean F1 across all experiments. (B) High-dimensional: F1 vs. number of nodes. (C) Long-range dependencies: F1 vs. maximum lag. (D) Nonlinearity: F1 vs. functional forms. (E) Non-stationarity: F1 vs. number of domains. DOT = decoder-only transformer.
Nonlinear dependencies.
Nonlinear dependencies. Traditional methods are efficient in simple linear cases, but transformers improve consistently as data scales.
Non-stationary dependencies.
Non-stationary dependencies. Unlike methods that become intractable with more data, the transformer exhibits scaling — accuracy improves with sample size.
Robustness.
Robustness. Stable across noise types and variances, but spurious links appear as latent confounders increase.
Handling violated assumptions.
Handling violated assumptions. L-PCMCI post-processing recovers latent confounders; PCMCI+ refines instantaneous effects; domain indices improve data efficiency.
Attention vs. gradient attribution.
Attention vs. gradient attribution. Raw attention works in shallow models but fails with depth; LRP-based attribution consistently wins.
Uncertainty.
Uncertainty. True edges show high mean relevance rankings and low variance — a pragmatic way to surface reliable edges.
Intervention effects vs. gradient attributions.
Intervention effects vs. gradient attributions. Intervention effect correlates strongly with the relevance score.
Zero-shot structure recovery.
Zero-shot structure recovery. Reasonable forecasting, suboptimal structure — until light domain finetuning.