- Type
- NLP transfer-learning / fine-tuning pipeline
What does it do?
Domain adaptation is a natural-language-processing technique that takes a general pretrained language model and continues training it on target-domain text, such as medical, legal, or financial documents, so that it fits the vocabulary and conventions of that field.
The adapted model can then be fine-tuned on labelled examples for a specific task. Lee et al. (2020) illustrate the approach with BioBERT, a model pre-trained on biomedical corpora. Whether an adapted model outperforms the general one depends on the task and data, and it has to be checked on held-out examples.
The intuition behind the method
A general language model learns broad patterns from everyday text, but specialised fields use vocabulary, phrasing, and conventions that such text rarely contains. Rather than training a new model from scratch, domain adaptation reuses what the general model already knows and continues training it on examples from the target field. The aim is to keep the model's general language ability while sharpening its grasp of the domain.
History
Early NLP work on domain adaptation includes Blitzer et al. (2007), who studied domain adaptation for sentiment classification. Lee et al. (2020) give a documented later example in biomedical NLP: BERT was pre-trained on large biomedical corpora to address a word distribution shift between general and biomedical text. Domain adaptation is best understood as a case of transfer learning, in which a general pretrained language model is specialised to a new field.
When to use it
Use domain adaptation when your text comes from a specialised field such as medicine, law, or finance, when a general pretrained model performs poorly on that text, and when you have target-domain text and access to a suitable base model. It is suited to tasks of the kind studied in the BioBERT work, which covered named entity recognition, relation extraction, and question answering. Do not use it when no target-domain text is available, when the target text is close to general text so there is little shift to correct, or when compute for fine-tuning is not available. A specific minimum number of target examples cannot be given with confidence; the amount needed depends on the task, label quality, and model size, and should be judged by performance on held-out examples.
Limitations and considerations
- Requires target-domain text; without it there is no signal to specialise the model.
- The benefit depends on a real difference between the general and target text. If the target text is close to the general text, there is little for adaptation to correct.
- Fine-tuning a large pretrained model can be computationally demanding and may need GPU resources.
- The results reported in the BioBERT work are for biomedical tasks; they do not automatically carry over to legal, financial, or other fields.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Starts from an existing pretrained model rather than training from scratch, so the adaptation step only has to move the model's parameters toward the target field.
- Targets a specific gap: Lee et al. (2020) report that directly applying general NLP advances to biomedical text gave unsatisfactory results because of a word distribution shift, and that pre-training on biomedical corpora significantly outperformed previous state-of-the-art models on biomedical named entity recognition (0.62% F1 improvement), relation extraction (2.80% F1 improvement), and question answering (12.24% MRR improvement).
- Adaptation builds on general language knowledge rather than starting over, although that knowledge can also be eroded (see the pitfalls).
Applications
- Biomedical text mining, as in the BioBERT work by Lee et al. (2020) on named entity recognition, relation extraction, and question answering.
- Legal text such as contracts and case law.
- Financial text and reporting.
- Cross-domain sentiment classification, as studied by Blitzer et al. (2007), in which a model trained on one domain is applied to a new target domain.
How it works
How it works
Start from a general pretrained language model that has already learned broad linguistic patterns from large collections of text. Adaptation modifies this model rather than building a new one, so the choice of base model shapes what the adapted model can do. The suitable model depends on the task and on the model family in use.
Collect text from the target field, for example medical, legal, or financial documents. For continued pretraining this can be unlabelled text; for task fine-tuning it must be labelled examples of the task. Lee et al. (2020) attribute the unsatisfactory results of directly applying general-domain NLP advances to biomedical text to a word distribution shift from general to biomedical corpora; target-domain data is what addresses that kind of gap. The amount and quality of this data limit how far the model can specialise.
This step has two parts that are often confused. First, domain-adaptive pretraining continues the model's masked-language-model training on unlabelled target-domain text, as Lee et al. (2020) did by pre-training BERT on biomedical corpora. Second, task fine-tuning trains the model on labelled target examples for a specific task, such as named entity recognition or relation extraction. Use the first when you have unlabelled field text and want the model to learn the field's vocabulary, and the second when you have labelled task data. When both are available they can be combined, adapting to the field first and then fine-tuning on the labelled task data. Training objectives and hyperparameters depend on the task and are not fixed by the method. Fine-tuning a large pretrained model can be computationally demanding and may require GPU resources.
Test the adapted model on held-out target-domain examples and compare it with the unadapted base model on the same examples. Examples used during training, including any used to choose hyperparameters or stopping points, must not be reused for this comparison, because doing so measures memorisation rather than transfer to new text. Because continued training can erode general language ability, also evaluate on a general-domain control set. Use a separate validation split for choosing the learning rate and stopping point, and where feasible repeat training with several random seeds and report the variation, since results on small target sets can differ noticeably between runs.
Common pitfalls
- Fine-tuning on a small target set can overfit it, leaving the model worse on target text that differs slightly from the training examples.
- Evaluating the adapted model on examples it was trained on gives inflated scores that do not show the model transfers.
- Assuming adaptation helped without comparing against the unadapted base model on the same held-out examples; that comparison is the only evidence of benefit.
- Underestimating compute needs, since fine-tuning a large model may require GPU resources that are not available.
- Continued training on field text can erode general language ability (catastrophic forgetting), so the adapted model may perform worse on general text. Check this with a general-domain control set.
Frequently asked questions
How is domain adaptation different from training from scratch?
Training from scratch builds a model with no prior knowledge and typically needs large amounts of data and compute. Domain adaptation starts from a general pretrained model that already captures broad language patterns and continues training it on target-domain text. Starting from a pretrained model usually reduces the data and compute needed compared with training from scratch, although the actual saving depends on the task and model.
How much target-domain data do I need?
A fixed minimum number of examples cannot be given with confidence. The amount needed depends on the task, label quality, and model size. More high-quality target text generally helps continued pretraining, while a small labelled set risks overfitting. Whatever the amount, check the adapted model on held-out examples.
Do I need a GPU?
Often, yes. Fine-tuning a pretrained language model can be computationally demanding and may require GPU resources, especially for larger models. Estimate compute needs before starting.
What kinds of tasks does it support?
It is suited to text tasks in specialised fields such as medicine, law, and finance where a general model performs poorly. The BioBERT work covered named entity recognition, relation extraction, and question answering as examples.
Should I run continued pretraining, task fine-tuning, or both?
It depends on your data. If you have unlabelled text from your field, continued pretraining helps the model learn its vocabulary. If you have labelled examples for a specific task, task fine-tuning trains the model for that task. When both are available, adapt to the field first and then fine-tune on the labelled task data, which is the sequence used in the BioBERT work.
Related methods
Sources
Lee, J. et al. (2020). BioBERT: A Pre-trained Biomedical Language Representation Model. Bioinformatics.
Open DOI referenceBlitzer, J. et al. (2007). Biographies, Bollywood, Boom-boxes and Blenders: Domain Adaptation for Sentiment Classification. ACL.
Open publication reference