LIG: Layer-wise Integrated Gradients for Within-Layer Flow Analysis in Transformers

Eight Suzuki, Hideitsu Hino, Noboru MurataarXiv 2026

TL;DR

LIG (Layer-wise Integrated Gradients) is a new explainability tool designed to dissect the internal information flow within individual Transformer layers by analyzing token-to-token contributions. By extending Integrated Gradients to vector-valued, set-to-set maps via $L_2$ scalarization and composing them using Layer-wise Relevance Propagation (LRP) principles, LIG uncovers how Multi-Head Attention (ATT) and Multi-Layer Perceptrons (MLP) interact without requiring model retraining.

What Problem Does This Paper Address?

While Transformers have revolutionized natural language processing, their internal mechanics remain notoriously opaque. Most Explainable AI (XAI) methods focus on input-to-output feature attributions or rely heavily on visualizing attention maps. However, attention weights alone do not tell the whole story; they ignore the magnitudes of value vectors and the subsequent non-linear transformations performed by the MLP blocks.

Existing methods that attempt to track internal representations often incur massive computational costs, require model retraining, or demand tedious, operation-specific propagation rules. The authors address this gap by providing a framework to precisely isolate and compose the distinct contributions of the ATT and MLP modules within a single layer, shedding light on the internal "flow" of information.

Methods

The authors view each Transformer layer as a dynamic graph where the nodes represent token representations and per-head attention outputs, and the edges represent the information flow across module boundaries.

Fig. 1. Basic Transformer structure and the dynamic-graph view. A token sequence enters from the left and passes through multiple Transformer layers (each with ATT and MLP) to become a context-aware set of vectors. Within each layer, token representation vectors and per-head attention outputs are nodes; information flows at ATT and MLP module boundaries.

To map the relationships between these nodes, they introduce two key technical innovations:

  1. Set-to-Set Integrated Gradients (IG): Standard IG is designed for scalar objectives (like a classification logit). To apply it to the vector-to-vector transformations occurring inside a Transformer layer, the authors introduce an $L_2$ norm scalarization. This measures the deviation of an output vector from a baseline reference point, effectively compressing multi-dimensional token changes into a single scalar that IG can digest.
  2. Path Composition: Inspired by Layer-wise Relevance Propagation (LRP), the authors chain the attributions calculated at the ATT boundary with those at the MLP boundary.
Two views of within-layer contributions

By leveraging the mathematical "completeness" property of IG (where the sum of attributions equals the total change in output), they establish a conservation relation across module boundaries. This allows them to verify if the step-by-step path composition (ATT $\times$ MLP) matches the directly measured layer-whole attribution.

Conceptual diagram of Integrated Gradients

Datasets

The framework was evaluated using:

  • Model: Pretrained BERT-base-uncased (12 layers, 12 heads).
  • Data: Penn Treebank (PTB) dev sentences from Treebank-3 (1,700 sentences), utilizing the Stanford Dependencies format for structural evaluation.

Key Insights and Ideas

  • Baseline Selection is Critical for ATT, Less for MLP: The choice of the baseline (the "blank slate" reference point used in IG) heavily influences the accuracy of the explanation. For the Attention module, using the target token's own embedding as a reference (Input Token Base, or ITB) yielded the highest consistency. Interestingly, the MLP module proved highly robust; switching its baseline between a zero vector and the inherited ATT integration endpoint had negligible impact on the results.
  • Completeness Acts as Conservation: A major hurdle in layer-wise XAI is ensuring that the breakdown of parts equals the whole. LIG elegantly solves this by showing that IG's completeness property naturally mirrors the conservation laws of LRP, eliminating the need to engineer custom mathematical rules for every unique sub-operation in the network.
  • Macroscopic Role Shifts: Qualitative tracking across layers revealed a clear hierarchical division of labor: shallow layers focus heavily on local token neighborhoods (phrases), middle layers bridge long-range semantic and syntactic dependencies, and deep layers integrate information globally across the entire sentence.

Key Results

The authors measured the consistency between the path-composed attributions and the true layer-whole attributions using an $L_2$ distance metric ($d_j^{(l)}$), where a smaller value signifies a higher-fidelity explanation.

  • Under the Input Token Base (ITB) reference group, the configuration pairing the ITB baseline for ATT with either a Zero baseline or the inherited ATTITBa=0 baseline for the MLP achieved the lowest error, tying at a minimal $L_2$ distance of 0.214.
  • When evaluating against a global Zero baseline reference, the combination of ATT(ITB-zeroRatio) × MLP(Zero) performed best with an error of 0.769.
  • Across all experiments, changing the MLP baseline altered the consistency metric by at most $\approx 0.001$, proving that the ATT baseline selection is the dominant factor in explanation fidelity.

Limitations and Future Work

  • Computational Cost: Calculating set-to-set IG across every module boundary and attention head is computationally expensive, which restricted the quantitative evaluation to BERT-base.
  • Out-of-Distribution (OOD) Paths: Like standard IG, the straight-line interpolation path between the baseline and the input may pass through unnatural, out-of-distribution representation spaces, potentially introducing artifacts.
  • Scope: The current validation is limited to encoder architectures (BERT) and English textual data. The authors note that extending LIG to massive autoregressive Large Language Models (LLMs) and exploring non-linear integration path shapes remain vital directions for future work.

Summary updated

BibTeX
@misc{suzuki2026lig,
  author = {Eight Suzuki and Hideitsu Hino and Noboru Murata},
  title = {{LIG: Layer-wise Integrated Gradients for Within-Layer Flow Analysis in Transformers}},
  year = {2026},
  eprint = {2606.21564},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2606.21564},
}
Figure