Abstract
Contrastive learning has gained popularity as an effective self-supervised representation learning technique. Several research directions improve traditional contrastive approaches, e.g., prototypical contrastive methods better capture the semantic similarity among instances and reduce the computational burden by considering cluster prototypes or cluster assignments, while adversarial instance-wise contrastive methods improve robustness against a variety of attacks. To the best of our knowledge, no prior work jointly considers robustness, cluster-wise semantic similarity and computational efficiency. In this work, we propose SwARo, an adversarial contrastive framework that incorporates cluster assignment permutations to generate representative adversarial samples. We evaluate SwARo on multiple benchmark datasets and against various white-box and black-box attacks, obtaining consistent improvements over state-of-the-art baselines.
Introduction
Contrastive learning has emerged as a dominant paradigm in self-supervised learning, enabling models to learn rich representations by distinguishing between similar (positive) and dissimilar (negative) pairs. However, these models remain highly vulnerable to adversarial perturbations—small, often imperceptible changes to input data that can drastically degrade performance.
Existing adversarial contrastive learning (ACL) methods typically employ untargeted attacks to push images away from their original feature space. While this improves robustness, it often ignores the global semantic structure of the data, such as the natural clustering of images (e.g., "dogs" vs. "cars"). This oversight frequently results in a significant trade-off, where gains in robustness come at the cost of accuracy on clean, un-attacked images. SwARo (Swapping Assignments for Robust contrastive learning) is designed to bridge this gap by incorporating cluster-aware mechanisms into the adversarial training process.
The SwARo Framework
SwARo introduces a cluster-aware mechanism into the adversarial training loop to generate more semantically meaningful adversarial samples. The framework operates through a three-step process:
- Cluster Assignment: The model performs $k$-means clustering on current latent representations to assign pseudo-labels to each image in a batch.
- Adversarial Sample Generation via Permutation: Instead of simple untargeted attacks, SwARo creates "pseudo-targeted" attacks by permuting cluster assignments within the batch. If a pair of images belongs to the same cluster, the attack maximizes contrastive loss to push them apart; if they belong to different clusters, it minimizes loss to pull them together.
- Robust Training: The model is trained to resist these semantically confusing perturbations, forcing it to learn a feature space where cluster boundaries are resilient to blurring.
This "swapping" mechanism ensures that the adversarial directions explored during training are semantically relevant, helping the model maintain a clearer understanding of the data's global structure even under attack.
Experimental Results
The researchers evaluated SwARo on standard computer vision benchmarks, CIFAR-10 and CIFAR-100, using a ResNet-18 backbone. The results demonstrate that SwARo achieves a superior balance between natural accuracy and robustness compared to previous state-of-the-art methods like RoCL and ACL.
Accuracy and Robustness Trade-off
On CIFAR-10, SwARo achieved a clean accuracy ($A_{nat}$) of 87.38%, significantly outperforming the previous best adversarial method, RoCL (83.71%). Furthermore, SwARo showed exceptional generalization to unseen attack types. While many models are trained specifically against $\ell_\infty$ attacks, SwARo demonstrated superior transfer robustness to $\ell_1$ attacks, reaching 84.06% compared to RoCL's 79.21%.
Qualitative Analysis
Qualitative evaluations using t-SNE visualizations confirmed that SwARo produces tighter, more distinct clusters than its competitors. This suggests that the learned representations are semantically cleaner and that the model's implicit semantic supervision—using its own emerging understanding of clusters—is an effective defense mechanism.
Conclusion
SwARo demonstrates that jointly considering robustness and cluster-wise semantic similarity is key to improving self-supervised representations. By using cluster assignment permutations to guide adversarial training, SwARo mitigates the traditional trade-off between clean accuracy and adversarial robustness. Future work will focus on reducing the computational overhead of iterative adversarial generation and exploring hierarchical clustering to capture finer-grained semantic details in larger datasets.
Summary updated