Instructions to use AnuragBodkhe/legal-embedding-1.0 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use AnuragBodkhe/legal-embedding-1.0 with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("AnuragBodkhe/legal-embedding-1.0") sentences = [ "That is a happy person", "That is a happy dog", "That is a very happy person", "Today is a sunny day" ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [4, 4] - Notebooks
- Google Colab
- Kaggle
legal-embedding-1.0
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.
Model summary
| 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 |
Intended use
Embed a contract clause and use cosine similarity against other embedded clauses for:
- Similar-clause search β surfacing comparable clauses from a user's own prior contracts.
- Retrieval-augmented contract Q&A β retrieving the clauses most relevant to a natural-language question before an answer is generated or assembled from evidence.
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).
How to use
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.
Training data
CUAD contract clauses, split by document to prevent leakage:
| Split | Examples | Documents |
|---|---|---|
| Train | 7,705 | 353 |
| Validation | 1,711 | 70 |
| Test | 1,728 | 84 |
Training pair construction
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.
Training procedure
| Hardware | 1Γ RTX 3050 6 GB (laptop GPU), fp16, CUDA 12.6 |
| Wall clock | 5 minutes |
Evaluation results
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 |
What this changes in practice
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 |
Limitations and bias
- Training population. CUAD skews toward US commercial contracts. Retrieval quality on other jurisdictions or contract families has not been separately evaluated.
- Not a substitute for exact matching. For near-duplicate or boilerplate-variant clauses, a lexical baseline (signed hashing over word unigrams, bigrams and character 4-grams) can perform comparably or better; this model's advantage is on paraphrase, where lexical overlap is low or absent.
- A low-similarity result means "the contract does not address this," not a best guess. The serving platform withholds results below a cosine similarity of 0.25 and says so explicitly, rather than returning the nearest vector regardless of how far it is.
- Model-version scoping. Every similarity query in the serving platform filters on model name and version. Comparing vectors from two different model versions returns confident, silently wrong results β the platform's embedding store enforces this filter for exactly that reason, and any downstream use of this model outside that platform should do the same.
Index recommendation
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.
License
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.
Part of ContractGuard AI
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.
Model tree for AnuragBodkhe/legal-embedding-1.0
Base model
nreimers/MiniLM-L6-H384-uncased