Abstract
Pretrained transformer models have achieved state-of-the-art results in many tasks and benchmarks recently. Many state-of-the-art Language Models (LMs), however, do not scale well above the threshold of 512 input tokens. In specialized domains though (such as legal, scientific or biomedical), models often need to process very long text (sometimes well above 10000 tokens). Even though many efficient transformers have been proposed (such as Longformer, BigBird or FNet), so far, only very few such efficient models are available for specialized domains. Additionally, since the pretraining process is extremely costly in general - but even more so as the sequence length increases - it is often only in reach of large research labs. One way of making pretraining cheaper is the Replaced Token Detection (RTD) task, by providing more signal during training, since the loss can be computed over all tokens. In this work, we train Longformer models with the efficient RTD task on legal data to showcase that pretraining efficient LMs is possible using much less compute. We evaluate the trained models on challenging summarization tasks requiring the model to summarize long texts to show to what extent the models can achieve good performance on downstream tasks. We find that both the small and base models outperform their baselines on the in-domain BillSum and out-of-domain PubMed tasks in their respective parameter range. We publish our code and models for research purposes.
Introduction
Most popular Large Language Models (LLMs) like BERT or RoBERTa face a significant limitation: a "hard ceiling" at 512 tokens. While suitable for short-form content, this constraint is a major roadblock in specialized fields like law, where court opinions or contracts frequently span tens of thousands of tokens. While efficient architectures like the Longformer exist to handle long sequences, they face two primary challenges: a domain gap, as most are trained on general web text, and a "compute tax," where pretraining from scratch is prohibitively expensive for most academic and smaller research labs.
BudgetLongformer addresses these challenges by creating an English legal Longformer that is both high-performing and "budget-friendly" to train, democratizing access to state-of-the-art legal AI.
Methodology
The researchers combined two core innovations to achieve efficiency without sacrificing performance:
- Longformer Architecture: Unlike standard Transformers with quadratic complexity, Longformer utilizes a "sliding window" attention mechanism. This allows it to process sequences up to 4,096 tokens with linear complexity, making it ideal for long legal documents.
- Replaced Token Detection (RTD): Instead of standard Masked Language Modeling (MLM), which learns from only 15% of tokens, BudgetLongformer uses the RTD task. A small generator model replaces tokens with plausible alternatives, and a discriminator identifies these replacements. This approach is significantly more sample-efficient as the model learns from every token in the sequence.
Two versions were developed: a small model (29M parameters) and a base model (159M parameters).
Experimental Setup
The models were pretrained on the Pile of Law, a 256GB corpus of legal text. Experiments focused on two subsets: "caselaw" (Court Listener Opinions) and "diverse" (a mix of caselaw, legislation, contracts, and court filings).
Evaluation was conducted across three benchmarks:
- BillSum: Summarization of US Congressional bills (in-domain).
- PubMed: Summarization of long biomedical papers (out-of-domain generalization).
- LexGLUE: A multi-task benchmark for legal text classification and question answering.
Key Results and Discussion
Efficiency and Performance on Summarization
BudgetLongformer demonstrates massive compute savings. The small and base models required only 12 and 24 GPU days (NVIDIA V100s), respectively—a fraction of the 1,024+ days typically required for models like RoBERTa.
On the BillSum legal summarization task, the small model (29M params) outperformed the original paper's baseline (340M parameter BERT-large). The base BudgetLongformer approached the performance of PEGASUS-large, despite being nearly three times smaller and trained on orders of magnitude less data.
Performance on Legal Classification
On the LexGLUE benchmark, BudgetLongformer achieved results competitive with much more "expensive" architectures. This indicates that the model's benefits for long-text processing do not come at the cost of performance on shorter-text classification tasks.
Insights on Data Diversity and Generalization
Models trained on the "diverse" legal subset were more robust and performed better than those trained solely on court opinions, suggesting that exposure to various legal document structures (like contracts and legislation) improves representation learning. Furthermore, the legal-trained model generalized surprisingly well to the biomedical domain (PubMed), indicating that mastering long-range dependencies in one complex domain provides transferable structural benefits.
Conclusion
BudgetLongformer proves that high-performance, domain-specific language models can be built without massive budgets. While limited by geographic bias (primarily US law) and minimal hyperparameter tuning, the project opens doors for future work in "warm-starting" RTD training and applying these efficient models to complex legal reasoning tasks like contract review.
Summary updated