Skip to main content

LeBSE — Legal-BERT Sentence Embeddings (a legal-domain LaBSE)

CI Python License Code style: black Ruff Checked with ty

LeBSE adapts Google's LaBSE to the register of U.S. case law, so that legal sentences and opinions land in a better-organized embedding space than the general-purpose base model — while keeping LaBSE's 109-language alignment.

It is a drop-in sentence-transformers model: same API, same 768-dim output, same tokenizer.

from sentence_transformers import SentenceTransformer
m = SentenceTransformer("ahb-sjsu/lebse")          # or a local path
v = m.encode(["The district court lacked subject-matter jurisdiction over the claim."])

Why

General sentence encoders are trained on web text; their geometry is anisotropic (embeddings pile into a narrow cone) and tuned to everyday semantics, not the dense, formulaic register of judicial writing. LeBSE re-tunes the geometry on real opinions so that legally-related text is measurably closer and the space is more isotropic — useful for legal retrieval, clustering, near-duplicate and boilerplate detection, citation recommendation, and as a feature extractor for downstream legal NLP.

How it's trained (v2, citation-supervised)

Citation-supervised contrastive fine-tuning, SPECTER-style: positive pairs are (citing opinion body, cited opinion body) drawn from the CourtListener citation graph, and MultipleNegativesRanking Loss uses the rest of the batch as negatives. Base model: sentence-transformers/LaBSE. Corpus: U.S. federal opinions from the CourtListener / Free Law Project bulk data (public domain). No case outcomes are used.

# lebse-train = SimCSE (v1) baseline; lebse-train-citation = the v2 citation-supervised model.
lebse-train-citation --pairs pairs_train.jsonl --batch 96 --max-seq-len 128 --epochs 2 --out ./lebse

v1 was unsupervised SimCSE and did not beat base LaBSE (it's kept in MODEL_CARD.md for the record). The published weights are v2 (citation-supervised), which does — decisively.

Rigorous evaluation

Two held-out protocols with opinion-level splits (train/eval opinions are disjoint), so any gain is generalization: (1) citation retrieval — the trained relation, on held-out opinions; and (2) docket-lineage retrieval — an independent relation (a district opinion and its appellate reviewer, matched by docket number) the model never trained on. Each reports a paired bootstrap 95% CI on the AUROC gain.

Held-out results (v2, citation-supervised):

eval base LaBSE LeBSE-v2 Δ AUROC (95% CI)
citation retrieval (trained relation, held-out) 0.765 0.971 +0.206 [+0.190, +0.223]
docket-lineage (independent relation, unseen) 0.545 0.562 +0.018 [+0.004, +0.031]

LeBSE-v2 dramatically improves citation-type relatedness and transfers a small-but-significant amount to an independent legal relation (district↔appellate lineage) it never trained on. See MODEL_CARD.md for the full protocol and honest caveats. (v1 used unsupervised SimCSE and did not beat LaBSE — kept in the model card for the record.)

LEBSE_DSN="dbname=courtlistener" python eval.py --n 4000 --pairs 3000 --lebse ./lebse

Files

file purpose
train.py SimCSE fine-tune of LaBSE on legal sentences
eval.py held-out, citation-graph-based comparison vs base LaBSE
MODEL_CARD.md intended use, training data, metrics, limitations
requirements.txt pinned deps

License

Apache-2.0 (matching the LaBSE base). Training data is U.S. federal case law (public domain). See LICENSE.

Citation

@software{bond_lebse_2026,
  author = {Bond, Andrew H.},
  title  = {LeBSE: Legal-Domain Sentence Embeddings adapted from LaBSE},
  year   = {2026},
  url    = {https://github.com/ahb-sjsu/lebse}
}

Metadata

Release files for lebse 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lebse 0.2.0
File Size Uploaded Provenance
lebse-0.2.0.tar.gz 16.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for lebse 0.2.0
File Interpreter ABI Platform
lebse-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 31.1 kB

Release files / lebse-0.2.0.tar.gz

Download URL lebse-0.2.0.tar.gz
Size 16.1 kB
Tags Source
SHA-256 checksum
How to use checksums
a94eb028c32facc057bd27e0beceb12cbc9669c2fefe9e7219c0751a3200b3cd
BLAKE2b-256 checksum
How to use checksums
dc665f7beae9175e92e1e97176ca9a767461d4a940ec706d57e01a13df5c8a81
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.2

Release files / lebse-0.2.0-py3-none-any.whl

Download URL lebse-0.2.0-py3-none-any.whl
Size 15.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
754ab4040807effcd69e660d11a6e2deb1e0eade1898ff2b63b69e325b843715
BLAKE2b-256 checksum
How to use checksums
5a4832ee353ea3048147d949adcef75d95c2652e21d37d3534e704ee35d01b19
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.2

Security for lebse 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page