Abstract
Although Transformer has achieved great success in natural language processing and computer vision, it has difficulty generalizing to medium and large-scale graph data for two important reasons: (i) High complexity. (ii) Failing to capture the complex and entangled structure information. In graph representation learning, Graph Neural Networks (GNNs) can fuse the graph structure and node attributes but have limited receptive fields. Therefore, we question whether we can combine Transformers and GNNs to help each other. In this paper, we propose a new model named TransGNN where the Transformer layer and GNN layer are used alternately to improve each other. Specifically, to expand the receptive field and disentangle the information aggregation from edges, we propose using Transformer to aggregate more relevant nodes' information to improve the message passing of GNNs. Besides, to capture the graph structure information, we utilize positional encoding and make use of the GNN layer to fuse the structure into node attributes, which improves the Transformer in graph data. We also propose to sample the most relevant nodes for Transformer and two efficient sample update strategies to lower the complexity. At last, we theoretically prove that TransGNN is more expressive than GNNs only with extra linear complexity. The experiments on eight datasets corroborate the effectiveness of TransGNN on node and graph classification tasks.
Introduction
In graph representation learning, particularly within Collaborative Filtering (CF) and recommender systems, Graph Neural Networks (GNNs) have become the standard approach. They operate via "message passing," where nodes (users and items) update their representations by aggregating information from their immediate neighbors. However, GNNs face two significant hurdles:
- Limited Receptive Fields: Stacking many GNN layers to reach distant nodes often leads to "over-smoothing," where node embeddings become indistinguishable. Consequently, most models are limited to 2-3 hops, missing critical long-range dependencies.
- Noisy Connections: Not every interaction in a graph is meaningful. Popularity bias or accidental clicks create "interest-irrelevant" edges that GNNs aggregate indiscriminately.
Transformers offer a potential solution through global self-attention, which can weigh the importance of any node in the graph. However, standard Transformers suffer from $O(N^2)$ computational complexity and a lack of inherent understanding of graph topology.
The TransGNN Framework
TransGNN addresses these issues by integrating Transformer and GNN architectures in an alternating fashion. This hybrid approach allows the Transformer to expand the GNN's horizon to distant but relevant nodes, while the GNN provides the structural grounding that Transformers typically lack.
Key Methodologies
- Attention Sampling Module: To avoid the quadratic complexity of global attention, TransGNN samples the top-$k$ most relevant nodes for each user or item. Relevance is determined by a combination of semantic similarity (node attributes) and structural preference.
- Graph-Aware Positional Encoding: To inject structural awareness into the Transformer, the model utilizes three types of encoding: Shortest Path (SPE), Degree (DE), and PageRank (PRE).
- Alternating Layers and Sample Updates: The architecture passes data through a Transformer layer for long-range capture and then a GNN layer for local structural refinement. As embeddings evolve during training, the model uses an efficient message-passing-based strategy to update the sampled relevant nodes without re-calculating global similarity.
Experimental Results and Insights
The model was evaluated on diverse large-scale datasets, including Yelp, Amazon-Book, and MovieLens 10M. The results demonstrate several key advantages:
- Superior Accuracy: TransGNN consistently outperformed state-of-the-art baselines like LightGCN and SHT. For instance, on the Yelp dataset, it achieved a 21.04% improvement in Recall@20 over the best baseline.
- Depth Resilience: Unlike standard GNNs that degrade after a few layers due to over-smoothing, TransGNN remains stable or improves even at 5 layers deep, successfully capturing long-range dependencies.
- Efficiency: By utilizing a sampled top-$k$ approach, TransGNN reduces complexity from quadratic to linear. It proved to be 30-40% faster in training and inference than NGCF while maintaining a lower GPU memory footprint than other Transformer-graph hybrids.
- Theoretical Expressiveness: The authors prove that TransGNN is more expressive than the standard 1-WL (Weisfeiler-Lehman) test, meaning it can distinguish complex graph structures that standard GNNs cannot.
Conclusion
TransGNN successfully bridges the gap between the local structural precision of GNNs and the global reach of Transformers. By introducing efficient attention sampling and graph-aware encodings, it provides a scalable solution for large-scale graph representation tasks. Future work may involve more sophisticated noise filtering for edges and applying the TransGNN framework to broader domains like social network analysis and molecular biology.
Summary updated