Unleashing the Power of Transformer for Graphs

Lingbing Guo, Qiang Zhang, Huajun ChenarXiv 2022 · OpenReview

Abstract: Despite recent successes in natural language processing and computer vision, Transformer suffers from the scalability problem when dealing with graphs. The computational complexity is unacceptable for large-scale graphs, e.g., knowledge graphs. One solution is to consider only the near neighbors, which, however, will lose the key merit of Transformer to attend to the elements at any distance. In this paper, we propose a new Transformer architecture, named dual-encoding Transformer (DET). DET has a structural encoder to aggregate information from connected neighbors and a semantic encoder to focus on semantically useful distant nodes. In comparison with resorting to multi-hop neighbors, DET seeks the desired distant neighbors via self-supervised training. We further find these two encoders can be incorporated to boost each others' performance. Our experiments demonstrate DET has achieved superior performance compared to the respective state-of-the-art methods in dealing with molecules, networks and knowledge graphs with various sizes.

Introduction

Transformers have revolutionized deep learning by enabling models to capture long-range dependencies through global self-attention. However, their application to graph-structured data presents a significant challenge. Standard Graph Neural Networks (GNNs) like GCN or GAT typically operate on local 1-hop neighborhoods. While stacking layers can theoretically reach distant nodes, this often leads to "over-smoothing"—where node features become indistinguishable—and the introduction of noise from irrelevant distant connections.

Conversely, a naive Transformer approach treats a graph as a fully connected set of nodes, resulting in $O(n^2)$ computational complexity. This is unmanageable for large-scale knowledge graphs or social networks. The Dual-Encoding Transformer (DET) addresses this by maintaining the Transformer's global reach while ensuring computational efficiency and signal purity through a bifurcated encoding strategy.

The Dual-Encoding Transformer Architecture

The core of DET is its split workload, divided into two specialized but interactive encoders: the Structural Encoder and the Semantic Encoder.

The DET architecture features parallel structural and semantic encoding branches that mutually reinforce each other through attention biases.

Structural Encoder

This component focuses on the explicit topology of the graph. It utilizes standard dot-product self-attention to aggregate information from direct (1-hop) neighbors. To preserve the geometric context of the graph, the encoder incorporates structural positional information, such as node centrality and shortest-path distances, ensuring the model understands the relative "physical" layout of the nodes.

Semantic Encoder

The Semantic Encoder acts as the model's "global eye," identifying nodes that share semantic similarities regardless of their distance in the graph topology. To maintain efficiency, it employs a linear attention variant and a learnable similarity function based on weighted L1 distance. This allows the model to "teleport" to relevant distant nodes without the computational burden of a full $O(n^2)$ attention matrix.

Mutual Reinforcement and Bias

A key innovation in DET is that these encoders do not operate in isolation. The semantic encoder provides an "attention bias" to the structural encoder, helping it prioritize the most relevant local neighbors. Simultaneously, structural information helps the semantic encoder filter out distant noise, focusing only on nodes likely to provide meaningful signal.

Semantic Neighbor Fetching

Traditional GNNs find distant nodes by iteratively following paths (1-hop to 2-hop, and so on). DET replaces this path-based search with a score-based "fetching" mechanism. The "Semantic Neighbor Hypothesis" posits that a node's most critical influences are often nodes that are semantically similar in the embedding space, even if they are not physically connected.

Visualization of semantic neighbor fetching: a query node identifies relevant distant nodes based on feature similarity rather than graph distance.

To train this fetching mechanism without manual labels, the authors utilize a self-supervised contrastive loss function ($L_{sn}$). This loss encourages the model to distinguish "useful" distant nodes (positive examples) from randomly sampled distant noise (negative examples). As the model trains and embeddings refine, the semantic encoder becomes increasingly precise at identifying these global dependencies.

Experimental Results

DET was evaluated across three diverse domains, demonstrating state-of-the-art (SOTA) or highly competitive performance:

  • Molecular Graphs: On the PCQM4M-LSC dataset (3.8M molecules), DET outperformed the previous leader, Graphormer, reducing the Mean Average Error (MAE) from 0.1234 to 0.1212. It also achieved a SOTA MAE of 0.113 on the ZINC dataset.
  • Knowledge Graph Completion: The model showed significant improvements in Mean Rank (MR) on benchmarks like FB15K-237 and WN18RR, indicating a superior ability to grasp global relational contexts compared to traditional path-based models.
  • Node Classification: DET outperformed GAT and other attention-based baselines on citation networks like Cora and PubMed, validating the power of semantic fetching in identifying relevant research clusters.

Conclusion

The Dual-Encoding Transformer effectively bridges the gap between local GNNs and global Transformers. By separating structural and semantic processing, it achieves the global reach necessary for complex graph tasks without the scalability issues of traditional attention mechanisms. Future work will explore the integration of more advanced structural encoders and the application of this dual-encoding framework to other domains like NLP and Computer Vision, where hierarchical relationships are prevalent.

Summary updated

BibTeX
@misc{guo2022unleashing,
  author = {Lingbing Guo and Qiang Zhang and Huajun Chen},
  title = {{Unleashing the Power of Transformer for Graphs}},
  year = {2022},
  eprint = {2202.10581},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2202.10581},
}
Figure