Contrastive Clustering

Yunfan Li, Peng Hu, Jerry Zitao Liu, Dezhong Peng, Joey Tianyi Zhou, Xi Peng

TL;DR

Contrastive Clustering (CC) is a novel one-stage, end-to-end deep clustering framework that simultaneously learns instance-level and cluster-level representations. By elegantly treating the rows of a feature matrix as soft labels and its columns as cluster prototypes, CC achieves massive performance gains—up to 39% improvement in NMI—on standard image benchmarks while supporting large-scale online learning.

What Problem Does This Paper Address?

Clustering is a cornerstone of unsupervised learning, but traditional methods like k-means often fail on high-dimensional, complex data like images. Deep clustering attempts to solve this by using neural networks for representation learning. However, most existing deep clustering methods are "two-stage" or iterative: they alternate between learning features and performing clustering. This approach is prone to error accumulation and typically requires the entire dataset to be present (offline), making it unsuitable for large-scale online applications.

Recent online methods like IIC or PICA have emerged, but they often rely on complex, hard-to-explain tricks like "over-clustering." The authors of this paper sought a unified, one-stage framework that could learn both discriminative features and cluster assignments simultaneously in a batch-wise (online) fashion without these auxiliary tricks.

Methods

The core of the Contrastive Clustering (CC) method is a dual-head architecture that performs contrastive learning in two different subspaces.

  1. Pair Construction: Like other contrastive methods (e.g., SimCLR), CC starts by creating two augmented views of each image in a mini-batch using transformations like random cropping, color jittering, and flipping.
  2. Shared Backbone: Both views are passed through a shared ResNet34 backbone to extract high-level features.
  3. Dual Contrastive Heads: This is where CC innovates. The features are projected into two separate MLP heads:
  4. Instance-level Contrastive Head (ICH): This head projects features into a row space. It uses a standard contrastive loss to maximize the similarity between different views of the same image while minimizing similarity between different images.
  5. Cluster-level Contrastive Head (CCH): This head projects features into a space where the dimensionality equals the number of clusters ($M$). The authors' key insight is that in this space, the output vector for an instance can be interpreted as a soft label (probability of belonging to each cluster).
Fig. 2. The framework of Contrastive Clustering. We construct data pairs using two data augmentations. Given data pairs, one shared deep neural network is used to extract features from different augmentations. Two separate MLPs (σ denotes the ReLU activation and ∼denotes the Softmax operation to produce soft labels) are used to project the features into the row and column space wherein the instance- and cluster-level contrastive learning are conducted respectively.

By maximizing the similarity between the cluster assignments (columns of the feature matrix) of the two augmented views, the model learns to group similar instances together. To prevent the trivial solution where all instances are assigned to a single cluster, they include an entropy-based regularization term.

Datasets

The authors evaluated CC on six challenging image benchmarks:

  • CIFAR-10 and CIFAR-100: Standard small-image datasets (CIFAR-100 uses 20 super-classes).
  • STL-10: Includes 100,000 additional unlabeled samples used to boost the instance-level head.
  • ImageNet-10 and ImageNet-Dogs: Subsets of the massive ImageNet dataset focusing on specific categories.
  • Tiny-ImageNet: A scaled-down version of ImageNet with 200 classes.

Key Insights and Ideas

  • Label as Representation: The most profound insight is the duality of the feature matrix. If you project data into an $M$-dimensional space, the rows are instance representations (soft labels), and the columns are cluster representations distributed over the dataset.
  • Dual-Space Optimization: By performing contrastive learning on both rows (instances) and columns (clusters), the model forces the representations to be both locally discriminative and globally consistent.
  • Decoupling for Performance: While theoretically possible to do both on one matrix, the authors found that using two separate MLP heads (subspaces) improved representability and final clustering performance.
Fig. 1. The key observation. By regarding the rows of the feature matrix as the soft labels of instances (i.e., P(cj|xi) denotes the probability of sample i belonging to cluster j), the columns could accordingly be interpreted as cluster representations distributed over the dataset. As a result, the instance- and cluster-level contrastive learning could be con- ducted in the row and column space of the feature matrix, respectively.

Key Results

CC significantly outperformed 17 state-of-the-art clustering methods across all metrics (NMI, Accuracy, and ARI).

  • CIFAR-10: Achieved an NMI of 0.705, a 19% improvement over the previous best baseline (PICA).
  • CIFAR-100: Achieved an NMI of 0.431, representing a staggering 39% improvement.
  • Qualitative Success: t-SNE visualizations show that while features start as a mixed cloud, they rapidly organize into distinct, well-separated clusters as training progresses.
t-SNE evolution on ImageNet-10

Limitations and Future Work

  • Augmentation Dependency: Ablation studies confirmed that CC relies heavily on strong data augmentation. Without it, the model fails to learn meaningful clusters.
  • Prior Knowledge: The method requires the number of clusters ($M$) to be known beforehand, which is a common limitation in clustering but a hurdle for truly "discovery-oriented" unsupervised learning.
  • Future Directions: The authors suggest extending this dual contrastive framework to semi-supervised learning and transfer learning tasks.

Summary updated

Abstract

In this paper, we propose a one-stage online clustering method called Contrastive Clustering (CC) which explicitly performs the instance- and cluster-level contrastive learning. To be specific, for a given dataset, the positive and negative instance pairs are constructed through data augmentations and then projected into a feature space. Therein, the instance- and cluster-level contrastive learning are respectively conducted in the row and column space by maximizing the similarities of positive pairs while minimizing those of negative ones. Our key observation is that the rows of the feature matrix could be regarded as soft labels of instances, and accordingly the columns could be further regarded as cluster representations. By simultaneously optimizing the instance- and cluster-level contrastive loss, the model jointly learns representations and cluster assignments in an end-to-end manner. Extensive experimental results show that CC remarkably outperforms 17 competitive clustering methods on six challenging image benchmarks. In particular, CC achieves an NMI of 0.705 (0.431) on the CIFAR-10 (CIFAR-100) dataset, which is an up to 19\% (39\%) performance improvement compared with the best baseline.
BibTeX
@inproceedings{li2021contrastive,
  author = {Yunfan Li and Peng Hu and Jerry Zitao Liu and Dezhong Peng and Joey Tianyi Zhou and Xi Peng},
  title = {{Contrastive Clustering}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2021},
  doi = {10.1609/aaai.v35i10.17037},
}
Figure