GraphiT: Encoding Graph Structure in Transformers
Abstract
We show that viewing graphs as sets of node features and incorporating structural and positional information into a transformer architecture is able to outperform representations learned with classical graph neural networks (GNNs). Our model, GraphiT, encodes such information by (i) leveraging relative positional encoding strategies in self-attention scores based on positive definite kernels on graphs, and (ii) enumerating and encoding local sub-structures such as paths of short length. We thoroughly evaluate these two ideas on many classification and regression tasks, demonstrating the effectiveness of each of them independently, as well as their combination. In addition to performing well on standard benchmarks, our model also admits natural visualization mechanisms for interpreting graph motifs explaining the predictions, making it a potentially strong candidate for scientific applications where interpretation is important..
Benchmark Results
Tested on 3 datasets 1 baseline value reported too low
Tables show presented results in global context (best 3 papers + GCN + MLP).
TU Dortmund
| # | Model | Accuracy ↑ | Paper |
|---|---|---|---|
| 1 | MSH-GNN | 0.9910
±0.0030 | |
| 2 | ID-GNN+BEC | 0.9830
±0.0360 | |
| 3 | SupCosine | 0.9830
±0.0250 | |
| 39 | GIN | 0.9330
±0.0290 best reported | best at pub: CogDL: A Comprehensive Library for Graph Deep Learning (WWW 2021) best today: ProtGNN: Towards Self-Explaining Graph Neural Networks (AAAI 2021) |
| 63 | GCN | 0.9220
±0.0440 best reported | best at pub: Breaking the Limits of Message Passing Graph Neural Networks (ICML 2021) best today: Depth-Adaptive Graph Neural Networks via Learnable Bakry-Émery Curvature (KDD 2025) Difference within reported uncertainty; not counted as underperformance. |
| 153 | T + GCKN + Adj PE | 0.9050
±0.0700 | This paper |
| 158 | GraphSAGE | 0.9040
±0.0780 | |
| 183 | GAT | 0.9010
±0.0580 best reported | best at pub: Breaking the Limits of Message Passing Graph Neural Networks (ICML 2021) best today: The Expressive Power of Graph Neural Networks: A Survey (2023) Difference within reported uncertainty; not counted as underperformance. |
| 349 | GCKN-subtree | 0.8780
±0.0940 | This paper |
| 385 | T + Adj PE | 0.8720
±0.0980 | This paper |
| 403 | MLP | 0.8660
±0.0495 | |
| 429 | T + LapPE | 0.8580
±0.0590 | This paper |
| 443 | T + 2-step RW kernel | 0.8530
±0.0690 | This paper |
| 477 | T + GCKN | 0.8440
±0.0780 | This paper |
| 539 | T + Diffusion kernel | 0.8270
±0.0760 | This paper |
| 563 | Transformers (T) | 0.8220
±0.0630 | This paper |
| 582 | MF | 0.8150
±0.1100 | This paper |
| 639 | dwivedi2021generalization | 0.7930
±0.1160 | This paper |
| # | Model | Accuracy ↑ | Paper |
|---|---|---|---|
| 1 | WL-MLP | 0.9954 | |
| 2 | GIN | 0.9934 best reported | best at pub: Provably Powerful Graph Networks (NeurIPS 2019) best today: 1-WL Expressiveness Is (Almost) All You Need (2022) |
| 3 | GCN | 0.9727 best reported | best at pub: Hierarchical Graph Capsule Network (AAAI 2020) best today: 1-WL Expressiveness Is (Almost) All You Need (2022) |
| 4 | GAT | 0.7680
±0.0210 | prev best: Contrastive Self-supervised Learning for Graph Classification (AAAI 2020) best today: 1-WL Expressiveness Is (Almost) All You Need (2022) Improvement within reported uncertainty; not highlighted. |
| 131 | GraphSAGE | 0.8200
±0.0100 | |
| 161 | T + GCKN + Adj PE | 0.8140
±0.0220 | This paper |
| 190 | MF | 0.8060
±0.0250 | This paper |
| 240 | T + Adj PE | 0.7970
±0.0200 | This paper |
| 246 | GCKN-subtree | 0.7960
±0.0180 | This paper |
| 271 | dwivedi2021generalization | 0.7890
±0.0110 | This paper |
| 272 | T + Diffusion kernel | 0.7890
±0.0160 | This paper |
| 316 | T + GCKN | 0.7810
±0.0510 | This paper |
| 320 | T + 2-step RW kernel | 0.7800
±0.0150 | This paper |
| 420 | T + LapPE | 0.7460
±0.0190 | This paper |
| 483 | Transformers (T) | 0.7000
±0.0450 | This paper |
| # | Model | Accuracy ↑ | Paper |
|---|---|---|---|
| 1 | MSH-GNN | 0.9410
±0.0330 | |
| 2 | GRDL | 0.8260
±0.0120 | |
| 3 | GMN | 0.8225 | |
| 32 | GIN | 0.7880
±0.0410 best reported | best at pub: Breaking the Limits of Message Passing Graph Neural Networks (ICML 2021) best today: Permutation-Invariant graph partitioning: How graph neural networks capture structural interactions? (2023) Difference within reported uncertainty; not counted as underperformance. |
| 49 | GAT | 0.7800
±0.0300 best reported | best at pub: Breaking the Limits of Message Passing Graph Neural Networks (ICML 2021) best today: CI-GNN: A Granger Causality-Inspired Graph Neural Network for Interpretable Brain Network-Based Psychiatric Diagnosis (2023) Difference within reported uncertainty; not counted as underperformance. |
| 67 | SAGE | 0.7726
±0.0228 | |
| 148 | GCN | 0.7580
±0.0550 | prev best: Hierarchical Graph Capsule Network (AAAI 2020) Improvement within reported uncertainty; not highlighted. |
| 149 | MLP | 0.7600
±0.0320 | |
| 188 | Transformers (T) | 0.7560
±0.0490 | This paper |
| 284 | T + LapPE | 0.7460
±0.0270 | This paper |
| 285 | T + Diffusion kernel | 0.7460
±0.0420 | This paper |
| 374 | T + 2-step RW kernel | 0.7280
±0.0450 | This paper |
| 393 | T + Adj PE | 0.7240
±0.0490 | This paper |
| 411 | GCKN-subtree | 0.7200
±0.0370 | This paper |
| 414 | MF | 0.7190
±0.0520 | This paper |
| 439 | T + GCKN + Adj PE | 0.7110
±0.0690 | This paper |
| 458 | Dwivedi and Bresson + LapPE | 0.7010
±0.0320 | This paper |
| 463 | T + GCKN | 0.6950
±0.0380 | This paper |
| 480 | Dwivedi and Bresson | 0.6580
±0.0310 | This paper |
