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

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

TL;DR

Contrastive pre-training is highly effective for unsupervised domain adaptation (UDA), but it completely breaks conventional wisdom. Instead of forcing features to be domain-invariant, contrastive learning disentangles class and domain information into separate, orthogonal dimensions, proving that domain invariance is not necessary for cross-domain generalization.

What Problem Does This Paper Address?

Machine learning models frequently fail when deployed on a "target domain" (e.g., sketches) that differs from their "source" training domain (e.g., photos). Unsupervised Domain Adaptation (UDA) attempts to mitigate this by leveraging labeled source data alongside unlabeled target data.

For over a decade, the dominant paradigm in UDA has been domain invariance: the idea that a model must learn a feature space where the source and target domains are completely indistinguishable. Popular methods like Domain-Adversarial Neural Networks (DANN) actively force these distributions to collapse together. However, this paper investigates a surprising alternative: out-of-the-box contrastive pre-training excels at UDA, yet it leaves the domains highly separable. The authors set out to resolve this paradox and explain theoretically how a model can generalize across domains without forcing domain invariance.

Methods

The authors analyze a simple two-stage pipeline:

  1. Contrastive Pre-training: An encoder (such as SwAV or SimCLR) is trained on a mixture of unlabeled source and target data using standard data augmentations (cropping, color jitter, etc.).
  2. Linear Probing/Fine-tuning: A linear classifier head is trained on top of the frozen or fine-tuned encoder using only the labeled source data.

To explain why this works, the authors model data augmentations using an augmentation graph under a multi-class Stochastic Block Model (SBM). In this graph, nodes are images, and edges represent the probability that two images share a common augmentation. They define three key connectivity parameters:

  • $\alpha$: Connectivity between the same class across different domains (e.g., a photo of a clock and a sketch of a clock).
  • $\beta$: Connectivity between different classes within the same domain (e.g., a photo of a clock and a photo of a butterfly).
  • $\gamma$: Connectivity between different classes across different domains (e.g., a photo of a clock and a sketch of a butterfly).

The authors prove theoretically that as long as $\alpha$ and $\beta$ are strictly greater than $\gamma$, contrastive learning will yield low target domain error.

Datasets

The paper evaluates its findings on several standard computer vision benchmarks:

  • DomainNet: A massive UDA benchmark; the authors use a filtered subset containing 40 classes across 4 domains (Clipart, Painting, Real, Sketch).
  • BREEDS (Living-17 and Entity-30): Subpopulation shift datasets derived from ImageNet using hierarchical WordNet nodes to create distinct source and target domain splits.
  • STL-10 $\rightarrow$ CIFAR-10: A classic domain adaptation setup paired together due to their resolution and style differences.

Key Insights and Ideas

  • Connect, Don't Collapse: Contrastive learning does not merge domains. In the learned feature space of DomainNet, a linear classifier can predict the domain of an image with only an 8% error rate (compared to 14% for DANN). It is just as easy for the model to distinguish between two domains as it is to distinguish between two classes.
  • Feature Disentanglement: Instead of destroying domain information, contrastive pre-training organizes the feature space so that domain and class information lie along approximately orthogonal dimensions. When a linear classifier is trained on the source domain, it learns to ignore the "domain axis" and focus entirely on the "class axis," allowing it to seamlessly generalize to the target domain.
Figure 1: (Left) Edges between class-domain pairs indicate how “connected” they are by augmentations (e.g., cropping, colorization). For example, α denotes the probability that augmentations connect examples of the same class across different domains. Small crop sizes (e.g., the red rectangles) can increase the connectivity between disparate domains. (Right) When α and β (which measure the connectivity between images of the same class or same domain respectively) are larger than γ (different domain and different class), fine-tuning with labeled source data (sketch: green, filled) in the feature space achieves high accuracy on the target (real: gray, hollow).
  • The Role of Augmentations: Generalization relies entirely on augmentations creating "bridges" across domains. For instance, an aggressive crop of a clock's gears looks similar whether it's from a photo or a sketch, driving up the cross-domain connectivity ($\alpha$) and enabling downstream transfer.

Key Results

  • Competitive Performance: Contrastive pre-training matches or outperforms specialized UDA algorithms. On DomainNet, SwAV achieves an average target accuracy of 44.91%, comparable to DANN with strong augmentations (45.81%). On STL-10 $\rightarrow$ CIFAR-10, SimCLR hits 75.41%, edging out the previous state-of-the-art method, Dirt-T (75.3%).
  • Scaling with Extra Data: A natural advantage of pre-training is its ability to scale. By adding extra unlabeled data from related domains during pre-training (SwAV+extra), DomainNet accuracy jumps significantly to 51.73%.
  • Theory Validation: The authors found that the ratio of cross-domain connectivity ($\alpha/\gamma$) strongly correlates with actual target accuracy ($R^2 = 0.78$), validating their theoretical framework on real-world datasets.

Limitations and Future Work

  • Stylized Theoretical Assumptions: The theoretical proofs rely on a Stochastic Block Model, which assumes a uniform marginal distribution over inputs—a simplification that does not fully capture the complex, continuous nature of real-world image distributions.
  • Failure Modes: Contrastive pre-training does not solve all distribution shifts; for example, it is known to perform poorly on benchmarks like iWildCam2020-WILDS, where augmentations fail to create sufficient cross-domain connectivity.
  • Future Directions: The authors suggest that future work should focus on designing data augmentation and data selection strategies that explicitly maximize cross-domain connectivity ($\alpha$) rather than trying to force domain invariance.

Summary updated

BibTeX
@inproceedings{shen2022connect,
  author = {Kendrick Shen and Robbie 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