Prototypical Graph Contrastive Learning

Shuai Lin, Pan Zhou, Zi-Yuan Hu, Shuojia Wang, Ruihui Zhao, Yefeng Zheng, Liang Lin, Eric P. Xing, Xiaodan LiangIEEE TNNLS 2021 · DOI

Abstract

Graph-level representations are critical in various real-world applications, such as predicting the properties of molecules. But in practice, precise graph annotations are generally very expensive and time-consuming. To address this issue, graph contrastive learning constructs instance discrimination task which pulls together positive pairs (augmentation pairs of the same graph) and pushes away negative pairs (augmentation pairs of different graphs) for unsupervised representation learning. However, since for a query, its negatives are uniformly sampled from all graphs, existing methods suffer from the critical sampling bias issue, i.e., the negatives likely having the same semantic structure with the query, leading to performance degradation. To mitigate this sampling bias issue, in this paper, we propose a Prototypical Graph Contrastive Learning (PGCL) approach. Specifically, PGCL models the underlying semantic structure of the graph data via clustering semantically similar graphs into the same group, and simultaneously encourages the clustering consistency for different augmentations of the same graph. Then given a query, it performs negative sampling via drawing the graphs from those clusters that differ from the cluster of query, which ensures the semantic difference between query and its negative samples. Moreover, for a query, PGCL further reweights its negative samples based on the distance between their prototypes (cluster centroids) and the query prototype such that those negatives having moderate prototype distance enjoy relatively large weights. This reweighting strategy is proved to be more effective than uniform sampling. Experimental results on various graph benchmarks testify the advantages of our PGCL over state-of-the-art methods.

Introduction

Contrastive learning has emerged as a powerful paradigm for unsupervised representation learning. In the context of graphs, the standard approach involves instance discrimination: pulling together augmented versions of the same graph (positives) while pushing away all other graphs in a batch (negatives).

Despite its success, this approach suffers from a fundamental flaw known as sampling bias. Because negative samples are typically drawn uniformly at random from the dataset, the model often treats semantically similar graphs as negatives. For instance, in molecular property prediction, two different molecules sharing the same functional group might be pushed apart in the embedding space. This unintended behavior confuses the model, leading to suboptimal representations that fail to capture the true underlying semantic structure of the data.

Methodology

To address the sampling bias issue, we introduce Prototypical Graph Contrastive Learning (PGCL). PGCL moves beyond simple instance-level discrimination by explicitly modeling the global semantic structure of the graph data through clustering.

Overview of the PGCL framework, illustrating the dual-encoder architecture, prototype-based clustering, and the reweighted contrastive objective.

The framework is built upon two primary components:

1. Clustering Consistency

PGCL maintains a set of trainable prototypes (cluster centroids) in the embedding space. For each graph, the model computes a cluster assignment. To prevent degenerate solutions where all graphs collapse into a single cluster, the assignment is formulated as an optimal transport problem and solved efficiently using the Sinkhorn-Knopp algorithm. The model is then trained to ensure that different augmentations of the same graph are assigned to the same prototype, thereby enforcing semantic consistency across different "views" of the data.

2. Reweighted Contrastive Objective

Instead of uniform negative sampling, PGCL employs a more nuanced strategy:

  • Semantic Masking: Negative samples that fall into the same cluster as the query are masked out. This directly prevents the model from pushing away semantically similar graphs (false negatives).
  • Distance-based Reweighting: The remaining negatives are reweighted based on the distance between their cluster prototype and the query's prototype. PGCL prioritizes "moderate" negatives—those that are neither too similar (potentially misleading) nor too different (too easy to distinguish). This "Goldilocks" approach provides a more informative gradient signal for refining the learned representations.

Experimental Results

We evaluated PGCL across seven diverse graph benchmarks, including bioinformatics datasets (MUTAG, PTC, PROTEINS, NCI1) and social network datasets (COLLAB, RDT-B, RDT-M5K).

Comparison of PGCL against supervised, kernel-based, and unsupervised baselines across multiple graph benchmarks.

As shown in the table above, PGCL consistently outperforms existing state-of-the-art unsupervised methods. Notably, on the RDT-B dataset, PGCL achieves a 91.5% accuracy, representing a significant improvement over previous methods like GraphCL. Furthermore, PGCL often narrows the gap with supervised learning models, even outperforming some supervised GNN baselines on specific datasets like MUTAG.

In transfer learning experiments for molecular property prediction (pre-trained on ZINC-2M), PGCL demonstrated superior generalization capabilities, achieving a top mean rank across seven different tasks compared to other self-supervised competitors.

Discussion and Conclusion

PGCL demonstrates that modeling global semantic structure through prototypes is a highly effective way to mitigate sampling bias in graph contrastive learning. By combining clustering consistency with a reweighted contrastive objective, the model learns representations that are both robust to local perturbations and aware of global semantic categories.

While the method shows strong performance, it does introduce additional hyperparameters, such as the number of prototypes ($K$), which may require tuning for different domains. Additionally, the clustering steps add some computational complexity. Future work could explore automated ways to determine the optimal number of clusters or integrate more sophisticated graph augmentation strategies to further enhance the quality of the learned embeddings.

Code is available at https://github.com/ha-lins/PGCL.

Summary updated

BibTeX
@article{lin2021prototypical,
  author = {Shuai Lin and Pan Zhou and Zi-Yuan Hu and Shuojia Wang and Ruihui Zhao and Yefeng Zheng and Liang Lin and Eric P. Xing and Xiaodan Liang},
  title = {{Prototypical Graph Contrastive Learning}},
  journal = {IEEE Trans. Neural Networks Learn. Syst.},
  year = {2021},
  doi = {10.1109/tnnls.2022.3191086},
}
Figure