Mixture-of-Domain-Adapters: Decoupling and Injecting Domain Knowledge to Pre-trained Language Models Memories

Shizhe Diao, Tianyang Xu, Ruijia Xu, Jiawei Wang, Tong Zhang

TL;DR

The authors introduce Mixture-of-Domain-Adapters (MixDA), a parameter-efficient method that injects domain-specific knowledge into pre-trained language models (PLMs) without altering their original memories. By decoupling the Transformer's feed-forward networks (FFNs) and training parallel domain adapters alongside a dynamic routing gate, MixDA achieves state-of-the-art performance across in-domain, out-of-domain, and knowledge-intensive tasks while avoiding catastrophic forgetting.

What Problem Does This Paper Address?

While pre-trained language models (PLMs) excel at general language understanding, they frequently stumble when applied to specialized domains like medicine, finance, or computer science. The traditional remedy—continued pre-training on a massive domain-specific corpus—is computationally prohibitive for most organizations because it requires updating all of the model's parameters.

On the flip side, parameter-efficient fine-tuning (PEFT) methods like standard adapters or LoRA reduce compute costs but typically focus on task adaptation rather than domain adaptation. If you try to force these PEFT methods to learn a new domain by training them directly on a domain corpus, the model suffers from catastrophic forgetting—it overwrites its original, general-world knowledge to make room for the new data.

MixDA addresses this fundamental tension: How can we efficiently inject new domain knowledge into a PLM while keeping its existing general-domain knowledge completely intact?

Methods

MixDA builds on recent mechanistic interpretability research showing that factual knowledge in Transformers is primarily stored within the feed-forward networks (FFNs). Guided by this insight, the authors decouple the FFN layer into two parallel paths: the original, frozen pre-trained FFN (which preserves old knowledge) and a lightweight, trainable domain-adapter.

The training is split into a novel two-stage adapter-tuning strategy:

Figure 1: The overall structure of the model. Our training method includes two stages: (a) In Stage 1, we introduce domain-adapters into the model and freeze other parameters. The model learns from domain-specific knowledge (knowledge loss LK) and keeps similar outputs with the FFN on old-domain knowledge (sample loss LS). LK and LS are then combined into the total loss L. (b) In Stage 2, we introduce the mixture-of-adapters gate and task-adapters, then freeze the domain-adapter. The model is trained to perform downstream tasks, which gives us the total loss L. (c) shows the detailed structures of the domain-adapter and the MoA gate.
  1. Stage 1: Domain-Specific Tuning (Unlabeled Data) The domain-adapter is trained on a mix of unlabeled domain-specific data and general pre-training data. To ensure the new adapter doesn't drift too far from the original model's latent space, the authors introduce a dual loss function: $$\mathcal{L} = \lambda \cdot \mathcal{L}_K + \mathcal{L}_S$$ Where $\mathcal{L}_K$ is the standard masked language modeling (MLM) knowledge loss, and $\mathcal{L}_S$ is a sampling loss ($L_2$ loss) that forces the domain-adapter's outputs to remain similar to the original FFN's outputs when processing general-domain text.

  2. Stage 2: Task-Specific Tuning (Labeled Data) The domain-adapters are frozen. The authors introduce a trainable Mixture-of-Adapters (MoA) gate and a standard task-adapter. The MoA gate uses a Sigmoid-activated multi-layer perceptron to dynamically weight and combine the outputs of the original FFN and the various domain adapters based on the input context.

Datasets

The authors evaluated MixDA across 15 different datasets spanning three distinct categories:

  • Out-of-Domain (OOD): ChemProt (biomedical), RCT (PubMed sentence classification), IMDB (movie reviews), and Amazon (product reviews).
  • In-Domain (ID): The GLUE benchmark (including MNLI, CoLA, MRPC, SST-2, RTE, STS-B, WNLI, QNLI, QQP).
  • Knowledge-Intensive (KI): FEVER (fact verification) and CommonsenseQA (CSQA).

The unstructured text used to train the domain adapters in Stage 1 is summarized below:

Domain knowledge corpora used in Stage 1 training.

Key Insights and Ideas

  • Parallel Knowledge Injection: Instead of stacking adapters sequentially (which can bottleneck information), placing domain adapters parallel to the FFN layers allows the model to treat them as an isolated, plug-and-play key-value memory space.
  • The Power of Sampling Loss: The ablation studies revealed that omitting the old-domain sampling loss ($\mathcal{L}_S$) caused a significant performance drop (7.5% on average). This proves that simply training an adapter on new data isn't enough; you must explicitly anchor its latent space to the base model's original representations to prevent representation collapse.
  • Scalability for LMaaS: Because the base PLM remains completely frozen and the MoA gate can route inputs dynamically, multiple domain adapters can sit side-by-side. This makes MixDA highly suitable for "Language Model as a Service" (LMaaS) settings, where a single base model server can support diverse, customized domain applications simultaneously.

Key Results

The authors evaluated MixDA in a strict few-shot setting ($K=16$ labeled examples for task tuning).

Overall performance of single MixDA compared to PEFT baselines and full fine-tuning.
  • Outperforming Baselines: MixDA achieved an average score of 52.2% across all tasks, outperforming the best baseline adapter (Pfeiffer) by 3.5% and full fine-tuning (FT) by 3.3%.
  • Exceptional OOD Gains: The model showed its strongest improvements on highly specialized out-of-domain tasks. On ChemProt, MixDA beat the Pfeiffer adapter baseline by 6.9% and full fine-tuning by 2.7%.
  • Structured Knowledge Integration: When the domain adapters were trained on a combination of unstructured text and structured knowledge graphs (ConceptNet), performance on knowledge-intensive tasks like FEVER skyrocketed by 10.3% (jumping from 20.2% to 30.5%).

Limitations and Future Work

The primary limitation acknowledged by the authors is that MixDA is a two-stage approach rather than a fully end-to-end training pipeline. It requires separate phases for domain knowledge injection and task adaptation.

As a direction for future work, the authors plan to explore unifying these two stages, potentially finding ways to merge or co-train the domain and task adapters into a single, streamlined architecture without sacrificing the decoupling benefits.

Summary updated

BibTeX
@inproceedings{diao2023mixture,
  author = {Shizhe Diao and Tianyang Xu and Ruijia Xu and Jiawei Wang and Tong Zhang},
  title = {{Mixture-of-Domain-Adapters: Decoupling and Injecting Domain Knowledge to Pre-trained Language Models Memories}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2023},
  doi = {10.18653/v1/2023.acl-long.280},
}
Figure