GraphFormers: GNN-nested Transformers for Representation Learning on Textual Graph

Junhan Yang, Zheng Liu, Shitao Xiao, Chaozhuo Li, Defu Lian, Sanjay Agrawal, Amit Singh, Guangzhong Sun, Xing Xie

TL;DR

GraphFormers introduces a novel architecture that nests Graph Neural Network (GNN) components directly within the layers of a Transformer. By iteratively fusing text encoding and graph aggregation, the model allows nodes to "understand" their own text through the lens of their neighbors' semantics, significantly outperforming traditional cascaded models on large-scale textual graphs.

What Problem Does This Paper Address?

Textual graphs—networks where nodes contain text (like citation networks or e-commerce product graphs)—are ubiquitous. The standard approach to representing these graphs involves a "cascaded" architecture: first, a Pretrained Language Model (PLM) like BERT encodes each node's text in isolation; then, a GNN aggregates these static embeddings across the graph.

The authors argue this is fundamentally flawed. Because the text encoding happens independently, the model misses out on mutual semantic enhancement. For example, the word "transformer" in a research paper title is ambiguous until you see that its neighbors are about "machine translation" rather than "power grids." Cascaded models only realize this connection after the text has already been compressed into a fixed vector.

Methods

The core innovation is the GNN-nested Transformer. Instead of stacking a GNN on top of a Transformer, GraphFormers interweaves them.

Figure 1: Model architecture comparison (a center node C is connected with two neighbours N1, N2). (A) Cascaded Transformers-GNN: text embeddings are independently generated by language models and aggregated by rear-mounted GNNs. (B) GNN-nested Transformers: the text encoding and graph aggregation are iteratively performed with the layerwise GNNs and Transformers (TRM).
  1. Iterative Fusion: In each layer, the model performs graph aggregation (gathering info from neighbors) and then uses that information to augment the token-level text encoding for the next layer. This allows the model to iteratively refine its understanding of a node's text based on its neighborhood.
  2. Unidirectional Graph Aggregation: To prevent a computational explosion where every node depends on every other node's full encoding at every step, the authors use a unidirectional approach. Only the "center" node (the one being represented) attends to its neighbors. The neighbors are encoded independently, allowing their intermediate states to be cached and reused, keeping the running cost comparable to standard Transformers.
  3. Two-Stage Progressive Learning: Deep models are often "lazy"—if the center node's text is clear enough, the model might ignore the neighbors entirely. To fix this, the authors first train on "polluted" data (randomly masking tokens in the center node) to force the GNN to learn effective message passing. They then fine-tune on the original, unpolluted data.

Datasets

The model was evaluated on three million-scale textual graph datasets:

  • DBLP: A paper citation graph using titles as textual features.
  • Wikidata5M (Wiki): An entity graph from Wikipedia using the first sentence of each entity's introduction.
  • Product Graph: An e-commerce dataset where nodes are products connected by user browsing sessions (co-viewing), using product descriptions as text.

Key Insights and Ideas

  • Semantics and Structure are Inseparable: The "aha moment" here is that text encoding shouldn't be a preprocessing step for graph learning. By nesting the GNN, the Transformer's attention mechanism can be conditioned on graph structure at every level of abstraction.
  • Forcing the "Shortcut" to Close: The progressive learning strategy is a clever way to handle the "informative center node" problem. By temporarily "blinding" the model to the center node's full text, they ensure the GNN components are actually doing heavy lifting.
  • Efficiency is Possible: Usually, deep integration of GNNs and Transformers is too slow for production. The unidirectional simplification and caching strategy prove that you can get the benefits of deep fusion without a massive hit to latency.

Key Results

GraphFormers consistently outperformed all SOTA baselines, including powerful cascaded PLM+GNN combinations.

Table 2: Overall evaluation (GraphFormers marked in bold, the best baseline underlined). Graph- Formers outperforms all baselines, especially the ones based on cascaded Transformers-GNN.
  • Accuracy Gains: The model achieved relative improvements of 2.9%, 4.8%, and 6.5% over the most competitive baselines on the three datasets, respectively.
  • Efficiency: Despite the nested architecture, the time and memory costs remained very close to the cascaded PLM+Max baseline. For instance, with 5 neighbors, GraphFormers took ~97ms per mini-batch compared to ~93ms for the baseline.
  • Real-world Impact: The authors deployed GraphFormers as an ads retrieval algorithm on Bing Search, where it significantly improved revenue per thousand impressions (RPM) and click yield (CY) in a large-scale A/B test.

Limitations and Future Work

The authors note that the form of the graph aggregator matters. While GraphFormers excels, GNNs in general can be vulnerable on heterogeneous graphs (like Wiki) where connections have highly varied semantics. If a neighbor is connected via a relationship that doesn't clarify the center node's text, the added information might just be noise.

Future work could explore more sophisticated ways to handle these diverse relationship types within the nested architecture or scaling the approach to even denser graphs where unidirectional caching might face memory bottlenecks.

Summary updated

BibTeX
@inproceedings{yang2021graphformers,
  author = {Junhan Yang and Zheng Liu and Shitao Xiao and Chaozhuo Li and Defu Lian and Sanjay Agrawal and Amit Singh and Guangzhong Sun and Xing Xie},
  title = {{GraphFormers: GNN-nested Transformers for Representation Learning on Textual Graph}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2021},
  url = {https://openreview.net/forum?id=6NDG0kX4ey},
}
Figure