Rethinking Graph Transformers with Spectral Attention
- Publication
- NeurIPS 2021Conference
- First submitted to arXiv
- arXiv:2106.03893
Cite this paper · BibTeX
The citation identifies the linked source version. It cites the original paper and its authors.
@misc{graphlearningsan2021,
title = {{Rethinking Graph Transformers with Spectral Attention}},
author = {Devin Kreuzer and Dominique Beaini and William L. Hamilton and Vincent Létourneau and Prudencio Tossou},
year = {2021},
eprint = {2106.03893},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2106.03893}
}
In 1966, mathematician Mark Kac writes “Can One Hear the Shape of a Drum?” A drum's shape determines its vibration frequencies; conversely, can those frequencies alone reveal its shape?
Graphs have frequencies too: their Laplacian eigenvalues and eigenvectors. Devin Kreuzer, Dominique Beaini, William L. Hamilton and colleagues at McGill, Mila and Valence Discovery want a Transformer to “hear” these frequencies and learn each node's position.
They also want to overturn a verdict. Six months earlier, Graph Transformer (GT) tried letting every node see every other, badly hurting all three datasets and leading its authors to favor neighbor-only attention. SAN, Spectral Attention Network, aims to show that full connectivity can work.
Defining the Problem
The authors list message passing's known limitations: WL-bounded graph discrimination, over-smoothing with depth, and over-squashing over distance. All are tied to graph structure directly determining computational routes.
A Transformer lets all positions interact and supplies structure softly, through positional encoding. For graphs, that encoding is the key.
GT already uses Laplacian eigenvectors, but the authors identify unresolved issues:
- Eigenvalues carry information too. GT supplies eigenvectors without eigenvalues. Sequence frequencies are fixed, so order identifies them; graph frequencies vary, and order alone loses the frequency corresponding to each vector.
- Repeated eigenvalues. With multiplicity, any combination within the corresponding eigenspace is a valid eigenvector.
- Variable counts. A graph has at most as many eigenvectors as nodes. Taking a fixed means using a smaller fraction on larger graphs.
- Signs. vectors have sign combinations. Random sign flips are manageable for small , less so as it grows.
Repeated eigenvalues show up even in a small graph of two triangles joined by a bridge. A, B and C are on the left, D, E and F on the right, and C and D form the bridge. Its normalized Laplacian has two eigenvalues equal to 1.5. The vector , nonzero only on A and B, the vector , nonzero only on E and F, and any combination of the two are all eigenvectors for 1.5. The value A receives may be 0.71, 0 or 0.5, depending on which one the library picks. Use that value directly as A's position, and what the model learns may change with the library.
Solving the Problem
SAN has two stages: learn a positional encoding for each node, concatenate it with node features, and feed the result into a fully connected Transformer.

Learned Positional Encoding
The right half is SAN's learned positional encoding (LPE).
For node , take the smallest eigenvalues and pair each with the corresponding eigenvector entry , producing a length- sequence. The authors view eigenvectors as sitting on a frequency axis, with eigenvalues specifying positions along it.
A linear layer maps each pair to dimensions. A Transformer encoder attends across the elements, then sums them into node 's -dimensional LPE. If the graph has fewer than nodes, masked padding fills the remainder.
This addresses three of the four issues. Eigenvalues accompany eigenvectors; sequence lengths can vary, with even reaching the largest graph size in the dataset to use the full spectrum; and the Transformer can potentially combine or ignore vectors from repeated eigenspaces. Signs remain unresolved: SAN randomly flips them during training, like GT.
The appendix also describes an edge-wise version, using sign-invariant quantities such as and as pairwise features. It is theoretically stronger but costs up to with full connectivity, so the main text uses node-wise LPE.
Full Connectivity, Two Attention Mechanisms
The left half is the main Transformer. Every nonadjacent pair gets an added connection with its own edge embedding. Original edges use , , ; added connections use , , . Hyperparameter balances their weights:
At , added connections have no weight and attention is neighbor-only; at , neither set is favored. This knob trades local structure against distant interaction. Residuals, normalization and feedforward layers follow as in GT. Edge representations are not updated: the authors say doing so adds complexity with almost no benefit.
Discussion
How Large Should Be?
The authors sweep on ZINC, PATTERN, CLUSTER and MolHIV. On molecular datasets ZINC and MolHIV, the best lies between −7 and −5, giving added connections only a tiny share. PATTERN and CLUSTER prefer larger .
The explanation is that molecular graphs are small and depend on local structures such as rings and particular bonds; a few sparse-attention layers already span the graph. CLUSTER is semi-supervised, with some true node labels provided in each graph; full connectivity exposes those labeled nodes to everyone at every layer.
Contributions of Connectivity and LPE
Keeping fixed and parameters around 500,000, the authors ablate both designs:
| Attention | LPE | ZINC (MAE ↓) | PATTERN | CLUSTER | MolHIV (ROC-AUC) |
|---|---|---|---|---|---|
| Sparse | No | 0.267 | 83.61% | 75.68% | 73.46% |
| Sparse | Yes | 0.198 | 81.33% | 75.74% | 76.61% |
| Fully connected | No | 0.392 | 86.32% | 76.45% | 73.84% |
| Fully connected | Yes | 0.157 | 86.44% | 76.69% | 77.57% |
Both factors matter. On ZINC, full connectivity without LPE worsens MAE from 0.267 to 0.392, matching GT's observation; with LPE, it becomes best at 0.157. LPE helps molecular datasets most, which the authors connect to substructure detection; PATTERN and CLUSTER are simpler clustering tasks, so its effect is smaller.
Against the Best Models of the Time
Tuned SAN reaches ZINC MAE 0.139, ahead of PNA's 0.142. PATTERN at 86.58% and CLUSTER at 76.69% also lead the table. Fully connected GT has ZINC MAE 0.598 in the same table. To the authors' knowledge, SAN is the first fully connected model to perform well on graph benchmarks.
OGB molecular results are less striking. MolHIV test ROC-AUC is 77.85%, below DGN's 79.70%. The authors note SAN's validation score of 85.30% exceeds PNA's 84.25% and DGN's 84.70%, attributing the outcome to low validation/test correlation on this dataset. MolPCBA average precision is 27.65%, versus DGN's 28.85%.
The Cost
Full attention costs , LPE , far more than message passing's , as the authors acknowledge. Later work makes the cost clearer: GraphGPS reports 196 seconds per epoch for roughly 6 million-parameter GPS on ogbg-molpcba, versus 883 seconds for SAN on the same GPU type. On LRGB's COCO-SP, with over 120,000 graphs averaging nearly 480 nodes, SAN fails to converge after 60 hours on an A100.
Conclusion
SAN demonstrates that fully connected Transformers can perform well on graphs, provided positional encodings carefully handle the spectrum and original versus added edges score separately, balanced by . Its ablation also explains GT's observation: full connectivity without good positional encoding makes things worse.
The following year, GraphGPS, also involving Beaini, treats this attention as a replaceable module alongside message passing in each layer. It also offers encodings such as SignNet specifically for sign ambiguity.
For graphs with only tens of nodes, SAN is worth trying. As graphs grow, quadratic computation becomes the first obstacle.