Llama-3-8B Legal Summarizer (Fine-Tuned)
This model is a fine-tuned version of NousResearch/Meta-Llama-3-8B-Instruct trained for legal document summarisation on a combined dataset of:
- CUAD v1 โ Contract Understanding Atticus Dataset
- MAUD Dataset โ Merger Agreement Understanding Dataset
- Pile of Law โ Large-scale legal text corpus
Training Details
| Parameter | Value |
|---|---|
| Base model | NousResearch/Meta-Llama-3-8B-Instruct |
| Fine-tuning | QLoRA (4-bit, NF4) |
| LoRA rank | 8 |
| LoRA alpha | 16 |
| Epochs | 1 |
| Learning rate | 2e-4 |
| Optimizer | paged_adamw_8bit |
| Max seq length | 768 |
Usage
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
from peft import PeftModel
import torch
BASE_MODEL = "NousResearch/Meta-Llama-3-8B-Instruct"
REPO_ID = "ParthModi01/llama3-8b-legal-summarizer-ft"
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.float16,
bnb_4bit_use_double_quant=True,
)
tokenizer = AutoTokenizer.from_pretrained(REPO_ID)
base_model = AutoModelForCausalLM.from_pretrained(
BASE_MODEL, quantization_config=bnb_config,
dtype=torch.float16, device_map="auto"
)
model = PeftModel.from_pretrained(base_model, REPO_ID)
model.eval()
def summarize(text: str) -> str:
prompt = f"""### Instruction:
Summarize the following legal text in clear, concise language.
### Input:
{text}
### Response:
"""
inputs = tokenizer(prompt, return_tensors="pt", truncation=True, max_length=768).to(model.device)
with torch.no_grad():
outputs = model.generate(**inputs, max_new_tokens=256, do_sample=False)
generated = outputs[0][inputs["input_ids"].shape[-1]:]
return tokenizer.decode(generated, skip_special_tokens=True).strip()
print(summarize("Your legal text here ..."))
Intended Use
Legal document summarisation for contract review and clause extraction. Not a substitute for qualified legal advice.
Model tree for ParthModi01/llama3-8b-legal-summarizer-ft
Base model
NousResearch/Meta-Llama-3-8B-Instruct