Connect, Not Collapse: Explaining Contrastive Learning for Unsupervised Domain Adaptation

Kendrick Shen, Robbie M. Jones, Ananya Kumar, Sang Michael Xie, Jeff Z. HaoChen, Tengyu Ma, Percy Liang

This paper from the Stanford NLP and Theory groups, presented at ICML 2022, challenges the fundamental "common sense" of Unsupervised Domain Adaptation (UDA). While the field has spent a decade trying to force models to ignore the differences between domains, this research suggests that the secret to success might actually be to embrace those differences—as long as you can disentangle them from the classes you're trying to predict.

The Problem: The Flaw in Domain Invariance

In Unsupervised Domain Adaptation (UDA), researchers are given labeled data from a source domain (e.g., clear photos of cars) and unlabeled data from a target domain (e.g., artistic sketches of cars). The goal is to build a classifier that accurately predicts classes on the target domain despite the visual shift.

For years, the gold standard approach has been domain invariance. The logic was straightforward: if the model cannot tell the difference between a photo and a sketch, it will be forced to rely only on the core "car-ness" to make its prediction. Methods like Domain Adversarial Neural Networks (DANN) explicitly penalize the model if it can distinguish between the source and target domains.

However, the authors noticed a surprising trend: contrastive learning methods (like SimCLR or SwAV)—which do not explicitly optimize for domain invariance—were performing exceptionally well on UDA tasks. This paper seeks to explain why this happens, providing a theoretical framework for understanding how connectivity via data augmentation enables generalization without requiring domain collapse.

Methods: The Theoretical Connectivity Model

To explain why contrastive learning succeeds where adversarial methods struggle, the authors analyze a simple two-step pipeline:

  1. Contrastive Pre-training: Train a feature encoder on a mixture of unlabeled source and target data using standard contrastive losses.
  2. Fine-tuning: Train a linear classifier (or fine-tune the whole model) using only the labeled source data.

They introduce a Theoretical Connectivity Model based on an "augmentation graph." In this graph, nodes are images, and edges represent the probability that two images are generated as augmentations of the same original image.

Simplified augmentation graph and the resulting learned representation space showing disentanglement.

The authors prove that contrastive learning succeeds if the data augmentations satisfy a specific hierarchy of "connectivity":

  • High Connectivity: Augmentations that stay within the same class. This includes augmentations that bridge the domain gap (e.g., a crop of a photo that looks stylistically similar to a sketch).
  • Low Connectivity: Augmentations that cross class boundaries (e.g., a crop so aggressive it turns a "clock" into a generic "circle", confusing it with another class).

Key Insights: Connect, Not Collapse

  • Connecting Domains: Traditional UDA tries to "collapse" the distributions of photos and sketches so they overlap perfectly. Contrastive learning instead "connects" them. If a specific augmentation of a "clock photo" looks similar to an augmentation of a "clock sketch," the model learns they belong to the same class, even if it still knows one is a photo and the other is a sketch.
  • Disentanglement over Invariance: The authors found that in the learned feature space, it is actually easier to tell the domains apart than in traditional methods. However, the "domain info" and "class info" are stored on different axes (disentangled). A linear classifier can simply learn to ignore the "domain axis" and focus on the "class axis."
  • The Power of Extra Data: Because contrastive learning is self-supervised, you can throw in unlabeled data from other related domains. This "SwAV+extra" approach significantly boosted performance, suggesting that more variety in the pre-training mix helps the model find better "bridges" between classes.
  • Connectivity Ratios: The paper shows that the ratio of "same-class connectivity" to "cross-class connectivity" is a strong predictor of how well a model will adapt. If your augmentations are too aggressive and blur class boundaries, UDA performance tanks.

Empirical Results

The authors validated their theory and empirical results on several standard UDA benchmarks, including DomainNet, BREEDS (Living-17 & Entity-30), and STL-10 → CIFAR-10.

  • Competitive Performance: Contrastive pre-training (SwAV) achieved results comparable to or better than state-of-the-art UDA methods like SENTRY and DANN.
  • Entity-30 Success: On the challenging Entity-30 benchmark, contrastive pre-training outperformed the best baseline by 3.1%.
  • Domain Separability: In DomainNet, a simple linear probe could distinguish the domain with only 8% error in the contrastive feature space, compared to 14% in DANN. This proves the model is not learning domain-invariant features, yet it still generalizes better.
  • Theory Validation: The authors' theoretical formula for target accuracy (based on connectivity ratios) achieved an $R^2 = 0.78$ correlation with actual experimental results.

Limitations and Future Work

While groundbreaking, the theoretical proofs rely on a Stochastic Block Model (SBM), which assumes a uniform distribution of data—a simplification of real-world data distributions. Furthermore, the method's success is entirely dependent on the choice of augmentations. If the augmentations don't "bridge" the domains (e.g., if no augmentation of a photo ever looks like a sketch), the connectivity fails.

The authors suggest that instead of designing better adversarial losses, future UDA research should focus on designing domain-bridging augmentations or smarter data selection strategies to increase connectivity between source and target domains.

Summary updated

BibTeX
@inproceedings{shen2022connect,
  author = {Kendrick Shen and Robbie M. Jones and Ananya Kumar and Sang Michael Xie and Jeff Z. HaoChen and Tengyu Ma and Percy Liang},
  title = {{Connect, Not Collapse: Explaining Contrastive Learning for Unsupervised Domain Adaptation}},
  booktitle = {International Conference on Machine Learning},
  year = {2022},
  url = {https://openreview.net/forum?id=e9SBpJ6jsfy},
}
Figure