Enhancing Graph Transformers with Hierarchical Distance Structural Encoding
Yuankai Luo, Hongkang Li, Lei Shi, Xiao-Ming Wu
TL;DR
The paper introduces Hierarchical Distance Structural Encoding (HDSE) to inject multi-level graph hierarchy information into graph transformer attention, addressing the lack of hierarchical bias in existing methods. HDSE defines Graph Hierarchy Distance (GHD) and encodes node-pair distances across multiple coarsening levels, enabling a learned bias that improves expressivity over shortest-path only encodings. The approach integrates HDSE into standard graph transformers and scales to large graphs via high-level HDSE that couples with linear attention, yielding strong performance gains on graph-level and billion-node-scale node classification tasks while maintaining efficiency. Theoretical results show HDSE is strictly more expressive than SPD within the GD-WL framework, and empirical results across 18 benchmarks demonstrate robust improvements with different coarsening strategies. This work has practical impact for molecules, social networks, and large-scale graphs where hierarchical structure is pivotal for accurate reasoning and scalable inference.
Abstract
Graph transformers need strong inductive biases to derive meaningful attention scores. Yet, current methods often fall short in capturing longer ranges, hierarchical structures, or community structures, which are common in various graphs such as molecules, social networks, and citation networks. This paper presents a Hierarchical Distance Structural Encoding (HDSE) method to model node distances in a graph, focusing on its multi-level, hierarchical nature. We introduce a novel framework to seamlessly integrate HDSE into the attention mechanism of existing graph transformers, allowing for simultaneous application with other positional encodings. To apply graph transformers with HDSE to large-scale graphs, we further propose a high-level HDSE that effectively biases the linear transformers towards graph hierarchies. We theoretically prove the superiority of HDSE over shortest path distances in terms of expressivity and generalization. Empirically, we demonstrate that graph transformers with HDSE excel in graph classification, regression on 7 graph-level datasets, and node classification on 11 large-scale graphs, including those with up to a billion nodes.
