Downloads · 30 days
9
12% of all-time downloads
Govardhan12345/legal-risk-classifier-lora
legal-risk-classifier-lora is a machine learning model from Govardhan12345. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for peft. The card lists the license as apache-2.0.
A LoRA fine-tuned adapter for Mistral 7B Instruct v0.3 that classifies commercial contract clauses by type and risk level, and generates a plain-English explanation — all in a single structured JSON output.
Downloads · 30 days
9
12% of all-time downloads
All-time downloads
76
Public
Repo size
336 MB
Likes
0
Public
Click a slice to open those files.
.safetensors336 MB · 99%
From the Hugging Face model README
A LoRA fine-tuned adapter for Mistral 7B Instruct v0.3 that classifies commercial contract clauses by type and risk level, and generates a plain-English explanation — all in a single structured JSON output.
This model takes a contract clause as input and returns:
It was fine-tuned using LoRA (Low-Rank Adaptation) on top of the frozen Mistral 7B Instruct v0.3 base model, trained on the CUAD (Contract Understanding Atticus Dataset) legal clause dataset.
Encoder-only models output a single label. This task requires three simultaneous outputs — classification, risk assessment, and natural-language explanation — in one coherent response. A decoder-based generative model produces all three in a single forward pass. Mistral 7B was additionally pre-trained on a broad corpus that includes legal text, giving it strong zero-shot legal reasoning before any fine-tuning was applied.
{
"clause_type": "Indemnification",
"risk_level": "High",
"summary": "You are responsible for all losses the other party suffers.",
"reason": "Broad unlimited indemnification — no liability cap specified."
}
CUAD — an expert-annotated legal dataset produced by the Atticus Project. 510 real commercial contracts annotated by practising lawyers and supervised law students across 41 clause categories.
Risk-level labels (High / Medium / Low) are not present in CUAD and were added as part of this project, based on legal exposure principles:
| Risk Level | Example Clause Types |
|---|---|
| High | Indemnification, Unlimited Liability, IP Ownership, Termination for Convenience, Non-Compete |
| Medium | Limitation of Liability, Governing Law, Payment Terms, Warranty |
| Low | Confidentiality, Notice Period, Audit Rights |
Unmapped clause types default to Medium as a conservative measure.
Evaluated on 454 held-out test examples never seen during training (High: 78, Medium: 325, Low: 51).
| Metric | Zero-Shot (Before) | Fine-Tuned (After) | Improvement |
|---|---|---|---|
| Overall F1 (weighted) | 67.36% | 88.71% | +21.35 pts |
| Accuracy | 67.62% | 88.99% | +21.37 pts |
| High Risk F1 | 47.29% | 76.81% | +29.52 pts |
| High Risk Recall | 61.54% | 67.95% | +6.41 pts |
| Medium Risk F1 | 78.06% | 92.63% | +14.57 pts |
| Medium Risk Recall | 76.62% | 94.77% | +18.15 pts |
| Low Risk F1 | 29.85% | 81.90% | +52.05 pts |
| Low Risk Recall | 19.61% | 84.31% | +64.70 pts (+330% relative) |
| JSON Parse Success | 99.34% | 100.00% | Perfect |
| Inference Failures | 3 | 0 | Zero failures |
| Avg Latency / clause | 13.85s | 11.33s | Faster |
| Method | Score | Source |
|---|---|---|
| RoBERTa-base | 8.2% P@80R | CUAD paper (Hendrycks et al. 2021) |
| DeBERTa-xlarge | 44.0% P@80R | CUAD paper (Hendrycks et al. 2021) |
| Best zero-shot LLM | ~52% F1 | ContractEval 2025 |
| Mistral 7B zero-shot (this model, pre-tuning) | 67.36% F1 | This project |
| Mistral 7B + LoRA (this model) | 88.71% F1 | This project |
from peft import PeftModel
from transformers import AutoModelForCausalLM, AutoTokenizer
base_model = AutoModelForCausalLM.from_pretrained(
"mistralai/Mistral-7B-Instruct-v0.3",
torch_dtype="bfloat16",
device_map="auto"
)
model = PeftModel.from_pretrained(base_model, "Govardhan12345/legal-risk-classifier-lora")
tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-Instruct-v0.3")
prompt = """<s>[INST] You are a legal risk analyst specialising in commercial contracts.
Analyse the following contract clause:
The contractor shall indemnify and hold harmless the employer from all claims.
Respond ONLY with a valid JSON object:
{
"clause_type": "...",
"risk_level": "High or Medium or Low",
"summary": "...",
"reason": "..."
} [/INST]"""
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
output = model.generate(**inputs, max_new_tokens=300, temperature=0.1)
print(tokenizer.decode(output[0], skip_special_tokens=True))
This model is designed as a decision-support tool for identifying and summarising contract risk — it is not a substitute for legal advice. High Risk classifications and edge cases should always be reviewed by a qualified professional before any contractual decision is made.