Abstract
BERT has achieved impressive performance in several NLP tasks. However, there has been limited investigation on its adaptation guidelines in specialised domains. Here we focus on the legal domain, where we explore several approaches for applying BERT models to downstream legal tasks, evaluating on multiple datasets. Our findings indicate that the previous guidelines for pre-training and fine-tuning, often blindly followed, do not always generalize well in the legal domain. Thus we propose a systematic investigation of the available strategies when applying BERT in specialised domains. These are: (a) use the original BERT out of the box, (b) adapt BERT by additional pre-training on domain-specific corpora, and (c) pre-train BERT from scratch on domain-specific corpora. We also propose a broader hyper-parameter search space when fine-tuning for downstream tasks and we release LEGAL-BERT, a family of BERT models intended to assist legal NLP research, computational law, and legal technology applications.
Introduction
The advent of Transformer-based models, most notably BERT, has fundamentally changed the landscape of Natural Language Processing (NLP). Typically, these models are pre-trained on massive, general-purpose datasets like Wikipedia and BookCorpus, which provide a broad understanding of the English language. However, when these "generalist" models are applied to highly specialized fields like law, their performance often degrades.
Legal text is not merely formal English; it is a distinct sublanguage. It is characterized by archaic terminology (e.g., "heretofore"), complex nested syntactic structures, and semantic shifts where common words take on highly specific technical meanings. For instance, the word "consideration" in a legal contract refers to something of value exchanged between parties, a far cry from its everyday meaning of "thoughtfulness." This paper addresses the critical need for systematic guidance on adapting BERT to the legal domain, comparing different strategies to determine the most effective path for legal NLP applications.
Methodology: Strategies for Domain Adaptation
The researchers investigated three primary strategies for adapting BERT to the legal domain, as illustrated in the figure below:
- BERT-BASE (Out of the box): This serves as the baseline, using the original model pre-trained on generic English corpora and fine-tuning it directly on legal tasks.
- LEGAL-BERT-FP (Further Pre-training): This approach takes the pre-trained weights of BERT-BASE and continues the pre-training process on a large corpus of legal text. This allows the model to adjust its internal representations to better fit legal syntax and semantics.
- LEGAL-BERT-SC (Pre-training from Scratch): This is the most intensive approach, where a model is initialized with random weights and trained entirely on legal text. A key component of this strategy is the creation of a new domain-specific vocabulary of 30,000 sub-word units, ensuring that legal terms are represented efficiently rather than being fragmented.
Furthermore, the authors challenged the standard fine-tuning "recipes" often cited in literature. They found that the narrow hyperparameter ranges suggested in the original BERT paper—such as training for only 3-4 epochs—often lead to underfitting in specialized domains. They proposed a broader search space, including lower learning rates and early stopping based on validation performance.
Data and Evaluation
To train and evaluate these models, the authors compiled a diverse 12GB corpus of English legal text, totaling approximately 11.5 billion tokens. This corpus includes:
- Legislation: EU legislation from EURLEX and UK legislation.
- Court Cases: Decisions from the European Court of Justice (ECJ), the European Court of Human Rights (ECHR), and a large collection of US court cases.
- Contracts: US contracts sourced from the SEC-EDGAR database.
The models were evaluated across three distinct legal NLP benchmarks:
- EURLEX57K: A large-scale multi-label classification task involving EU laws.
- ECHR-CASES: Both binary and multi-label classification of human rights cases.
- CONTRACTS-NER: Named Entity Recognition (NER) focused on identifying parties, dates, and locations within US contracts.
Key Results and Insights
The experimental results consistently demonstrated the superiority of specialized legal models over the generic BERT-BASE.
Key findings include:
- Vocabulary Efficiency: The LEGAL-BERT-SC model, with its custom vocabulary, showed significant advantages. By representing legal terms as single units rather than multiple sub-words, the model captures legal concepts more effectively.
- The Impact of Tuning: The "tuned" versions of the models, which utilized the broader hyperparameter search space, significantly outperformed those following the standard BERT recipe. This highlights that specialized domains require more careful optimization.
- LEGAL-BERT-SMALL: The authors introduced a lightweight version of the model with only 6 layers (compared to 12 in BERT-BASE). Despite having only 32% of the parameters, LEGAL-BERT-SMALL achieved performance remarkably close to its larger counterparts while being 4x faster during training and significantly more efficient for inference.
- Lower Perplexity: The specialized models exhibited much lower perplexity on legal documents, indicating a much better fit for the "sublanguage" of law compared to the generic model.
Conclusion and Future Work
LEGAL-BERT demonstrates that domain adaptation is not a one-size-fits-all process. For the legal domain, specialized pre-training and careful hyperparameter tuning are essential for achieving state-of-the-art performance. The introduction of LEGAL-BERT-SMALL also provides a "green" and accessible alternative for researchers and practitioners with limited computational resources.
Future work may involve even more granular adaptation, such as models specialized for specific legal sub-fields like tax or intellectual property law. Additionally, extending this systematic approach to other languages and legal traditions remains a vital area for future research in computational law.
Summary updated