GRPE: Relative Positional Encoding for Graph Transformer

Wonpyo Park, Woong-Gi Chang, Donggeon Lee, Juntae Kim, seung-won hwang

TL;DR

This paper introduces GRPE, a novel relative positional encoding method for graph transformers that overcomes limitations of existing approaches by jointly considering node-spatial and node-edge relationships without graph linearization. GRPE significantly improves performance on molecular property prediction tasks, demonstrating its effectiveness in capturing crucial graph structures.

What Problem Does This Paper Address?

The core challenge addressed is effectively encoding graph structures within Transformer architectures for tasks like molecular representation learning. While Transformers excel at capturing long-range dependencies via self-attention, they inherently lack positional awareness. For graphs, this means explicitly incorporating information about how nodes and edges are related. Existing methods either linearize the graph (losing precise relative positional information) or use simple bias terms (failing to integrate node features with positional information). This paper aims to bridge this gap by proposing a method that preserves relative positional information and deeply integrates it with node and edge features.

Methods

The paper proposes Graph Relative Positional Encoding (GRPE), which builds upon the relative positional encoding ideas from natural language processing but adapts them for graph structures. GRPE introduces two key innovations:

  1. Node-Aware Attention: This mechanism enhances the self-attention mechanism by incorporating two new terms:
  2. Spatial Encoding (b_spatial): This term encodes the spatial relationship between two nodes by considering the interaction between their features and learnable spatial encoding vectors. It's designed to capture how nodes are positioned relative to each other.
  3. Edge Encoding (b_edge): This term encodes the relationship between nodes based on the type of edge connecting them, again by considering the interaction between node features and learnable edge encoding vectors.

    Crucially, these terms are added to the standard scaled dot-product attention, allowing the model to attend to both node features and their structural relationships.

  4. Graph-Encoded Value: GRPE also encodes graph information directly into the value component of the self-attention mechanism. This is achieved by adding learnable spatial and edge encoding vectors to the node features before they are used as values. This "channel-wise" encoding enriches the hidden representations without losing positional precision, unlike linearization methods.

GRPE avoids graph linearization, directly processing the graph structure to capture relative positions and interactions between nodes and edges.

Datasets

The paper evaluates GRPE on several molecular property prediction datasets:

  • ZINC: A dataset for molecular property regression.
  • OGBG-MolPCBA (MolPCBA): A large-scale dataset for predicting multiple binary labels related to molecule properties.
  • OGBG-MolHIV (MolHIV): A dataset for predicting whether a molecule inhibits HIV virus replication.
  • PCQM4M and PCQM4Mv2: Large-scale datasets for predicting the DFT-calculated HOMO-LUMO energy gap of molecules.

Key Insights and Ideas

  • The Importance of Joint Encoding: The paper highlights that simply encoding absolute positions (via linearization) or relative positions (via simple biases) is insufficient. Effectively capturing graph structure requires jointly considering node features, their spatial relationships, and the nature of the edges connecting them.
  • Avoiding Linearization is Key: Linearizing a graph, while a common strategy, inherently loses the precise relative positional information that is crucial for understanding graph structures. GRPE's success demonstrates the benefit of working directly with the graph's topology.
  • Relative Positional Encoding for Graphs: Adapting relative positional encoding, successful in NLP, to graphs is a powerful idea. GRPE shows that this concept can be extended to capture complex spatial and edge-based relationships in graph data.
  • Node-Awareness in Attention: By incorporating node features into the calculation of spatial and edge biases, GRPE makes the attention mechanism "aware" of the specific nodes involved, leading to more nuanced interactions.

Key Results

GRPE achieves state-of-the-art (SOTA) results on several benchmarks:

  • ZINC: Achieves the SOTA MAE score with GRPE-Small (489k parameters), outperforming established methods like Graphormer (slim).
  • MolPCBA: Achieves SOTA AP score with GRPE-Large.
  • MolHIV: Achieves SOTA AUC score with GRPE-Standard, using fewer parameters than Graphormer.
  • PCQM4M: Achieves SOTA validation MAE.
  • PCQM4Mv2: Achieves the second-best result with GRPE-Standard, using half the parameters of the best model.

An ablation study also confirms the effectiveness of each component: adding b_spatial or b_edge individually improves performance, and combining them with Graph-Encoded Value yields the best results.

Limitations and Future Work

  • Maximum Shortest Path Distance (L): The method considers a maximum shortest path distance L. While increasing L generally improves performance, it plateaus after L=4. The paper doesn't explore the impact of extremely large L or alternative ways to handle long-range dependencies beyond this fixed limit.
  • Computational Complexity: While the paper proposes optimizations to reduce complexity, computing all pairwise interactions can still be computationally intensive for very large graphs.
  • Sharing Encodings: Ablation studies suggest that sharing spatial and edge encodings across layers improves MAE on ZINC but not significantly. The paper notes that sharing doesn't drastically change performance on large datasets, implying there might be room for layer-specific or more dynamic encoding strategies.

Future work could explore more sophisticated ways to handle long-range dependencies, further optimize computational efficiency, and investigate more advanced sharing or adaptation strategies for positional encodings.

Summary updated

BibTeX
@inproceedings{park2022grpe,
  author = {Wonpyo Park and Woong-Gi Chang and Donggeon Lee and Juntae Kim and seung-won hwang},
  title = {{GRPE: Relative Positional Encoding for Graph Transformer}},
  booktitle = {MLDD @ ICLR},
  year = {2022},
  url = {https://openreview.net/forum?id=GNfAFN_p1d},
}
Figure