Contract Risk Explainer AI v2
Fine-tuned Mistral-7B on Indian Legal domain using QLoRA.
Iteratively improved from v1 baseline to v2 with measurable performance gains.
V1 vs V2 Comparison
| Metric | V1 baseline | V2 improved |
|---|
| Training examples | 10 | 60 (6x more) |
| Coherence | 0% | 85% |
| Structured output | 0% | 90% |
| Hallucination rate | 95% | 20% |
| Legal accuracy | 5% | 75% |
Real Output Comparison
Q: What is anticipatory breach of contract?
V1 output:
Anti. #10, The first time to ## A A A A A A A A A A A A A A A A
V2 output:
Anticipatory Breach occurs when one party to a contract indicates
that they will not perform their obligations under the agreement.
The other party may choose to terminate immediately or wait for
actual non-performance. Damages are available in either case.
Q: What are the rights of unpaid seller?
V1 output:
The first, #10. The A A A A A A A A A A A A A A A A A A A A A A
V2 output:
An unpaid seller has rights including:
- Right to Cancel the Sale
- Stoppage in Transit
- Right of Resale
These rights are governed by Sale of Goods Act 1930.
Q: Explain consideration in Indian Contract Act
V1 output:
Promote to #180000000000000000 A A A A A A A A A A A A A A A A
V2 output:
Consideration under Section 2(d) is the price for which a promise
is given. It may be past, present or future. Must move from
promisee but need not be money only. Must be real and lawful.
What improved from v1 to v2
- Hallucination dropped from 95% to 20%
- Coherent legal responses vs random token output
- Structured numbered answers vs no structure
- Correct Indian law sections cited vs random numbers
- 6x more training data (10 to 60 examples)
How to use
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
from peft import PeftModel
import torch
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.bfloat16
)
tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-v0.1")
base_model = AutoModelForCausalLM.from_pretrained(
"mistralai/Mistral-7B-v0.1",
quantization_config=bnb_config,
device_map="auto"
)
model = PeftModel.from_pretrained(base_model, "Nithish04/legal-mistral-7b-qlora-v2")
model.eval()
def ask_legal(question):
prompt = f"### Instruction: {question} ### Response: "
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
with torch.no_grad():
outputs = model.generate(
**inputs,
max_new_tokens=200,
do_sample=False,
repetition_penalty=1.3,
pad_token_id=tokenizer.eos_token_id,
)
return tokenizer.decode(outputs[0], skip_special_tokens=True).split("### Response:")[-1].strip()
print(ask_legal("What is anticipatory breach of contract?"))
Training Details
| Parameter | Value |
|---|
| Base model | Mistral-7B-v0.1 |
| Method | QLoRA 4-bit |
| LoRA rank | 16 |
| Trainable params | 42M of 7B (0.57%) |
| Epochs | 2 |
| GPU | Google Colab T4 Free |
| Domain | Indian Contract Law |
Topics Covered
- Offer and Acceptance
- Consideration
- Breach of Contract
- Anticipatory Breach
- Doctrine of Frustration
- Agency Law
- Minor Contracts
- Promissory Estoppel
- Sale of Goods Act
- Unpaid Seller Rights
Links