Hierarchical Graph Transformer with Adaptive Node Sampling

Zaixi Zhang, Qi Liu, Qingyong Hu, Chee-Kong Lee

TL;DR

ANS-GT is a scalable Graph Transformer that solves the "sampling problem" by treating node selection as an adversary bandit problem, adaptively learning which neighbors are most informative during training. By combining this adaptive sampling with a hierarchical attention scheme that uses graph coarsening, the model captures both fine-grained local details and long-range global context with linear complexity.

The Challenge of Graph Transformers

While Transformers have revolutionized Natural Language Processing and Computer Vision, they struggle to achieve the same dominance with large-scale graph data. The primary hurdle is the "quadratic explosion": the vanilla self-attention mechanism has a computational complexity of $O(n^2)$, making it unusable for graphs with thousands or millions of nodes.

To bypass this, researchers typically resort to node sampling, restricting attention to a small subset of nodes. However, current sampling approaches suffer from two major flaws:

  1. Static Sampling is Blind: Most methods use fixed strategies, such as only looking at 1-hop neighbors or using Personalized PageRank (PPR). These strategies do not adapt to the specific characteristics of a graph (e.g., homophily vs. heterophily) or the evolving needs of the model during training.
  2. Missing the Big Picture: By focusing exclusively on local neighborhoods to save memory, these models often lose the "long-range dependencies"—the global structural context that makes Transformers so powerful in other domains.

Introducing ANS-GT

To address these deficiencies, the authors propose the Hierarchical Graph Transformer with Adaptive Node Sampling (ANS-GT), which introduces two main innovations: Adaptive Node Sampling and Hierarchical Attention.

Architecture of the ANS-GT model, illustrating the adaptive sampling module and graph coarsening process.

1. Adaptive Node Sampling (ANS)

Instead of picking a single sampling strategy and sticking to it, ANS-GT treats sampling as a Multi-Armed Bandit problem. The "arms" of the bandit are different sampling heuristics:

  • 1-hop and 2-hop neighbors (capturing local structure)
  • K-Nearest Neighbors (KNN) (capturing feature similarity)
  • Personalized PageRank (PPR) (capturing structural importance)

During training, the model calculates a "reward" based on the attention weights assigned to the sampled nodes. If a specific heuristic consistently provides nodes that the Transformer finds highly informative (indicated by high attention scores), the model dynamically increases the probability of using that heuristic in subsequent iterations. This creates a virtuous cycle: the model learns what to look at, and the sampler learns what to provide.

2. Hierarchical Attention

To capture global context without incurring the $O(n^2)$ cost, ANS-GT employs a two-tier attention strategy:

  • Fine-grained Local Attention: Utilizes the adaptive sampling described above to attend to specific, informative nearby nodes.
  • Coarse-grained Global Attention: Uses graph coarsening to cluster the graph into "super-nodes." The center node attends to these super-nodes, allowing it to "see" distant parts of the graph in a compressed, computationally efficient manner.

By combining these approaches, the total computational complexity is reduced to $O(n)$, making the Transformer scalable to large graphs.

Key Insights

A core insight of the paper is that no single sampling strategy wins everywhere. For "homophilic" graphs (where connected nodes tend to be similar), 1-hop and PPR strategies work best. Conversely, for "heterophilic" graphs (where connected nodes are often different), 2-hop or KNN strategies frequently perform better. ANS-GT's ability to switch between these strategies mid-training allows it to adapt to any graph type seamlessly. Furthermore, instead of trying to sparsify the attention matrix—which is notoriously difficult to optimize—the authors simplify the graph itself for global context, mimicking the down-sampling seen in traditional Convolutional Neural Networks.

Results and Performance

The model was evaluated across diverse benchmarks, including citation networks (Cora, CiteSeer, PubMed), Wikipedia graphs (Chameleon, Squirrel), and WebKB datasets (Actor, Cornell, Texas, Wisconsin).

Performance comparison of ANS-GT against popular GNNs and state-of-the-art Graph Transformers across multiple datasets.

ANS-GT consistently outperformed both popular Graph Neural Networks (GNNs) and state-of-the-art Graph Transformers:

  • State-of-the-Art Performance: It achieved the best results on nearly all benchmark datasets tested.
  • Transformer Dominance on Heterophily: On the highly heterophilic "Squirrel" dataset, ANS-GT reached 45.88% accuracy. While the GPRGNN baseline slightly edged it out at 46.34%, ANS-GT vastly outperformed all other Graph Transformers (e.g., the standard GT model only hit 25.68%).
  • Ablation Success: Removing the adaptive sampling module caused performance to drop significantly (e.g., a ~8% drop on the Chameleon dataset), proving that "learning how to sample" is just as critical as the Transformer architecture itself.

Limitations and Future Work

While highly effective, ANS-GT has a few limitations. The current framework uses proximity encoding but remains agnostic to the specific encoding scheme; exploring more advanced structural encodings (like Laplacian eigenvectors) could yield further gains. Additionally, while the training phase is linear, the preprocessing steps—such as graph coarsening and calculating initial sampling matrices (like PPR)—can be computationally intensive for extremely massive graphs. Finally, the authors suggest that this adaptive sampling logic could eventually help Transformers bridge the gap between graph data and other modalities, like text or images, in a unified architecture.

Summary updated

BibTeX
@inproceedings{zhang2022hierarchical,
  author = {ZAIXI ZHANG and Qi Liu and Qingyong Hu and Chee-Kong Lee},
  title = {{Hierarchical Graph Transformer with Adaptive Node Sampling}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2022},
  url = {https://openreview.net/forum?id=x3JsaghSj0v},
}
Figure