TL;DR
Even when a language model is trained on trillions of tokens, domain adaptation still matters. By further pre-training ModernBERT on 13 billion tokens of US court opinions, researchers created LegalModernBERT, achieving significant performance gains on legal NLP tasks while demonstrating that continued pre-training now beats training from scratch.
What Problem Does This Paper Address?
While generative AI dominates current headlines, encoder-only models like BERT remain the workhorses of practical NLP for tasks like document embedding, legal passage retrieval, and text classification. In the legal domain, these tasks are highly sensitive; public defenders and legal teams often cannot risk uploading privileged data to commercial, proprietary APIs due to mandatory disclosure laws. This makes small, open-source, in-house models essential.
Recently, models like ModernBERT updated the classic architecture by incorporating modern techniques (like FlashAttention and Rotary Position Embeddings) and training on massive 2-trillion-token datasets—500x more data than the original BERT. The authors of this paper investigate a fundamental question: Does a model already exposed to such a vast scale of general data still benefit from domain-specific adaptation? Furthermore, they re-evaluate whether the old wisdom of domain adaptation—building a model from scratch with a custom vocabulary—still holds true for modern architectures.
Methods
The authors conducted two primary types of pre-training experiments using the ModernBERT architecture (both base and large variants):
- Continued Pre-training: They took existing general-domain ModernBERT checkpoints and performed further Masked Language Modeling (MLM) on legal text.
- From-Scratch Pre-training: They trained the architecture completely from scratch using a specialized, in-domain legal vocabulary.
For both approaches, they leveraged ModernBERT's native support for long sequences, training with a constant batch size of 512 and an extended context length of up to 8,192 tokens. This long-context capability is a massive upgrade over the traditional 512-token limit of older BERT models, allowing the network to process entire court opinions natively.
Datasets
- Pre-training: The models were trained on the Collaborative Open Legal Data (COLD) dataset, encompassing 8.3 million US court opinions (approximately 13 billion words).
- Evaluation: The models were benchmarked across four legal NLP datasets:
- LexGLUE/SCOTUS: Classifying US Supreme Court opinions into 14 issue areas.
- LexGLUE/CaseHold: A multiple-choice question-answering task to identify the correct legal holding.
- LePaRD: A legal passage retrieval dataset based on judicial citations.
- BarExam QA: Retrieving relevant legal paragraphs corresponding to manual Bar Exam hypothetical questions.
Key Insights and Ideas
- The Domain Adaptation Paradigm Shift: In the past, domain-specific models like SciBERT or LegalBERT achieved the best results when trained entirely from scratch with a custom vocabulary. This paper reveals an "aha moment": for modern scale models, continued pre-training of a general checkpoint is superior. The massive floor established by 2 trillion tokens of general training outweighs the benefits of a specialized vocabulary.
- Modern Vocabularies are Highly Adaptive: ModernBERT’s tokenizer handles specialized legal text surprisingly well. When tokenizing the SCOTUS dataset, ModernBERT's sequences were only 1.9% longer than a custom legal tokenizer, compared to RoBERTa's sequences which were 3.7% longer.
- Context Length is a Game Changer: Legal text is notoriously long. Restricting the model to a 512-token window severely cripples its performance. Expanding the context window to 8,192 tokens yielded massive, double-digit performance boosts, proving that bidirectional encoders were previously bottlenecked by short context lengths.
Key Results
The domain-adapted model, LegalModernBERT, consistently outperformed vanilla ModernBERT and older baselines like RoBERTa-large across classification and retrieval tasks.
On the LexGLUE benchmarks, LegalModernBERT-base achieved a Micro-F1 of 67.5 on SCOTUS (up from 65.3) and 76.1 on CaseHold (up from 74.8). The large variant achieved the highest overall scores, reaching a 78.6 Micro-F1 on CaseHold.
For retrieval tasks (LePaRD and BarExam QA), the domain-adapted models also showed substantial improvements. Interestingly, for the smaller base model size, the "from scratch" model occasionally performed best on retrieval, suggesting that lexical specialization helps smaller models with search queries. However, at the large scale, the continued pre-trained LegalModernBERT-large remained the top performer.
Limitations and Future Work
- US-Centric Focus: The pre-training data was exclusively composed of US court opinions. Probing experiments revealed that while the model's knowledge of US terms and crimes improved, its performance on international legal concepts (like the European Court of Human Rights) actually decreased.
- Data Noise: The COLD dataset relies on optical character recognition (OCR) and PDF conversions, which introduce text artifacts. Preliminary cleaning experiments actually lowered performance, indicating that optimal data-cleaning pipelines for legal text require deeper exploration.
- Model Scope: The study was strictly confined to BERT-style encoder architectures and did not benchmark against generative models (like Llama or GPT-4) fine-tuned for legal instruction following.
Summary updated