Pure Transformers are Powerful Graph Learners

Jinwoo Kim, Tien Dat Nguyen, Seonwoo Min, Sungjun Cho, Moontae Lee, Honglak Lee, Seunghoon Hong

Abstract

We show that standard Transformers without graph-specific modifications can lead to promising results in graph learning both in theory and practice. Given a graph, we simply treat all nodes and edges as independent tokens, augment them with token embeddings, and feed them to a Transformer. With an appropriate choice of token embeddings, we prove that this approach is theoretically at least as expressive as an invariant graph network (2-IGN) composed of equivariant linear layers, which is already more expressive than all message-passing Graph Neural Networks (GNN). When trained on a large-scale graph dataset (PCQM4Mv2), our method coined Tokenized Graph Transformer (TokenGT) achieves significantly better results compared to GNN baselines and competitive results compared to Transformer variants with sophisticated graph-specific inductive bias.

Introduction

Graph learning has traditionally been dominated by Message-Passing Neural Networks (MPNNs), which utilize neighborhood aggregation to update node representations. While effective, MPNNs face inherent limitations, including "oversmoothing"—where node features become indistinguishable in deep networks—and restricted expressivity, as they cannot distinguish certain non-isomorphic graphs.

Recent attempts to adapt Transformers for graph data typically involve "baking in" graph-specific inductive biases, such as restricting attention to local neighbors or incorporating complex attention biases based on shortest-path distances. While these specialized Graph Transformers perform well, they are often complex, difficult to scale, and incompatible with the latest efficiency optimizations (e.g., linear attention) developed for standard Transformers in NLP and Vision. This research introduces TokenGT (Tokenized Graph Transformer), asking whether a powerful graph learner can be built using a standard Transformer without any graph-specific architectural modifications.

The TokenGT Framework

TokenGT treats a graph as a "bag of tokens" and processes them using a standard Transformer encoder. The core innovation lies in the input representation rather than the architecture itself:

  1. Node and Edge Tokenization: Every node and every edge in the graph is treated as an independent token. For a graph with $n$ nodes and $m$ edges, the Transformer receives a sequence of $n + m$ tokens.
  2. Orthonormal Node Identifiers: To enable the model to perceive graph structure, each node is assigned an orthonormal vector $P \in \mathbb{R}^{n \times d_p}$.
  3. Node tokens are augmented with their own identifier twice: $[X_v, P_v, P_v]$.
  4. Edge tokens connecting nodes $u$ and $v$ are augmented with the identifiers of their endpoints: $[X_{(u,v)}, P_u, P_v]$. This allows the self-attention mechanism to recognize connectivity; the dot product of identifiers between an edge and its incident nodes will be high, while others will be zero.

  5. Type Identifiers: A simple trainable embedding is added to distinguish whether a token represents a node or an edge.

  6. Standard Architecture: These augmented tokens are projected and fed into a vanilla Transformer (identical to BERT or ViT). No special attention masks or biases are required.

Theoretical Expressivity

A key contribution of this work is the proof that TokenGT is at least as expressive as a 2-order Invariant Graph Network (2-IGN). This is significant because 2-IGNs are known to be more powerful than all message-passing GNNs and are equivalent to the 2-Weisfeiler-Lehman (WL) graph isomorphism test. By using orthonormal identifiers, the model reconstructs the topology purely through the relationships between node and edge tokens in the high-dimensional embedding space, effectively deriving structure from incidence.

Experimental Evaluation

The model was evaluated on several benchmarks, most notably PCQM4Mv2, a massive quantum chemistry dataset containing 3.7 million molecular graphs.

  • Performance: TokenGT (using Laplacian eigenvectors as identifiers) achieved a Mean Absolute Error (MAE) of 0.0910, significantly outperforming standard GNNs like GIN (0.1083) and GCN (0.1153). It achieved competitive results with specialized models like Graphormer (0.0864) despite having far less graph-specific engineering.
  • Ablation Studies: Results showed that a standard Transformer without node/edge identifiers fails completely (MAE of 0.2340), confirming that the token augmentation strategy is the critical component for learning graph structures.
  • Scaling and Efficiency: Because TokenGT uses a "pure" Transformer, it is compatible with efficient $O(N)$ attention variants like the Performer. Experiments showed that swapping standard attention for linear attention resulted in minimal performance loss, enabling the model to handle much larger graphs than specialized Graph Transformers that rely on dense attention biases.

Discussion and Limitations

While TokenGT offers a streamlined approach to graph learning, it faces certain challenges:

  • Sequence Length: Treating every edge as a token increases the sequence length to $n+m$. In dense graphs, this can become a computational bottleneck.
  • Identifier Choice: While Laplacian eigenvectors are effective, they possess known issues like sign ambiguity. Future work may explore more robust positional encodings.
  • Data Requirements: As a "pure" Transformer, TokenGT likely requires large-scale datasets to learn to interpret implicit graph structures, potentially making it less suitable for small-scale datasets where strong inductive biases are more beneficial.

Conclusion

TokenGT demonstrates that the standard Transformer architecture is a highly capable graph learner when provided with the correct input representation. By treating nodes and edges as tokens and utilizing orthonormal identifiers, TokenGT achieves a theoretical expressivity beyond MPNNs and delivers state-of-the-art performance on large-scale benchmarks without the need for graph-specific architectural modifications.

Summary updated

BibTeX
@inproceedings{kim2022pure,
  author = {Jinwoo Kim and Tien Dat Nguyen and Seonwoo Min and Sungjun Cho and Moontae Lee and Honglak Lee and Seunghoon Hong},
  title = {{Pure Transformers are Powerful Graph Learners}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2022},
  url = {https://openreview.net/forum?id=um2BxfgkT2_},
}
Figure