Abstract
Graphormer demonstrates that the standard Transformer architecture, when equipped with appropriate structural biases, can significantly outperform traditional Graph Neural Networks (GNNs). By introducing novel encodings for node centrality, spatial distance, and edge features, the authors achieved state-of-the-art results on major benchmarks, including winning the Open Graph Benchmark Large-Scale Challenge (OGB-LSC).
Introduction
While Transformers have revolutionized Natural Language Processing (NLP) and Computer Vision (CV), they have historically struggled to compete with GNNs in graph representation learning. GNNs utilize a "message-passing" scheme where nodes aggregate information from their immediate neighbors. In contrast, the standard Transformer’s self-attention mechanism treats all nodes as a sequence, effectively ignoring the rich structural and topological information that defines a graph. This paper addresses a fundamental question: Is the Transformer architecture inherently unsuitable for graphs, or are we simply missing a way to feed it structural information?
The Graphormer Architecture
The authors introduce Graphormer, which stays remarkably close to the standard Transformer architecture but adds three key structural encodings to the input and attention layers to capture graph topology.
- Centrality Encoding: To capture node importance (e.g., a "celebrity" node in a social network), the model adds learnable embedding vectors based on the node's degree (in-degree and out-degree) to the initial node features.
- Spatial Encoding: To help the model understand the geometry of the graph, the authors use the Shortest Path Distance (SPD) between any two nodes as a bias term in the self-attention module. This allows the model to adaptively attend more to nearby nodes or distant ones depending on the task.
- Edge Encoding: In many graphs, such as molecules, edges have their own features (e.g., bond types). Graphormer incorporates these by calculating an average of edge features along the shortest path between two nodes and adding this to the attention score.
Additionally, the model introduces a Virtual Node [VNode]. Similar to the [CLS] token in BERT, this special node is connected to every other node in the graph, serving as a global aggregator for graph-level representations.
Theoretical Advantages
Graphormer offers several theoretical advantages over traditional GNNs:
- GNNs as Special Cases: The authors mathematically demonstrate that Graphormer is a more powerful generalization of popular GNNs like GIN, GCN, and GraphSAGE. By choosing specific weights, a Graphormer layer can perfectly simulate the aggregate-combine steps of these models.
- Beyond the 1-WL Test: Most GNNs are limited by the 1-Weisfeiler-Lehman (WL) test, meaning they cannot distinguish between certain non-isomorphic graph structures. Graphormer’s spatial encoding allows it to distinguish structures that the 1-WL test fails on.
- Global Receptive Field: Unlike GNNs, which require many layers to pass information across a large graph, every node in a Graphormer can "see" every other node in a single layer. The spatial encoding ensures this global view is tempered by the actual graph topology.
Experimental Results
Graphormer was evaluated on several high-profile benchmarks, including PCQM4M-LSC (a massive quantum chemistry dataset with over 3.8 million graphs), ZINC, and various OGB graph-level tasks.
Graphormer won the graph-level track of the KDD Cup 2021 (OGB-LSC), outperforming the best GNN variants by more than 10% in relative error on the PCQM4M-LSC dataset. It also achieved the #1 spot on the leaderboards for ogbg-molhiv, ogbg-molpcba, and ZINC at the time of publication. Ablation studies confirmed that Spatial Encoding is the most critical component, providing a massive boost in Mean Absolute Error (MAE) compared to a vanilla Transformer.
Limitations and Future Work
Despite its success, Graphormer faces challenges regarding computational complexity. Like the original Transformer, it has $O(N^2)$ complexity relative to the number of nodes, making it difficult to apply to very large graphs (e.g., social networks with millions of nodes) without sampling or approximation techniques. Future work is needed to optimize Graphormer for node-level tasks and to leverage more sophisticated, domain-specific structural encodings beyond simple shortest-path distances.
Summary updated