The Effects of In-domain Corpus Size on pre-training BERT

Chris Sanchez, Zheyuan ZhangarXiv 2022

Abstract

Many prior language modeling efforts have shown that pre-training on an in-domain corpus can significantly improve performance on downstream domain-specific NLP tasks. However, the difficulties associated with collecting enough in-domain data might discourage researchers from approaching this pre-training task. In this paper, we conducted a series of experiments by pre-training Bidirectional Encoder Representations from Transformers (BERT) with different sizes of biomedical corpora. The results demonstrate that pre-training on a relatively small amount of in-domain data (4GB) with limited training steps, can lead to better performance on downstream domain-specific NLP tasks compared with fine-tuning models pre-trained on general corpora.

Introduction

Large language models like BERT are incredibly capable but often struggle with the specialized terminology of fields like medicine, law, or finance. While domain-specific pre-training is the standard solution, it is often perceived as requiring massive datasets—the original BERT, for instance, used approximately 20GB of text. This perceived requirement creates a "chilling effect," discouraging researchers who cannot aggregate such large corpora. This study investigates the "minimum viable" corpus size needed to outperform general-domain models, demonstrating that high performance is achievable with far less data than previously thought.

Methodology

We pre-trained BERT-base models from scratch using biomedical text corpora of 4GB, 8GB, and 12GB. A critical component was the development of a custom vocabulary from the PubMed corpus. This vocabulary showed only a 52% overlap with the original BERT vocabulary, highlighting the distinct nature of biomedical jargon. By using a domain-specific vocabulary, the model can process complex terms as single units rather than fragmented sub-words.

The training utilized only the Masked Language Modeling (MLM) objective, omitting Next Sentence Prediction (NSP). Models were trained for 67,000 steps on 8x NVIDIA V100 GPUs. For evaluation, we used three tasks from the Biomedical Language Understanding & Reasoning Benchmark (BLURB):

  • NCBI-disease: Named Entity Recognition (NER).
  • PubMedQA: Question Answering (Yes/No/Maybe).
  • HoC (Hallmarks of Cancer): Document classification.

Results and Discussion

Our experiments reveal that the quality and relevance of data often outweigh sheer volume. Even the smallest experimental model, trained on just 4GB of in-domain data, consistently outperformed the general BERT baseline across all tasks.

Performance comparison of models pre-trained on varying corpus sizes against general BERT and PubMedBERT baselines.

As shown in the results, the 4GB model achieved a Micro F1 of 87.7 on NCBI-disease, compared to 84.3 for general BERT. Interestingly, the 12GB model reached 88.0, slightly exceeding the performance of the mature PubMedBERT model which was trained on a much larger 21GB corpus. We observed diminishing returns as corpus size increased from 8GB to 12GB, suggesting that the most significant performance gains occur in the initial stages of domain-specific data collection.

Furthermore, we conducted a cost-benefit analysis to quantify the investment required for these performance gains. Achieving a ~2% boost over the general BERT baseline cost approximately $1,071 on Azure cloud infrastructure.

Cost-benefit analysis of pre-training BERT on in-domain data using Azure V100 instances.

Conclusion

This research demonstrates that massive datasets are not a prerequisite for effective domain-specific language modeling. Pre-training from scratch on as little as 4GB of relevant data provides a substantial performance advantage over general-domain models. Future work should explore whether these findings hold across other specialized domains like law or finance and compare these "from-scratch" results against continual pre-training strategies.

Summary updated

BibTeX
@misc{sanchez2022effects,
  author = {Chris Sanchez and Zheyuan Zhang},
  title = {{The Effects of In-domain Corpus Size on pre-training BERT}},
  year = {2022},
  eprint = {2212.07914},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2212.07914},
}
Figure