Transforming Causality: Transformer-Based Temporal Causal Discovery with Prior Knowledge Integration

Jihua Huang, Yi Yao, Ajay DivakaranarXiv 2025

TL;DR

This paper introduces a novel framework for temporal causal discovery that combines a multi-layer Transformer time-series forecaster with a gradient-based causal graph extractor. By leveraging attention masking and a strict separation of source and target variables, the framework successfully integrates human prior knowledge to eliminate spurious correlations across multiple layers. The approach yields a 12.8% improvement in F1-score for causal discovery and achieves 98.9% accuracy in estimating causal lags compared to state-of-the-art baselines.

What Problem Does This Paper Address?

Uncovering causal relationships in multivariate time-series data—knowing not just which variables influence each other, but when those influences occur—is foundational for fields like healthcare, finance, and climate science. However, temporal causal discovery is notoriously difficult due to complex nonlinear relationships, long-range dependencies, and spurious correlations (e.g., the classic example of ice cream sales and drowning incidents both rising due to hot weather).

Classical methods like Granger causality or score-based optimization struggle to scale or fail entirely in nonlinear settings. Recent deep learning approaches using RNNs or CNNs fall short when capturing long-range dependencies. While Transformers are excellent at modeling long-term temporal structures, existing Transformer-based causal discovery methods have been restricted to single-layer architectures. They lack a mechanism to reliably enforce prior human knowledge or constraints across multiple layers without suffering from "attention propagation," where restricted information accidentally bleeds through intermediate layers.

Methods

The authors propose a two-part framework consisting of a Causality-Aware Forecaster and an architecture-agnostic Causal Graph Extractor.

Figure 1: Overview of the proposed causal discovery and inference framework. The framework consists of two key components. (a) The causality-aware forecaster learns to predict target variables from input variables, while implicitly capturing causal dependencies during the training process. It also incorporates prior knowledge, when available, by applying attention masks to explicitly constrain the variable dependencies. (b) The causal graph extractor computes the gradients of the forecaster with respect to the target variables, extracting causal links and constructing a corresponding causal graph. The framework supports iterative human-in-the-loop refinement, enabling users to modify the generated causal graph and integrate these modifications as prior knowledge to further refine the forecaster.
  1. Causality-Aware Forecaster: The model uses a multi-layer, stacked Transformer architecture to predict future values of target variables based on the history of source variables. To handle long sequences, it partitions time-series data into patches and applies 1D convolutions hierarchically to extract multi-resolution temporal features.
  2. Prior Knowledge Integration via Attention Masking: To prevent the model from learning spurious correlations, users can specify excluded causal links. The framework enforces these constraints using binary attention masks across all Transformer layers. Crucially, by strictly separating source ($X$) and target ($Y$) variables, the architecture prevents forbidden causal information from propagating through intermediate layers.
  3. Causal Graph Extractor: Once the forecaster is trained, a model-agnostic, gradient-based module analyzes the forecaster's gradients with respect to the target variables. Large gradients indicate a strong causal link, and the specific timing of these gradients reveals the exact causal lag. These scores are normalized and thresholded to construct the final directed causal graph.

Datasets

The framework was evaluated on three distinct datasets:

  • Basic Structures: A synthetic dataset modeling four foundational causal structures with additive random noise: fork, V-structure, mediator, and diamond.
  • Lorenz96: A dataset simulated using the nonlinear Lorenz-96 model, widely used to benchmark climate dynamics and chaotic systems.
  • NetSim: A realistic simulation of functional MRI (fMRI) brain networks containing 28 diverse networks with varying node counts (5 to 50) and topologies.

Key Insights and Ideas

  • Overcoming Attention Propagation: The paper's core architectural "aha moment" is the realization that simply applying an attention mask to a standard multi-layer Transformer isn't enough to enforce prior constraints. In a standard setup, Variable A can still influence Variable C through an unmasked intermediate Variable B over multiple layers. Separating source and target variable groups entirely blocks this multi-layer information bleeding.
  • Gradients as Causal Interpreters: Instead of relying purely on attention weights (which can be noisy and hard to interpret across multiple layers), the authors use input-output gradients to extract causal links. This makes the graph extraction step entirely architecture-agnostic.
  • Human-in-the-Loop Refinement: The framework supports an iterative refinement process. If the extracted causal graph contains a known spurious correlation, a domain expert can manually prune that edge, update the attention mask, and re-run the training process to guide the model toward a more accurate causal structure.

Key Results

The proposed method was compared against several state-of-the-art (SOTA) baselines, including cMLP, cLSTM, TCDF, DVGNN, CUTS, and CausalFormer.

  • Causal Graph Reconstruction (F1-Score): The framework consistently outperformed all baselines, showing an F1-score improvement of 9.4% on the Basic Structures dataset, 15% on Lorenz96, and 14% on NetSim (Table 1 in the paper).
  • Causal Lag Estimation (Precision of Delay - PoD): The model accurately identified the exact time lags for 97.8% of edges in Basic Structures, 99% in Lorenz96, and 100% in NetSim, significantly outperforming alternative deep learning methods (Table 2 in the paper).

Limitations and Future Work

While highly effective, the authors note a few limitations that pave the way for future research:

  • Irregularly Sampled Data: The current framework assumes time-series data is regularly sampled and uses interpolation to handle missing values. Integrating continuous-time Transformer architectures (like Contiformer) could better accommodate irregular real-world data.
  • Context-Dependent Causality: The framework maps static causal graphs. However, in many real-world systems, causal structures change depending on the system's current state or context. Moving beyond static graph representations remains an open challenge.

Summary updated

BibTeX
@misc{huang2025transforming,
  author = {Jihua Huang and Yi Yao and Ajay Divakaran},
  title = {{Transforming Causality: Transformer-Based Temporal Causal Discovery with Prior Knowledge Integration}},
  year = {2025},
  eprint = {2508.15928},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2508.15928},
}
Figure