GraphFormers: GNN-nested Language Models for Linked Text Representation

Junhan Yang, Zheng Liu, Shitao Xiao, Chaozhuo Li, Guangzhong Sun, Xing Xie · OpenReview

Abstract

The representation learning on textual graph is to generate low-dimensional embeddings for the nodes based on the individual textual features and the neighbourhood information. Recent breakthroughs on pretrained language models and graph neural networks push forward the development of corresponding techniques. The existing works mainly rely on the cascaded model architecture: the textual features of nodes are independently encoded by language models at first; the textual embeddings are aggregated by graph neural networks afterwards. However, the above architecture is limited due to the independent modeling of textual features. In this work, we propose GraphFormers, where layerwise GNN components are nested alongside the transformer blocks of language models. With the proposed architecture, the text encoding and the graph aggregation are fused into an iterative workflow, making each node's semantic accurately comprehended from the global perspective. In addition, a progressive learning strategy is introduced, where the model is successively trained on manipulated data and original data to reinforce its capability of integrating information on graph. Extensive evaluations are conducted on three large-scale benchmark datasets, where GraphFormers outperform the SOTA baselines with comparable running efficiency.

Introduction

In many real-world datasets—such as citation networks, social media, or e-commerce platforms—data is structured as a "textual graph," where nodes contain rich text features and edges represent relationships. Traditional approaches to learning representations for these graphs typically employ a "cascaded" architecture. In this setup, a Pretrained Language Model (PLM) like BERT encodes the text of each node independently, followed by a Graph Neural Network (GNN) that aggregates these frozen text embeddings across the graph's edges.

However, independent text encoding misses crucial context. Words can have multiple meanings depending on their neighbors. For example, if a node is titled "notes on transformers" and its neighbor is "tutorials on machine translation," the word "transformers" clearly refers to the machine learning model. In a cascaded architecture, the language model must infer the meaning without visibility into the neighborhood, leading to suboptimal embeddings.

Methodology: GraphFormers

To address the limitations of cascaded architectures, we propose GraphFormers, which fuses text encoding and graph aggregation into an iterative workflow.

GNN-nested Transformers

Instead of placing the GNN at the end of the model, GraphFormers nests a GNN layer alongside each Transformer block. At each layer, the model gathers the [CLS] token embeddings from a node and its neighbors. These are passed through a Multi-Head Attention GNN to create a "graph-augmented" embedding, which is then concatenated back into the token sequence for the subsequent Transformer layer to process.

Detailed architecture of the GNN-nested Transformer block showing the integration of graph information at each layer.

Unidirectional Graph Aggregation and Progressive Learning

To maintain computational efficiency, GraphFormers utilizes a unidirectional approach: only the center (target) node attends to its neighbors. This allows neighbor representations to be cached and reused.

Furthermore, to prevent the model from ignoring graph structure when node text is highly informative (the "lazy learning" problem), we introduce a two-stage progressive learning strategy. In Stage 1, the model is trained on "polluted" data (randomly masking 15% of input tokens) to force reliance on neighbor nodes. Stage 2 involves fine-tuning on clean data.

Experimental Results

GraphFormers was evaluated on three million-scale textual graph datasets: DBLP (citation graph), Wikidata5M (heterogeneous entity graph), and a Product Graph (e-commerce co-viewed products).

Performance Comparison

GraphFormers consistently outperformed state-of-the-art cascaded baselines across all datasets and metrics, as shown in the table below.

Performance comparison of GraphFormers against state-of-the-art baselines on Product, DBLP, and Wiki datasets.

Key performance highlights include:

  • Product Graph: Precision@1 improved from 0.7570 (best baseline) to 0.7786.
  • DBLP: Precision@1 improved from 0.6934 to 0.7267.
  • Wiki: Precision@1 improved from 0.3712 to 0.3952.

Beyond benchmark performance, GraphFormers was deployed in Bing Search for ads retrieval. An online A/B test showed significant improvements in business metrics, including a +1.87% increase in Revenue Per Mille (RPM) and a +0.96% increase in Click Yield.

Discussion and Conclusion

The success of GraphFormers demonstrates that "early fusion" of text and graph encoding allows language models to disambiguate text using graph context before finalizing node embeddings. This confirms that text semantics and graph topology are deeply intertwined and should be modeled together.

While the unidirectional simplification ensures efficiency, it may sacrifice some theoretical expressiveness compared to full bidirectional attention. Additionally, heterogeneous graphs like Wiki present challenges where neighborhood information can act as noise. Future work may explore dynamic gating mechanisms to better handle such heterogeneity. In conclusion, GraphFormers provides a scalable and effective architecture for joint modeling of text and graph structure.

Summary updated

BibTeX
@inproceedings{yang2021graphformers,
  author = {Junhan Yang and Zheng Liu and Shitao Xiao and Chaozhuo Li and Guangzhong Sun and Xing Xie},
  title = {{GraphFormers: GNN-nested Language Models for Linked Text Representation}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2021},
  url = {https://openreview.net/forum?id=6NDG0kX4ey},
}
Figure