LeBSE — legal-domain sentence embeddings adapted from LaBSE
Project description
LeBSE — Legal-BERT Sentence Embeddings (a legal-domain LaBSE)
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.mdfor 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}
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lebse-0.2.0.tar.gz.
File metadata
- Download URL: lebse-0.2.0.tar.gz
- Upload date:
- Size: 16.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a94eb028c32facc057bd27e0beceb12cbc9669c2fefe9e7219c0751a3200b3cd
|
|
| MD5 |
5435276f75511e5ae6bdce6dab172819
|
|
| BLAKE2b-256 |
dc665f7beae9175e92e1e97176ca9a767461d4a940ec706d57e01a13df5c8a81
|
File details
Details for the file lebse-0.2.0-py3-none-any.whl.
File metadata
- Download URL: lebse-0.2.0-py3-none-any.whl
- Upload date:
- Size: 15.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
754ab4040807effcd69e660d11a6e2deb1e0eade1898ff2b63b69e325b843715
|
|
| MD5 |
69c7d6a53e5b618c5e54017509a8028c
|
|
| BLAKE2b-256 |
5a4832ee353ea3048147d949adcef75d95c2652e21d37d3534e704ee35d01b19
|