Domain Confused Contrastive Learning for Unsupervised Domain Adaptation (2022)

Abstract: In this work, we study Unsupervised Domain Adaptation (UDA) in a challenging self-supervised approach. One of the difficulties is how to learn task discrimination in the absence of target labels. Unlike previous literature which directly aligns cross-domain distributions or leverages reverse gradient, we propose Domain Confused Contrastive Learning (DCCL), which can bridge the source and target domains via domain puzzles, and retain discriminative representations after adaptation. Technically, DCCL searches for a most domain-challenging direction and exquisitely crafts domain confused augmentations as positive pairs, then it contrastively encourages the model to pull representations towards the other domain, thus learning more stable and effective domain invariances. We also investigate whether contrastive learning necessarily helps with UDA when performing other data augmentations. Extensive experiments demonstrate that DCCL significantly outperforms baselines, further ablation study and analysis also show the effectiveness and availability of DCCL.

## introduction pre-trained language models @xcite @xcite have yielded considerable improvements with datasets drawing from various sources. however, the lack of portability of language model to adapt to a new textual domain remains a central issue @xcite , especially when the training set and testing set do not follow the same underlying distribution (changing of topic and genres) -usually referred to as domain shift. in this paper, we focus on studying unsupervised domain adaptation (uda). uda aims at designing adaptation algorithms that attempt to generalize well on the target domain by learning from both labeled samples from the source domain and unlabeled samples from the target domain. studying uda fits real-world scenarios since labeled data in the target domain is usually absent. moreover, advances in uda will also help out-ofdistribution generalizations @xcite . extensive algorithms have been proposed to mitigate the domain shift problem, for example, domain adversarial neural network (dann) @xcite and distribution matching @xcite . for dann, the training process of joint optimization is unstable, requiring extensive effort to tune the hyperparameters @xcite @xcite . as for distribution matching, it is very difficult to preserve the discriminative power of the model on the target task while trying to perform instance level alignment @xcite . to this end, it is essential to develop stable and effective solutions to learn domain invariance and instance-wise matching for uda. recent advances in self-supervised learning (ssl), such as contrastive learning (cl), have been proven effective at instance level by leveraging raw data to define surrogate tasks that help learn repre-sentations @xcite @xcite . cl benefits from treating instances as classes and conducting data augmentations to generate positive instance pairs. regarding cl for uda, previous works mark cross-domain images with the same labels (for example, real and cartoon dogs) as the positive pairs in contrastive loss @xcite . however, such methods are not applicable to nlp tasks because of the massive semantic and syntactic shifts between two cross-domain sentences. besides, from the domain adaptation perspective, constructing cross-domain positive samples and aligning domain-agnostic pairs have received less emphasis in related literature, since previous works focus on designing label preserving text transformations, such as back-translation, synonym, dropout and their combinations @xcite . confronting with limitations mentioned above, we propose the concept of domain puzzles which discard domain-related information to confuse the model, making it difficult to differentiate which domain these puzzles belong to. instead of directly seeking matched sentences across the source and target domains which is infeasible, we propose to pull the source (target) data and its corresponding domain puzzles closer to reduce the domain discrepancy, as shown in fig. 1 . a simple idea to craft domain puzzles is to mask domain-specific tokens. however, token-level operations are too discrete and non-flexible to reflect the complex semantic change of natural languages. hence, we aim to seek better domain puzzles that retain high-confidence predictions and task-discriminative power in the representation space for each training instance. in this paper, we propose domain confused contrastive learning (dccl) to encourage the model to learn similar representations for the original sentence and its curated domain-confused version with contrastive loss. more specifically, we synthesize these domain puzzles by utilizing adversarial examples @xcite . the algorithm will search for an extreme direction that roughly points to the opposite domain and produces most domain-challenging puzzles. we encourage the model to encode original and domain-confused samples closer, gradually pulling examples to the domain decision boundary as training progresses via cl, thus learning the domain invariance. furthermore, in order to investigate whether cl neces-sarily benefits uda, we conduct experiments and find that constructing domain puzzles as paired positive samples is favorable for uda, however, other data augmentation methods such as back translation @xcite do not have the same effect. the experiment results show that the proposed dccl significantly outperforms all the baselines. we also conduct quantitative experiments to measure the domain discrepancy after adaptation demonstrating that dccl can decrease the divergence between domains in a self-supervised way. overall, the paper makes the following contributions: ## method in this section, we focus our discussions on the proposed domain confused contrastive learning (dccl) under a sentiment classification scenario. the overall framework of our method is illustrated in fig. 2 . the model will take source labeled and target unlabeled sentences as input. it will then augment the input data with domain puzzles by fabricating adversarial perturbations. with the augmented data, the next step produces a hidden representation for each instance with an encoder which will be further used to produce three losses to train the entire model, namely sentiment classification loss, contrastive loss and consistency loss. ## conclusion in this work, we put forward a new concept, domain puzzles, which can be crafted through domainspecific token mask and domain-confused adversarial attacks. and we provide a more stable and effective solution to learn domain invariance for unsupervised domain adaptation. the proposed method dccl surpasses baselines with a large margin by mitigating domain shift without losing discriminative power on the target domain. moreover, the proposed framework can also be extended to other nlp tasks demanding adaptations, and we leave this for future work.