Downloads · 30 days
0
AnuragBodkhe/legal-embedding-1.0
legal-embedding-1.0 is a sentence similarity model from AnuragBodkhe. Use it when you need a score for how close two texts are. It is set up for sentence-transformers. The card lists the license as other.
A sentence-transformers bi-encoder, fine-tuned from all-MiniLM-L6-v2 on contract clauses, that maps a clause to a 384-dimensional vector for semantic similar-clause search and retrieval-augmented contract Q&A. It is M…
Downloads · 30 days
0
Access
Public
Updated Sep 23, 2026
Repo size
90.9 MB
Likes
1
Public
Click a slice to open those files.
.safetensors90.9 MB · 99%
From the Hugging Face model README
A sentence-transformers bi-encoder, fine-tuned from
all-MiniLM-L6-v2 on contract clauses, that maps a clause to a 384-dimensional
vector for semantic similar-clause search and retrieval-augmented contract
Q&A. It is Model 4 of five in ContractGuard AI,
an open-source clause-level contract analysis platform.
Not legal advice. This model retrieves clauses by semantic similarity. It does not itself determine legal effect — retrieved evidence is intended for a review workflow with a human in the loop.
| Base model | sentence-transformers/all-MiniLM-L6-v2 |
| Output dimension | 384 |
| Task | Sentence/clause embedding for cosine-similarity retrieval |
| Training data | CUAD, 11,144 examples from 507 documents |
| Version | 1.0 (active) |
| License | Other — see License |
Embed a contract clause and use cosine similarity against other embedded clauses for:
In scope: English-language commercial contract clauses, already segmented from the source document.
Out of scope: cross-lingual retrieval, whole-document embedding, and any comparison against vectors from a different model or version — embeddings are only meaningful compared against other embeddings from this exact model and version (see Model-version scoping).
from sentence_transformers import SentenceTransformer
from sentence_transformers.util import cos_sim
model = SentenceTransformer("AnuragBodkhe/legal-embedding-1.0")
clauses = [
"Either party may terminate this Agreement upon thirty (30) days' written notice.",
"This Agreement may be terminated by either party with 30 days prior notice.",
"The Confidential Information shall not be disclosed to any third party.",
]
embeddings = model.encode(clauses, normalize_embeddings=True)
print(cos_sim(embeddings[0], embeddings[1])) # near-duplicate termination clauses
print(cos_sim(embeddings[0], embeddings[2])) # unrelated confidentiality clause
The embedding width (384) is a hard contract with the rest of the platform:
the embeddings table, the service's embedding-dim setting, and this model's
hidden size are all enforced to agree — a model emitting a different width is
refused at load rather than silently corrupting retrieval.
CUAD contract clauses, split by document to prevent leakage:
| Split | Examples | Documents |
|---|---|---|
| Train | 7,705 | 353 |
| Validation | 1,711 | 70 |
| Test | 1,728 | 84 |
Positive pairs are same clause type, from different documents. Pairing two clauses from the same contract was deliberately avoided — it teaches the encoder to recognise a drafting house style rather than a legal concept, which is not what similar-clause retrieval needs.
Evaluation mirrors that constraint: a query's own source document is excluded from its candidate pool entirely, so the model cannot be rewarded for retrieving a sibling clause it has effectively already seen.
| Hardware | 1× RTX 3050 6 GB (laptop GPU), fp16, CUDA 12.6 |
| Wall clock | 5 minutes |
Measured on the held-out test split (1,728 examples from 84 unseen documents):
| Metric | Before fine-tuning | After fine-tuning |
|---|---|---|
| MRR | 0.7412 | 0.8412 |
| recall@5 | 0.0330 | 0.0465 |
| precision@5 | — | 0.7682 |
| nDCG@10 | — | 0.7631 |
The recall numbers understate the practical effect. Before fine-tuning, contract Q&A answered nothing for questions with no lexical overlap between the question and the clause text; after, it retrieves the right clause directly:
| Question | Retrieved clause | Before fine-tuning |
|---|---|---|
| "How much notice must I give to terminate?" | 7. TERMINATION | no evidence found |
| "Is there a non-compete?" | 8. RESTRICTIVE COVENANT | no lexical overlap |
| "Who owns the copyright in my work?" | 5. INTELLECTUAL PROPERTY | no lexical overlap |
For production-scale retrieval, an HNSW index over cosine distance is recommended (used as-is in ContractGuard's Postgres/pgvector deployment):
CREATE INDEX embeddings_vector_idx ON embeddings
USING hnsw (embedding vector_cosine_ops) WITH (m = 16, ef_construction = 64);
Order by the distance operator directly rather than a derived similarity score — only the operator form can use the index.
The base model, sentence-transformers/all-MiniLM-L6-v2, is licensed
Apache-2.0. Training data license: CUAD (CC BY 4.0). Review the upstream
license terms before commercial use in combination with this model's own
license terms.
This model is one of five in the ContractGuard AI
pipeline (clause classification, risk classification, legal NER, retrieval
embeddings, contract NLI). See the main repository and
docs/RETRIEVAL.md
for the full retrieval design, including the dimension contract, model-version
scoping, and user scoping enforced around this model.