A dapter S oup: Weight Averaging to Improve Generalization of Pretrained Language Models (2023)

Abstract: Pretrained language models (PLMs) are trained on massive corpora, but often need to specialize to specific domains. A parameter-efficient adaptation method suggests training an adapter for each domain on the task of language modeling. This leads to good in-domain scores but can be impractical for domain- or resource-restricted settings. A solution is to use a related-domain adapter for the novel domain at test time. In this paper, we introduce AdapterSoup, an approach that performs weight-space averaging of adapters trained on different domains. Our approach is embarrassingly parallel: first, we train a set of domain-specific adapters; then, for each novel domain, we determine which adapters should be averaged at test time. We present extensive experiments showing that AdapterSoup consistently improves performance to new domains without extra training. We also explore weight averaging of adapters trained on the same domain with different hyper-parameters, and show that it preserves the performance of a PLM on new domains while obtaining strong in-domain results. We explore various approaches for choosing which adapters to combine, such as text clustering and semantic similarity. We find that using clustering leads to the most competitive results on novel domains.

## introduction large lms are pre-trained using massive amounts of data in a self-supervised way @xcite @xcite and obtain general-domain knowledge. in order to adapt them to a new domain, continuing training using in-domain data has been shown to be helpful @xcite @xcite . to avoid fine-tuning all parameters, efficient methods such as domain-specific mixtures-of-experts @xcite and ⋆correspondence to achron@cis.lmu.de or jessed@allenai.org †work done during an internship at allen ai weight-average selected adapters hierarchical domain adapters @xcite have been proposed. additional in-domain gains can be obtained using weight-space averaging @xcite . motivated by this, we propose using weight-space averaging at test time to improve performance on novel domains without extra training. our approach, adaptersoup, ensembles adapters in the weight space to improve performance on novel domains at test time without parameter updates. to this end, we train adapters on top of a plm, each in a different domain. we compare several methods for selecting which adapters to use for each novel domain at test time and propose weight-space averaging models selected using text clustering. we find that adaptersoup improves performance on novel domains. we also explore weight averaging adapters trained in the same domain, each with a different hyper-parameter configuration, and find that combining models trained with a low learning rate provides competitive indomain scores, while averaging models trained with high learning rates performs similarly to a general-purpose plm on novel domains. our contributions are the following: 1) we propose combining domain-adapted plms at inference time using adapters. our approach leads to consistent gains in novel domains. we compare several methods for choosing the models of the adapter-soup, concluding that text clustering provides the best performance across all domains. 2) we perform weight-space averaging of plms adapted to the same domain with varied hyper-parameters using adapters. we find that we can obtain competitive in-domain scores but also preserve the generalization ability of a plm. ## proposed approach problem statement. assuming we have a plm adapted to k domains d 1 , ..., d k , we want a model that performs well in a novel domain d k+1 without training more parameters. we use the provenance of a piece of text (that is, the website from which the text was scraped) as a proxy for textual domain. this follows @xcite ; @xcite . if we assume that we have a plm fine-tuned on a single domain d i with different hyper-parameters, we want to combine the fine-tuned models in order to both obtain good in-domain performance and preserve the generalization ability of the plm to novel domains. ## results results are presented in ## related work as training large models from scratch has a severe computational and environmental cost @xcite , efficient methods such as mixtures-of-experts (moe) @xcite @xcite , adapters @xcite @xcite , and lora layers @xcite have recently been proposed. both adapters and moes have shown to work well for domain adaptation @xcite @xcite . the hierarchy adapter @xcite outperforms our approach but is significantly more expensive. it adds a training cost of 4ld model dt (following @xcite over the cost of running gpt-2 for a model with l layers, dimension d model , adapter bottleneck size d, average tree depth t (@xmath0, while adaptersoup needs 4ld model d flops. as a result, training the hierarchy adapter is a factor of t slower than our approach. at inference time, the hierarchy adapter activates 2 paths in the tree and invokes a cost 4ld model dt × 2, i.e., inference is a factor of 2t slower than our approach. averaging weights of models independently finetuned on the same task @xcite has shown to improve in-domain performance. matena and raffel (2021) weight-average fine-tuned plm models using fisher merging to avoid intermediate task training and then perform downstream finetuning. @xcite fine-tune moes using adapters on a downstream task and average their weights at test time. our paper, however, focuses on improving test-time scores of a model on novel domains. @xcite improve performance in an unseen (target) language by ensembling the source language adapter and language adapters similar to the target language. this approach uses weighted ensembling of the outputs of adapters, whereas we ensemble the weights of the adapters. adaptersoup has the inference cost of a single adapter, while @xcite require inference time that scales linearly to the number of adapters. contemporaneous work @xcite also explores performance in novel domains using weight averaging, but uses moes instead of adapters. ## conclusion a plm can be adapted to new domains using adapters. however, this requires training a new set of adapters for each domain. we propose a method based on weight-space averaging of adapters selected using text clustering. our approach improves performance on novel domains without updating parameters or increasing the inference cost. future work could explore more sophisticated selection methods to try to match the performance of the oracle experiments.