Text Generation
Transformers
Safetensors
English
llama
legal
sri-lanka
property-law
qlora
legal-reasoning
conversational
text-generation-inference
Instructions to use Sivanuja/Legal_vision_llama-3.1-8B-instruct-v1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Sivanuja/Legal_vision_llama-3.1-8B-instruct-v1 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Sivanuja/Legal_vision_llama-3.1-8B-instruct-v1") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Sivanuja/Legal_vision_llama-3.1-8B-instruct-v1") model = AutoModelForCausalLM.from_pretrained("Sivanuja/Legal_vision_llama-3.1-8B-instruct-v1") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Sivanuja/Legal_vision_llama-3.1-8B-instruct-v1 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Sivanuja/Legal_vision_llama-3.1-8B-instruct-v1" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Sivanuja/Legal_vision_llama-3.1-8B-instruct-v1", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Sivanuja/Legal_vision_llama-3.1-8B-instruct-v1
- SGLang
How to use Sivanuja/Legal_vision_llama-3.1-8B-instruct-v1 with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "Sivanuja/Legal_vision_llama-3.1-8B-instruct-v1" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Sivanuja/Legal_vision_llama-3.1-8B-instruct-v1", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "Sivanuja/Legal_vision_llama-3.1-8B-instruct-v1" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Sivanuja/Legal_vision_llama-3.1-8B-instruct-v1", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use Sivanuja/Legal_vision_llama-3.1-8B-instruct-v1 with Docker Model Runner:
docker model run hf.co/Sivanuja/Legal_vision_llama-3.1-8B-instruct-v1
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
- 5
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