LegalVision: Sri Lankan Property Law Reasoning Model
Fine-tuned Llama 3.1 8B for Sri Lankan property law with step-by-step legal reasoning, IRAC analysis, and statute citations.
Project Info
| Field | Details |
|---|---|
| Project | LegalVision (ID: 25-26J-127) |
| Component | Explainable Legal Reasoning Module |
| Author | S. Sivanuja |
| Collaborator | Sharan (Knowledge Graph) |
| Supervisors | Ms. Vindhya Kalapuge, Ms. Adya Dissanayake |
| Institution | IIT Sri Lanka / University of Westminster |
Training Config
| Spec | Value |
|---|---|
| Base Model | Llama-3.1-8B-Instruct |
| Method | QLoRA (4-bit) |
| LoRA Rank | 64 |
| Epochs | 3 |
| Learning Rate | 2e-4 |
Topics: Property Transfer, Bim Saviya, Prescription, Partition, Mortgage, Lease, State Land, Foreign Ownership, Inheritance
Usage
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
from peft import PeftModel
import torch
bnb_config = BitsAndBytesConfig(load_in_4bit=True, bnb_4bit_compute_dtype=torch.bfloat16)
base = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-3.1-8B-Instruct", quantization_config=bnb_config, device_map="auto")
model = PeftModel.from_pretrained(base, "YOUR_USERNAME/legalvision-srilanka-llama3.1-8b")
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-3.1-8B-Instruct")
messages = [
{"role": "system", "content": "You are a Sri Lankan property law expert. Provide IRAC analysis with statute citations."},
{"role": "user", "content": "What are the requirements for property transfer?"}
]
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
output = model.generate(**inputs, max_new_tokens=1024, temperature=0.7)
print(tokenizer.decode(output[0], skip_special_tokens=True))
API Deployment (Inference Endpoints)
Includes handler.py for HuggingFace Inference Endpoints.
Request:
{
"messages": [{"role": "user", "content": "Can foreigners buy land in Sri Lanka?"}],
"parameters": {"max_new_tokens": 1024, "temperature": 0.7}
}
Response:
{
"generated_text": "**Answer:** Foreigners face restrictions under the Land (Restrictions on Alienation) Act...",
"usage": {"prompt_tokens": 156, "completion_tokens": 423, "total_tokens": 579}
}
Limitations
- Sri Lankan property law only - not for other jurisdictions
- Informational purposes - not legal advice
- Consult a qualified lawyer for actual legal matters
Citation
@misc{legalvision2025,
author = {Sivanuja, S.},
title = {LegalVision: Sri Lankan Property Law Reasoning Model},
year = {2025},
publisher = {HuggingFace},
note = {Project ID: 25-26J-127, IIT Sri Lanka}
}
LegalVision | IIT Sri Lanka | University of Westminster | © 2025
- Downloads last month
- 21
Model tree for Sivanuja/Legal_vision_llama-3.1-8B-instruct-v1
Base model
meta-llama/Llama-3.1-8B Finetuned
meta-llama/Llama-3.1-8B-Instruct