- Introduced by
- Reimers, N. & Gurevych, I. (Sentence-BERT); Gururangan et al. (domain-adaptive pretraining)
- Year
- 2019–2020
- Type
- Domain-adaptive representation learning
- Family
- Deep learning / NLP / CV
What does it do?
Domain-adaptive sentence embeddings extend general-purpose sentence encoders — such as Sentence-BERT — by continuing their training on domain-specific text.
The result is a fixed-length vector representation that captures both universal language understanding and the vocabulary, style, and semantic nuances of the target domain, improving downstream NLP tasks such as semantic search, clustering, and classification.
The intuition behind the method
A general sentence encoder learns broad language patterns from its training text, but it may handle the jargon, abbreviations and writing conventions of specialised fields less well. Domain adaptation addresses this in two optional stages. The model first continues pre-training on unlabelled in-domain text, which exposes it to the domain's vocabulary and phrasing. It can then be fine-tuned on labelled sentence pairs so that its notion of similarity matches the judgements used in that domain. The aim is that semantically similar domain sentences end up close together in vector space, which a general-purpose encoder may not achieve reliably.
History
Sentence-BERT (Reimers & Gurevych, 2019) adapted BERT into Siamese networks so that sentences could be encoded as vectors and compared directly, making sentence-level dense representations practical. Gururangan et al. (2020) studied continued pretraining of language models on in-domain text for classification tasks. They reported that a second phase of in-domain pretraining (domain-adaptive pretraining) improved performance across four domains, including biomedical and computer science publications, in both high- and low-resource settings. Their study used classification models rather than sentence encoders, so applying the same idea to sentence embeddings is a reasonable extension that the work cited here does not evaluate.
When to use it
Choose domain-adaptive sentence embeddings when your text is specialised, for example biomedical, legal, financial, scientific or social-media text, and a general-purpose encoder gives poor similarity or retrieval results on a held-out check. The approach suits semantic search, clustering and sentence-level classification where labelled data are scarce but unlabelled in-domain text is available. Do not use it when standard pre-trained encoders already perform adequately on your data, for example general news text, when computing resources for continued pre-training are unavailable, or when a simple TF-IDF or BM25 baseline already meets your accuracy requirements.
Limitations and considerations
- Domain-adaptive pretraining needs a large in-domain corpus to yield meaningful improvements; with little text, gains may be small or absent.
- Continued pre-training adds significant compute cost compared with using a frozen general-purpose encoder.
- If the target domain shifts over time, embeddings may become stale and require periodic re-adaptation.
- Evaluating embedding quality often requires building a domain-specific benchmark, which itself needs expert annotation effort.
- Adaptation to a narrow domain can reduce performance on general-purpose text, because the encoder's weights shift towards the in-domain corpus. Evaluate the adapted encoder on a general-domain held-out set as well as on the target domain.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Captures domain-specific vocabulary and discourse that generic encoders miss, improving similarity and retrieval quality.
- Domain-adaptive pretraining requires only unlabeled text, making it accessible when annotated data are scarce.
- Produces fixed-length embeddings that are computationally cheap to compare at inference time via cosine similarity.
- Composable: the adapted encoder can be further fine-tuned on task-specific labelled pairs for additional gains.
- Works across languages when combined with multilingual base models such as LaBSE or multilingual SBERT.
- Off-the-shelf frameworks (sentence-transformers library) make implementation straightforward.
Applications
- Semantic search and dense retrieval in domain-specific document collections (biomedical literature, legal case databases).
- Clustering of scientific abstracts or patents by topic without labelled categories.
- Sentence-level semantic similarity scoring for domain-specific duplicate detection or paraphrase identification.
- Zero-shot or few-shot text classification using embedding similarity to labelled exemplars.
- Question-answering pipelines where domain passages must be retrieved efficiently before a reader model.
- Multilingual cross-domain information retrieval when combined with multilingual base encoders.
How it works
How it works
Start from a pre-trained sentence encoder, commonly Sentence-BERT or one of its multilingual variants, which already maps sentences to vectors that reflect general semantic similarity. This encoder is the starting point; the adaptation steps update its weights.
Continue pre-training the encoder on a large unlabelled in-domain corpus, using masked language modelling as the self-supervised objective. This domain-adaptive pretraining (DAPT) updates the model weights so that its representations reflect domain vocabulary and discourse patterns, and it does not require labelled data.
When labelled sentence pairs or triplets are available, for example semantically similar or dissimilar pairs from domain annotations, fine-tune the encoder on them. Multiple negatives ranking loss is a contrastive objective: each positive pair is scored against the other in-batch examples, which act as negatives. Cosine similarity loss is different in kind; it regresses the cosine similarity of a labelled pair towards its target score. Both adjust the embedding space so that sentences judged similar in the domain end up close together.
At inference time, input sentences are tokenised and passed through the adapted encoder. Token-level hidden states are mean-pooled across sequence positions to produce a single fixed-length embedding vector per sentence, suitable for cosine similarity or dot-product comparisons.
Formula
\mathbf{u} = \text{MEAN-POOL}(\{h_1,\ldots,h_T\})The resulting domain-adapted embeddings are used in downstream tasks: semantic similarity scoring, clustering of domain documents, dense retrieval (bi-encoder search), zero-shot classification, or as input features for a lightweight classifier head trained on task-specific labelled data.
Common pitfalls
- Applying a general sentence encoder to highly specialised text without checking tokenisation. Domain terms may be split into many subword pieces, so the embedding can carry little of their meaning; compare key terms' tokenisation and results against the unadapted encoder.
- Skipping evaluation of embedding quality (e.g. retrieval recall@k or semantic similarity correlation) and assuming adaptation helped.
- Comparing embeddings with dot product when they are not normalised. Dot-product scores then depend on vector length and can rank results differently from cosine similarity, which already normalises by vector length. Check which measure the index or code uses.
- Contaminating domain adaptation data with test-set documents, inflating downstream evaluation metrics.
- Conflating fine-tuned sentence embeddings with domain-adaptive sentence embeddings. DAPT targets vocabulary and discourse, not a specific downstream task label.
Frequently asked questions
How much unlabeled domain text is needed for effective adaptation?
Gururangan et al. (2020) report gains from in-domain pretraining in both high- and low-resource settings, but the sources available for this page do not give a minimum corpus size. The amount needed depends on the domain and the task. Check empirically by comparing the adapted and unadapted encoders on held-out data, and add more in-domain text only if the comparison shows further gains.
Is domain-adaptive pretraining different from fine-tuning on labelled pairs?
Yes. Domain-adaptive pretraining (DAPT) uses unlabeled text and a self-supervised objective, masked language modelling in the work of Gururangan et al. (2020), to shift the encoder's representations toward domain vocabulary. Fine-tuning on labelled pairs then further adjusts similarity structure for a specific task. The two steps are complementary and are typically applied in sequence.
Can I use this approach without GPU resources?
Using a frozen, already domain-adapted model for inference needs only modest computing resources. Running domain-adaptive pretraining is computationally demanding and is normally done on GPUs; on a CPU it is slow even for moderately sized corpora.
How do I evaluate whether adaptation actually helped?
Build a held-out set of sentence pairs with human-annotated similarity scores, or a retrieval task measured by recall@k on domain queries, and keep it separate from all adaptation data. Compare the adapted and unadapted encoders on the same held-out data and the same metric. Where feasible, repeat training with several random seeds and report the mean and the spread. Judge the difference against this run-to-run variation rather than against a fixed threshold: a gain larger than the spread across runs is more convincing than a single higher score. Also check performance on general-domain text, since adaptation can reduce it.
Which base model should I start from?
The choice depends on your language and domain. Start from a Sentence-BERT-style encoder that suits your language; for multilingual text, use a multilingual variant of the same family. For specialised domains, check whether a model pre-trained on text close to yours is available. Verify the licence, training data and reported evaluation results on each model's current model card before use, because no source cited on this page evaluates particular checkpoints.
Related methods
Sources
Reimers, N. & Gurevych, I. (2019). Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks. Proceedings of EMNLP-IJCNLP 2019, pp. 3982–3992.
Open DOI referenceGururangan, S., Marasovic, A., Swayamdipta, S., Lo, K., Beltagy, I., Downey, D. & Smith, N. A. (2020). Don't Stop Pretraining: Adapt Language Models to Domains and Tasks. Proceedings of ACL 2020, pp. 8342–8360.
Open DOI reference