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.
Introduction
Transformers have revolutionized Natural Language Processing (NLP) through their ability to model long-range dependencies via global self-attention. However, their application to graph-structured data is hindered by their inherent "permutation invariance." To a standard Transformer, a graph is merely a collection of nodes; it lacks an intrinsic understanding of neighborhood connectivity or global topology.
Traditional Graph Neural Networks (GNNs) address this by aggregating information from local neighborhoods. While effective at capturing local structure, GNNs often struggle with long-range information propagation. GraphiT aims to bridge this gap, combining the global communication capabilities of Transformers with the structural inductive biases characteristic of GNNs.
Methodology
GraphiT incorporates graph structure into the Transformer architecture through three primary mechanisms:
- Relative Positional Encoding via Graph Kernels: The attention mechanism is modulated by structural similarity between nodes. By using positive definite kernels—such as Diffusion kernels and p-step random walk kernels—to weight attention scores, the model is biased toward nodes that are structurally proximal. This serves as a topological "map" for the self-attention mechanism.
- Encoding Topological Structures (GCKN): Prior to the Transformer layers, Graph Convolutional Kernel Networks (GCKN) are used to enumerate and encode local sub-structures (e.g., short paths) into initial node features. This ensures the model begins with a rich representation of each node's immediate neighborhood.
- Symmetric Attention: The architecture utilizes the same projection matrix for both "Keys" and "Queries" in the attention layer. This ensures the attention mechanism defines a symmetric positive definite kernel on node pairs, aligning with recent theoretical recommendations for graph representation learning.
Experimental Results
The researchers evaluated GraphiT across several standard benchmarks, including graph classification (MUTAG, PROTEINS, PTC, NCI1) and graph regression (ZINC).
As shown in Table 1, GraphiT demonstrated significant performance gains over both traditional GNNs and previous Graph Transformer attempts:
- ZINC Regression: GraphiT achieved a Mean Absolute Error (MAE) of 0.211, significantly outperforming the previous state-of-the-art Graph Transformer (0.323) and standard GNNs like GIN (0.387).
- Classification: On datasets like MUTAG and NCI1, GraphiT reached accuracies of 90.5% and 81.4% respectively, frequently outperforming specialized GNN baselines.
- Ablation Studies: The results confirm that combining GCKN (local features) with kernel-based attention (relative positions) yields the best performance, validating the necessity of both local and global structural information.
Discussion and Conclusion
GraphiT challenges the notion that Transformers must be restricted to local neighborhoods to be effective on graphs. By providing sufficient structural bias through kernels, global communication becomes a powerful tool for graph representation. Furthermore, the model's attention mechanism provides built-in interpretability, allowing researchers to visualize the graph motifs that drive specific predictions.
Future work will address the $O(n^2)$ computational complexity of the self-attention mechanism to improve scalability for massive graphs. Additionally, incorporating edge features (such as bond types in molecular graphs) into the kernel definitions represents a promising avenue for further enhancing the model's predictive power.
Summary updated