Skip to main content
QUICK REVIEW

[Paper Review] Towards Mechanistic Interpretability of Graph Transformers via Attention Graphs

Batu El, Deepankar Choudhury|ArXiv.org|Feb 17, 2025
Advanced Graph Neural NetworksComputer Science3 citations
TL;DR

Introduces Attention Graphs to mechanistically interpret Graph Neural Networks and Graph Transformers by aggregating attention matrices into a unified information-flow graph; analyzes how learned attention patterns relate to input graph topology across homophilous and heterophilous graphs.

ABSTRACT

We introduce Attention Graphs, a new tool for mechanistic interpretability of Graph Neural Networks (GNNs) and Graph Transformers based on the mathematical equivalence between message passing in GNNs and the self-attention mechanism in Transformers. Attention Graphs aggregate attention matrices across Transformer layers and heads to describe how information flows among input nodes. Through experiments on homophilous and heterophilous node classification tasks, we analyze Attention Graphs from a network science perspective and find that: (1) When Graph Transformers are allowed to learn the optimal graph structure using all-to-all attention among input nodes, the Attention Graphs learned by the model do not tend to correlate with the input/original graph structure; and (2) For heterophilous graphs, different Graph Transformer variants can achieve similar performance while utilising distinct information flow patterns. Open source code: https://github.com/batu-el/understanding-inductive-biases-of-gnns

Motivation & Objective

  • Motivate and formalize mechanistic interpretability for GNNs and Graph Transformers using attention as a proxy for information flow.
  • Develop Attention Graphs to aggregate multi-head and multi-layer attention into a single, interpretable representation.
  • Investigate how different graph inductive biases (sparse/dense, fixed/learned attention) affect information flow and reliance on input graph structure across datasets with varying homophily.

Proposed method

  • Map GNN/GT message passing to self-attention mechanisms and define attention matrices per layer/head.
  • Define a design space for Graph Transformers along sparsity (sparse vs dense) and parametrization (constant vs learned) of attention (SC, SL, DLB, DL).
  • Propose aggregation of attention across heads by simple averaging to form layer-wise A_l.
  • Propose aggregation across layers via matrix multiplication A_Agg = A_L2 A_L1 to capture multi-hop information flow.
  • Construct and analyze Attention Graphs by thresholding to quasi-adjacency matrices and comparing to input graphs using F1 scores (for structure recovery).
  • Employ experiments on seven node-classification datasets spanning homophilous and heterophilous graphs, with 1–2 layers and 1–2 heads, using PyTorch TransformerEncoder to implement architectures.

Experimental results

Research questions

  • RQ1How can attention matrices from multiple heads and layers be aggregated into a single Attention Graph that captures information flow in GNNs/GTs?
  • RQ2How do different Graph Transformer inductive biases (SC, SL, DLB, DL) influence the reliance on input graph structure and the patterns of information flow on homophilous versus heterophilous graphs?
  • RQ3Do Graph Transformers recover the input graph structure through learned attention, and how does depth affect this?

Key findings

  • Attention Graphs reveal that when attention is not constrained to the input graph, learned information flow deviates from the input topology for both homophilous and heterophilous graphs.
  • On heterophilous graphs, different GT variants achieve similar performance but use distinct information-flow patterns, indicating diverse underlying algorithms.
  • DL models tend to distribute attention across all nodes (dense attention) and exhibit reference-node patterns, whereas DLB models show strong locality and self-attention, suggesting different computation strategies.
  • DL models show low F1-scores (<4%) for recovering input graph structure, while DLB models achieve moderate to high F1-scores (28-86%), with decreases as depth increases.
  • Aggregating across heads via simple averaging effectively captures overall information flow without losing major signals.
  • Aggregating across layers via matrix multiplication captures indirect, multi-hop information flow, illustrating how information propagates through successive layers.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.