Downloads · 30 days
7
19% of all-time downloads
phamthanhfd/contract-analysis-lora-adapter
contract-analysis-lora-adapter is a machine learning model from phamthanhfd. 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.
QLoRA fine-tuned adapter for legal contract clause analysis on CUAD dataset.
Downloads · 30 days
7
19% of all-time downloads
All-time downloads
37
Public
Repo size
131 MB
Likes
0
Public
Click a slice to open those files.
.safetensors120 MB · 91%
From the Hugging Face model README
QLoRA fine-tuned adapter for legal contract clause analysis on CUAD dataset.
| Base Model | Qwen/Qwen2.5-3B-Instruct |
| Method | QLoRA (4-bit NF4, LoRA r=16 alpha=32) |
| Eval Loss | 0.2167 |
| Perplexity | 1.24 ✅ Excellent |
| Accuracy | 80% |
{"category": "confidentiality", "summary": "Employee must not disclose company secrets."}
Categories: salary · payment · confidentiality · liability · termination · insurance · dispute_resolution · other
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
from peft import PeftModel
import torch, json
bnb = BitsAndBytesConfig(load_in_4bit=True, bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.float16)
tokenizer = AutoTokenizer.from_pretrained("phamthanhfd/contract-analysis-lora-adapter")
base = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-3B-Instruct",
quantization_config=bnb, device_map="auto")
model = PeftModel.from_pretrained(base, "phamthanhfd/contract-analysis-lora-adapter")
SYSTEM = "You are a legal contract expert. Return JSON with category and summary."
clause = "The employee shall not disclose confidential information."
messages = [{"role":"system","content":SYSTEM},
{"role":"user","content":f"Analyze: {clause}"}]
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
with torch.no_grad():
out = model.generate(**inputs, max_new_tokens=150, temperature=0.1, do_sample=True)
gen = out[0][inputs["input_ids"].shape[-1]:]
print(json.loads(tokenizer.decode(gen, skip_special_tokens=True)))