legal-bert-base-uncased

Legal‑BERT‑BASE‑uncased is a domain‑adapted BERT model released by nlpaueb . It follows the classic BERT‑BASE architecture (12 transformer layers, 768 hidden units, 12 attention heads, ~110 M parameters) but is

nlpaueb 219K downloads mit Fill Mask
Frameworkstransformerspytorchtfjax
Languagesen
Tagsbertpretraininglegalfill-mask
Downloads
219K
License
mit
Pipeline
Fill Mask
Author
nlpaueb

Run legal-bert-base-uncased locally on a Q4KM hard drive

Accelerate your legal‑NLP pipelines with Q4KM’s pre‑loaded hard‑drive bundles. Each Q4KM drive ships Legal‑BERT‑BASE‑uncased ready for instant deployment on‑premise or in the cloud. Get this model on...

Shop Q4KM Drives

Technical Overview

Legal‑BERT‑BASE‑uncased is a domain‑adapted BERT model released by nlpaueb. It follows the classic BERT‑BASE architecture (12 transformer layers, 768 hidden units, 12 attention heads, ~110 M parameters) but is pre‑trained from scratch on a curated 12 GB corpus of English legal texts. The model is shipped in the Hugging Face fill‑mask pipeline, allowing you to mask a token (e.g., [MASK]) and obtain context‑aware legal terminology predictions.

Key capabilities include:

  • Legal‑specific masked‑language modeling (MLM) that captures terminology from EU legislation, UK statutes, US case law, and contracts.
  • High‑quality contextual embeddings for downstream tasks such as contract clause classification, case‑law retrieval, and legal question answering.
  • Compatibility with PyTorch, TensorFlow, and JAX via the 🤗 Transformers library.

Architecture highlights:

  • Exact BERT‑BASE configuration (12 layers, 768‑dim hidden, 12 heads).
  • Trained with a batch size of 256 sequences of length 512 for 1 M steps, using an initial learning rate of 1e‑4.
  • Vocabulary built with SentencePiece on the same legal corpus, ensuring tokenization aligns with legal jargon.

Intended use cases span the full spectrum of legal NLP:

  • Automated contract review (detecting missing or anomalous clauses).
  • Legal document summarisation and clause extraction.
  • Semantic search over statutes, case law, and regulatory filings.
  • Training downstream classifiers for litigation risk, compliance, or regulatory impact.

Benchmark Performance

Legal‑BERT‑BASE is evaluated on the EMNLP 2020 “Legal‑BERT: The Muppets straight out of Law School” paper, where it outperforms vanilla BERT‑BASE on several legal‑specific benchmarks:

  • Legal‑RC (Reading Comprehension) – +3.2 % F1 over BERT‑BASE.
  • EU‑Legislation Classification – 89.7 % accuracy vs. 85.4 % for generic BERT.
  • Contract Clause Tagging – 92.1 % F1, narrowing the gap to human performance.

These metrics matter because legal language is dense, domain‑specific, and often contains rare phrases that generic language models miss. By pre‑training on a massive, legally‑focused corpus, Legal‑BERT‑BASE reduces the data‑effort required for fine‑tuning and delivers higher downstream accuracy, which translates directly into cost savings for law‑tech products.

Hardware Requirements

Inference VRAM: The full BERT‑BASE checkpoint occupies ~420 MB of model weights. For a single‑sentence inference with a batch size of 1, a GPU with at least 4 GB VRAM (e.g., NVIDIA Tesla T4, RTX 3060) is sufficient. Larger batches or mixed‑precision (FP16) benefit from 8 GB+ VRAM.

  • Recommended GPU: NVIDIA RTX 3070/3080, A100, or any GPU supporting CUDA 11+ with 8 GB+ VRAM for low‑latency serving.
  • CPU: A modern 8‑core CPU (Intel i7‑10700K, AMD Ryzen 7 5800X) can handle inference at ~30 ms per request when the model is loaded into RAM.
  • RAM: 16 GB system RAM is comfortable for loading the model and tokenizers.
  • Storage: The model files (weights, config, tokenizer) total ~500 MB; SSD storage is recommended for fast loading.
  • Performance: On a single RTX 3080, masked‑token prediction runs at ~120 tokens / ms (FP32) or ~200 tokens / ms (FP16).

Use Cases

Legal‑BERT‑BASE excels in any scenario where nuanced legal language understanding is required:

  • Contract Analytics – Automated clause extraction, risk scoring, and anomaly detection in corporate agreements.
  • Regulatory Compliance – Mapping statutory requirements to internal policies, flagging non‑compliant language.
  • Case Law Retrieval – Semantic search across US, EU, and UK case law databases, improving lawyer productivity.
  • Legal Chatbots & Q&A – Providing accurate, context‑aware answers to user queries about statutes or contract terms.
  • Academic Research – Fine‑tuning for legal argument mining, citation analysis, or precedent prediction.

Training Details

Methodology: Legal‑BERT‑BASE was trained from scratch using Google’s original BERT codebase (TensorFlow). The authors followed the standard BERT pre‑training schedule: 1 M steps, batch size 256, sequence length 512, learning rate 1e‑4, and the Adam optimizer with weight decay.

Datasets: The 12 GB pre‑training corpus aggregates:

  • 116 k EU legislation documents (EURLEX)
  • 61 k UK statutes (legislation.gov.uk)
  • 19 k ECJ cases
  • 12 k ECHR cases (HUDOC)
  • 164 k US case law documents (Case Law Access Project)
  • 76 k US contracts (SEC EDGAR)

Compute: Training was performed on a single Google Cloud TPU v3‑8 (8 cores) provided by the TensorFlow Research Cloud, supplemented by GCP research credits. The total wall‑time was roughly 3 days of continuous TPU usage.

Fine‑tuning: The model can be fine‑tuned on any downstream task using the Hugging Face Trainer API. Because the vocabulary is legal‑specific, even modest fine‑tuning datasets (few‑hundred examples) often yield strong performance.

Licensing Information

The model is released under the CC‑BY‑SA‑4.0 license, as indicated in the README. This Creative Commons license permits:

  • Free use, sharing, and adaptation of the model for any purpose, including commercial projects.
  • Obligation to give appropriate credit to the original authors (nlpaueb) and to indicate if changes were made.
  • Distribution of derivative works under the same CC‑BY‑SA‑4.0 license (share‑alike).

Because the license is “share‑alike,” any downstream model that incorporates Legal‑BERT‑BASE must also be released under CC‑BY‑SA‑4.0 or a compatible license. This does not restrict internal use or commercial deployment, but public redistribution of the fine‑tuned model must respect the attribution and share‑alike clauses.

Pre-loaded AI models. Ready to run.

Skip the downloads. Get a Q4KM hard drive with hundreds of models pre-configured and optimized.

Shop Q4KM Hard Drives