IDANI : Inference-time Domain Adaptation via Neuron-level Interventions (2022)

Abstract: Large pre-trained models are usually fine-tuned on downstream task data, and tested on unseen data. When the train and test data come from different domains, the model is likely to struggle, as it is not adapted to the test domain. We propose a new approach for domain adaptation (DA), using neuron-level interventions: We modify the representation of each test example in specific neurons, resulting in a counterfactual example from the source domain, which the model is more familiar with. The modified example is then fed back into the model. While most other DA methods are applied during training time, ours is applied during inference only, making it more efficient and applicable. Our experiments show that our method improves performance on unseen domains.

## introduction a common assumption in nlp, and in machine learning in general, is that the training set and the test set are sampled from the same underlying distribution. however, this assumption does not always hold in real-world applications since test data may arrive from many (target) domains, often not seen during training. indeed, when applied to such unseen target domains, the trained model typically encounters significant degradation in performance. da algorithms aim to address this challenge by improving models' generalization to new domains, and algorithms for various da scenarios have been developed @xcite @xcite . this work focuses on unsupervised domain adaptation (uda), the most explored da setup in recent years, which assumes access to labeled data from the source domain and unlabeled data from both source and target domains. algorithms for this setup typically use the target domain knowledge during training, attempting to bridge the gap between domains through representation learning @xcite @xcite @xcite . recently, @xcite and @xcite introduced an approach for inference-time da, assuming no prior knowledge regarding the test domains but still modifying the training process to their gain. in contrast to this line of work, we assume a more realistic scenario, in which the model was already trained on a source domain, and encounters unlabeled data from the target domain during inference time. given an example from a target domain, we would have liked to change it to a source domain example, so that the model would be more likely to perform well on it. since this is difficult to achieve, we aim to change its representation in a fine-grained manner, such that we modify only information about the domain of the representation, without hurting other information. to do so, we take inspiration from work analyzing language models, which showed that linguistic properties are localized in certain neurons (dimensions in model representations) @xcite @xcite @xcite . we first rank the neurons by their importance for identifying the domain (source or target) of each example. then, we modify target-domain representations only in the highest-ranked neurons, to change their domain to the source domain. since the model was trained on examples from the source domain, we expect it to perform better on the modified representations. we name this method as inference-time domain adaptation via neuron-level interventions (idani). figure 1 : the language model-which was trained on some source domain, e.g., airline-creates a representation (cls) for the review. since the review is from a domain on which it was not trained, the model's classifier mistakenly classifies it as negative (bottom). in idani (top), the representation is fed into a neuron-ranking method. the k-highest ranked neurons are modified by an intervention, to change the domain of the review, and the new representation is fed into the classifier, which correctly classifies it as positive. idani on a variety of well known da benchmarks, for a total of two text classification tasks (sentiment analysis, natural language inference) and one sequence tagging task (aspect identification), across 52 source-target domain pairs. we demonstrate that idani can improve results in many of these cases, with some significant gains. ## method given a model m with a classification module f and hidden dimensionality d, which was fine-tuned on data from a source domain d @xmath0, we receive unlabeled task data d @xmath1. as s ̸ = t, m 's performance is likely to deteriorate when processing x t compared to x s . thus, we would like to make the representation of x t more similar to that of x s (regardless of the labels). to do so, we apply the idani intervention method: to allow stronger intervention on neurons that are ranked higher, we scale the intervention with α ∈ r d , a log-scaled sorted coefficients vector in the range [0, β] such that α n 1 = β and α n @xmath2, where β is a hyperparameter @xcite . we denote the new set of representations as hs . ## results overall, we have 52 source to target domain adaptation experiments. some of these gains are quite impressive: in the aspect prediction task, we gain 18.8 and 14.4 f1 points when adapting the restaurants source domain to the target domains laptops and service, respectively. in other domain pairs, the gain is marginal. on average we gain 4 points with ∆ p o . in sentiment analysis, the airline domain (a) is quite different from the others, leading to lower init (initial performance) scores when it is the source domain. adapting from a using idani results in a gain of up to 4.9 accuracy points. when other domains are used as source domains, we see mostly marginal gains, as the upper bound is closer to the initial performance, leaving less room for improvement in this task (ub -init is low). in nli, it seems harder to improve: the room for improvement is lower (3.3 f1 points on average), which may imply that domain information is not crucial for this task. still, we do see some significant gains, e.g., an improvement of 2 f1 points when adapting from slate to the telephone domain. generally, across all tasks and domain pairs, probeless provides better performance than lin-ear as ∆ p @xmath3. this is in line with the insights from @xcite , who observed that probeless was better than linear when used for intervening on morphological attributes. ## conclusion in this work, we demonstrated the ability to leverage neuron-intervention methods to improve ood performance. we showed that in some cases, idani can significantly help models to adapt to new domains. idani performs best with oracle hyperparameters, but even with the default ones we see overall positive results. we showed that idani indeed focuses on domain-related information, as the gains come mostly from domain-related information, such as domain-specific aspect terms. importantly, idani is applied only during inference, unlike most other da methods. november 16-20, 2020, pages 7035-7045. association for computational linguistics. xiaochuang han and jacob eisenstein. 2019. unsupervised domain adaptation of contextualized embeddings for sequence labeling. in proceedings of the 2019 conference on empirical methods in natural language processing and the 9th international joint conference on natural language processing, emnlp-ijcnlp 2019, hong kong, china, november 3-7, 2019, pages 4237-4247. association for computational linguistics. minqing hu and bing liu. 2004. mining and summarizing customer reviews. in proceedings of the tenth acm sigkdd international conference on knowledge discovery and data mining, seattle, washington, usa, august 22-25, 2004, pages 168-177. acm. quang nguyen. 2015. the airline review dataset. maria pontiki, dimitris galanis, john pavlopoulos, harris papageorgiou, ion androutsopoulos, and suresh manandhar. 2014. semeval-2014 task 4: aspect based sentiment analysis. in proceedings of the 8th international workshop on semantic evaluation, se-meval@coling 2014, dublin, ireland, august 23-24, 2014, pages 27-35. the association for computer linguistics. roi reichart and ari rappoport. 2007. self-training for enhancement and domain adaptation of statistical parsers trained on small datasets. in proceedings of the 45th annual meeting of the association of computational linguistics, pages 616-623, prague, czech republic. association for computational linguistics. hassan sajjad, nadir durrani, and fahim dalvi. 2021. neuron-level interpretation of deep nlp models: a survey. arxiv, abs/2108.13138. tobias schnabel and hinrich schütze. 2014. flors: fast and simple domain adaptation for part-of-speech tagging. transactions of the association for computational linguistics, 2(0):15-26. cigdem toprak, niklas jakob, and iryna gurevych. 2010. sentence and expression level annotation of opinions in user-generated discourse. in acl 2010, proceedings of the 48th annual meeting of the association for computational linguistics, july 11-16, 2010, uppsala, sweden, pages 575-584. the association for computer linguistics. lucas torroba hennigen, adina williams, and ryan cotterell. 2020. intrinsic probing through dimension selection. in proceedings of the 2020 conference on empirical methods in natural language processing (emnlp), pages 197-216, online. association for computational linguistics. tomer volk, eyal ben-david, ohad amosy, gal chechik, and roi reichart. 2022. example-based hypernetworks for out-of-distribution generalization. arxiv preprint arxiv:2203.14276. adina williams, nikita nangia, and samuel r bowman. 2018. a broad-coverage challenge corpus for sentence understanding through inference. in 2018 conference of the north american chapter of the association for computational linguistics: human language technologies, naacl hlt 2018, pages 1112-1122. yftah ziser and roi reichart. 2018. pivot based language modeling for improved neural domain adaptation. in proceedings of the 2018 conference of the north american chapter of the association for computational linguistics: human language technologies, volume 1 (long papers), pages 1241-1251, new orleans, louisiana. association for computational linguistics. hui zou and trevor hastie. 2005. regularization and variable selection via the elastic net. journal of the royal statistical society: series b (statistical methodology), 67(2):301-320.