TransGNN: Harnessing the Collaborative Power of Transformers and Graph Neural Networks for Recommender Systems

Peiyan Zhang, Yuchen Yan, Xi Zhang, Chaozhuo Li, Senzhang Wang, Feiran Huang, Sunghun Kim

TL;DR

TransGNN is a hybrid architecture that combines the local structural awareness of Graph Neural Networks (GNNs) with the global receptive field of Transformers for recommender systems. By employing a clever attention sampling strategy and graph-aware positional encodings, it achieves state-of-the-art performance while maintaining linear computational complexity.

What Problem Does This Paper Address?

In the world of collaborative filtering, Graph Neural Networks (GNNs) are the reigning champions for modeling user-item interactions. However, they have two major Achilles' heels:

  1. Limited Receptive Fields: Due to the "over-smoothing" problem—where node embeddings become indistinguishable as you add more layers—GNNs are typically restricted to 2-3 hops. This means they miss out on long-range dependencies.
  2. Sensitivity to Noise: GNNs propagate information along edges, but not all edges are meaningful. "Interest-irrelevant" connections (like accidental clicks or popularity bias) can introduce significant noise into the embeddings.

Transformers offer a potential solution with their global self-attention mechanism, but applying them to massive interaction graphs is computationally prohibitive ($O(N^2)$ complexity) and they lack the inherent ability to capture the intricate topological structures that GNNs excel at.

Methods

The authors propose TransGNN, a framework that alternates between Transformer and GNN layers to leverage their complementary strengths.

The overview of TransGNN framework, showing the pipeline from interaction graph to item prediction.

Key components include:

  • Attention Sampling Module: To avoid the $O(N^2)$ cost of global attention, TransGNN samples a small set of the "most relevant" nodes for each user/item. This sampling is based on a refined similarity matrix that considers both raw node attributes and the preferences of neighboring nodes.
  • Graph-Aware Positional Encoding: To inject structural knowledge into the Transformer, the authors introduce three types of encoding:
  • Shortest Path Hop: Captures proximity.
  • Degree-based: Captures node popularity or user diversity.
  • PageRank-based: Captures overall structural importance.
  • Alternating Layers: The model uses Transformer layers to broaden the receptive field (aggregating information from distant but relevant nodes) and GNN layers to refine these representations using local graph topology.
  • Dynamic Sample Updates: Since node representations evolve during training, the set of "relevant nodes" must also change. The authors propose two efficient update strategies: one based on Random Walks and another that leverages the GNN's message-passing to aggregate attention samples from neighbors.

Datasets

The model was evaluated on five diverse, real-world benchmarks:

  • Yelp: Business ratings and reviews.
  • Gowalla: Location-based social network check-ins.
  • Tmall: Large-scale e-commerce interaction data.
  • Amazon-Book: Product reviews from the Amazon ecosystem.
  • MovieLens (ML-10M): A classic benchmark for movie recommendations.

Key Insights and Ideas

  • Breaking the 1-WL Barrier: The authors theoretically prove that TransGNN is more expressive than the standard 1-WL graph isomorphism test. By using global shortest-path information, the model can distinguish graph structures that traditional GNNs find identical.
  • Efficiency through Sparsity: You don't need to look at every node to get a global view. Sampling just a few highly relevant nodes (even distant ones) provides the benefits of a Transformer without the quadratic memory and time explosion.
  • Mutual Reinforcement: The Transformer acts as a "shortcut" for the GNN, allowing information to leap across the graph, while the GNN acts as a "filter" for the Transformer, ensuring it respects the underlying graph topology.
An illustration showing how TransGNN distinguishes graphs that the 1-WL test cannot by using shortest path information.

Key Results

TransGNN consistently outperformed state-of-the-art baselines (including LightGCN, SGL, and SHT) across all datasets.

  • Accuracy: On the Yelp dataset, TransGNN achieved a 32.25% improvement in NDCG@20 over the best-performing baseline.
  • Robustness to Depth: Unlike standard GNNs, TransGNN's performance continues to improve (or at least remains stable) as the number of layers increases, effectively overcoming the over-smoothing problem.
  • Efficiency: Despite its increased expressiveness, TransGNN is highly efficient. It requires 20-30% less GPU memory and has significantly lower FLOPs than many competitive baselines because it avoids full-graph attention.

Limitations and Future Work

  • Pre-processing Overhead: The calculation of the shortest path hop matrix is a one-time cost but can be computationally expensive for extremely large, dense graphs ($O(N^2)$ in the worst case, though optimized to $O(N(N+E)\log E)$ for sparse graphs).
  • Hyperparameter Sensitivity: The performance is tied to the sampling size $k$. While the authors found that a small $k$ is often sufficient, finding the optimal value for new datasets requires tuning.
  • Future Directions: The authors suggest extending TransGNN to heterogeneous graphs (graphs with multiple types of nodes and edges) and exploring more advanced dynamic sampling strategies.

Summary updated

Abstract

Graph Neural Networks (GNNs) have emerged as promising solutions for collaborative filtering (CF) through the modeling of user-item interaction graphs. The nucleus of existing GNN-based recommender systems involves recursive message passing along user-item interaction edges to refine encoded embeddings. Despite their demonstrated effectiveness, current GNN-based methods encounter challenges of limited receptive fields and the presence of noisy "interest-irrelevant" connections. In contrast, Transformer-based methods excel in aggregating information adaptively and globally. Nevertheless, their application to large-scale interaction graphs is hindered by inherent complexities and challenges in capturing intricate, entangled structural information. In this paper, we propose TransGNN, a novel model that integrates Transformer and GNN layers in an alternating fashion to mutually enhance their capabilities. Specifically, TransGNN leverages Transformer layers to broaden the receptive field and disentangle information aggregation from edges, which aggregates information from more relevant nodes, thereby enhancing the message passing of GNNs. Additionally, to capture graph structure information effectively, positional encoding is meticulously designed and integrated into GNN layers to encode such structural knowledge into node attributes, thus enhancing the Transformer's performance on graphs. Efficiency considerations are also alleviated by proposing the sampling of the most relevant nodes for the Transformer, along with two efficient sample update strategies to reduce complexity. Furthermore, theoretical analysis demonstrates that TransGNN offers increased expressiveness compared to GNNs, with only a marginal increase in linear complexity. Extensive experiments on five public datasets validate the effectiveness and efficiency of TransGNN.
BibTeX
@inproceedings{zhang2023transgnn,
  author = {Peiyan Zhang and Yuchen Yan and Xi Zhang and Chaozhuo Li and Senzhang Wang and Feiran Huang and Sunghun Kim},
  title = {{TransGNN: Harnessing the Collaborative Power of Transformers and Graph Neural Networks for Recommender Systems}},
  booktitle = {International ACM SIGIR Conference on Research and Development in Information Retrieval},
  year = {2023},
}
Figure