Causal Interpretation of Self-Attention in Pre-Trained Transformers

R. Y. Rohekar, Yaniv Gurwicz, Shami Nisimov
2/12/2026

Official code: IntelLabs/causality-lab (250 stars, Apache-2.0, last commit 2025-07-10).

Abstract

We propose a causal interpretation of self-attention in the Transformer neural network architecture. We interpret self-attention as a mechanism that estimates a structural equation model for a given input sequence of symbols (tokens). The structural equation model can be interpreted, in turn, as a causal structure over the input symbols under the specific context of the input sequence. Importantly, this interpretation remains valid in the presence of latent confounders. Following this interpretation, we estimate conditional independence relations between input symbols by calculating partial correlations between their corresponding representations in the deepest attention layer. This enables learning the causal structure over an input sequence using existing constraint-based algorithms. In this sense, existing pre-trained Transformers can be utilized for zero-shot causal-discovery. We demonstrate this method by providing causal explanations for the outcomes of Transformers in two tasks: sentiment classification (NLP) and recommendation.

View on arXivView PDF

Code Implementations(1)

Apache-2.0

Causal discovery algorithms and tools for implementing new ones

25031Python, Jupyter NotebookNov 25, 20211 years agoApache-2.0
causal-discoverycausal-reasoningcausality-algorithmsconstraint-based-causalityexplainable-ai+1 more

Similar Papers

Cite this paper

@article{rohekar2026causal,
  title  = {Causal Interpretation of Self-Attention in Pre-Trained Transformers},
  author = {R. Y. Rohekar and Yaniv Gurwicz and Shami Nisimov},
  year   = {2026},
  eprint = {2310.20307},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2310.20307},
  journal = {NEURIPS 2023 2023}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2310.20307.svg)](https://codeofpaper.com/paper/2310.20307)

Discussion