Leveraging Contrastive Learning for Enhanced Node Representations in Tokenized Graph Transformers

Jinsong Chen, Hanpeng Liu, John E. Hopcroft, Kun He

Introduction

Graph Neural Networks (GNNs) are the standard for graph data but often suffer from "over-smoothing" and "over-squashing." While Graph Transformers address long-range dependencies by treating nodes as sequences, existing "tokenized" variants typically only sample nodes with high similarity to the target node. This approach overlooks "disparity" information—knowing what a node is not like is often as critical as knowing what it is like, especially in heterophily graphs where connected nodes frequently have different labels.

GCFormer: Leveraging Contrastive Learning

The authors propose GCFormer (Graph Contrastive Transformer) to bridge this gap. GCFormer captures both commonalities and disparities through a hybrid generator and a dedicated contrastive learning objective.

Hybrid Token Generator

Unlike previous models that rely solely on raw attributes, GCFormer calculates similarity in two distinct spaces: Attribute-aware (node features) and Topology-aware (features propagated through the graph structure). This dual-space approach allows the model to adapt to various graph types. It performs a two-stage sampling process:

  • Positive Tokens: The top-$k$ most similar nodes.
  • Negative Tokens: Randomly sampled nodes from the "abandoned" set (those with low similarity).
GCFormer architecture overview comparing it to previous similarity-only methods.

Transformer Backbone and Signed Readout

The positive and negative sequences are processed through standard Transformer layers. To effectively integrate negative information without introducing noise, GCFormer introduces a "virtual token" to aggregate the negative sequence. The final representation is calculated via a Signed Readout: subtracting the negative aggregate from the positive representation ($P_0 - N_0$). This explicitly pushes the node away from its dissimilar counterparts in the embedding space.

Contrastive Learning Objective

A specific contrastive loss term ($\mathcal{L}_{cl}$) is added to ensure the target node's representation remains close to its positive tokens' center and far from its negative tokens.

Experimental Results

GCFormer was evaluated on eight benchmarks spanning homophily (e.g., Photo, ACM) and heterophily (e.g., BlogCatalog, Romanempire) graphs. It consistently outperformed eleven baseline models, including state-of-the-art Graph Transformers like GraphGPS and ANS-GT.

The performance gains were most significant on heterophily graphs. For instance, on the Romanempire dataset ($H(G)=0.05$), GCFormer achieved 75.38% accuracy, surpassing the next best Transformer (NAGphormer) by a notable margin. Ablation studies confirmed that both negative tokens and the contrastive loss are essential for these performance improvements.

Limitations and Future Work

While GCFormer sets a new state-of-the-art, it exhibits sensitivity to the number of positive ($p_k$) and negative ($n_k$) tokens sampled. Sensitivity analysis across different datasets reveals that optimal sampling sizes vary significantly depending on the graph's characteristics.

Sensitivity analysis of GCFormer performance across different datasets with varying numbers of positive ($p_k$) and negative ($n_k$) tokens.

Currently, the model employs a unified sampling strategy. Future research will focus on developing an adaptive sampling strategy that can automatically tune these hyperparameters based on the specific homophily ratio and structural properties of the input graph.

Summary updated

BibTeX
@inproceedings{chen2024leveraging,
  author = {Jinsong Chen and Hanpeng Liu and John E. Hopcroft and Kun He},
  title = {{Leveraging Contrastive Learning for Enhanced Node Representations in Tokenized Graph Transformers}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=u6FuiKzT1K},
}
Figure