Downloads · 30 days
3
6% of all-time downloads
Kamalesh-genai/phi3-mini-legal-clause-lora
phi3-mini-legal-clause-lora is a text classification model from Kamalesh-genai. Use it when you need a label for a piece of text. It is set up for peft. The card lists the license as mit.
This is a LoRA (QLoRA) adapter fine-tuned on top of microsoft/Phi-3-mini-4k-instruct for legal contract clause classification, trained on a subset of the CUAD (Contract Understanding Atticus Dataset).
Downloads · 30 days
3
6% of all-time downloads
All-time downloads
52
Public
Repo size
17.8 MB
Likes
1
Public
Click a slice to open those files.
.safetensors17.8 MB · 83%
From the Hugging Face model README
This is a LoRA (QLoRA) adapter fine-tuned on top of microsoft/Phi-3-mini-4k-instruct for legal contract clause classification, trained on a subset of the CUAD (Contract Understanding Atticus Dataset).
transformers, peft, trl (SFTTrainer)from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
from peft import PeftModel
import torch
base_model_id = "microsoft/Phi-3-mini-4k-instruct"
adapter_id = "Kamalesh-genai/phi3-mini-legal-clause-lora"
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.bfloat16,
)
tokenizer = AutoTokenizer.from_pretrained(base_model_id)
base_model = AutoModelForCausalLM.from_pretrained(
base_model_id, quantization_config=bnb_config, device_map="auto"
)
model = PeftModel.from_pretrained(base_model, adapter_id)
prompt = (
"<|user|>\nYou are a legal contract analyst. Classify the following "
"contract clause into exactly ONE of these categories: Parties, "
"License Grant, Cap On Liability, Anti-Assignment, Audit Rights, "
"Insurance, Expiration Date, Governing Law.\n\n"
"Clause:\n\"\"\"This Agreement shall be governed by the laws of the "
"State of New York.\"\"\"\n\nCategory:<|end|>\n<|assistant|>\n"
)
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
out = model.generate(**inputs, max_new_tokens=10)
print(tokenizer.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))
Fine-tuned by Kamaleshwar S as a portfolio project — training code on GitHub