A QLoRA fine-tuned version of
meta-llama/Llama-3.2-3B-Instruct on a domain-specific Nepali legal Q&A dataset. The model is trained to answer questions about Nepal's laws, constitution, and governance documents accurately, cite sources, and respond in the same language as the question.
Domain-specific Nepali legal Q&A pairs sourced from Nepal's constitution, acts, and governance documents. Dataset includes both Nepali and English language questions and answers with source citations.
Evaluated on 50 held-out test samples against the base model.
1from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
2from peft import PeftModel
3import torch
4
5base_model_id = "meta-llama/Llama-3.2-3B-Instruct"
6adapter_id = "Bibidh/civicLens-llama3.2-3b-nepali-legal"
7
8bnb_config = BitsAndBytesConfig(
9 load_in_4bit=True,
10 bnb_4bit_quant_type="nf4",
11 bnb_4bit_compute_dtype=torch.bfloat16,
12 bnb_4bit_use_double_quant=True,
13)
14
15tokenizer = AutoTokenizer.from_pretrained(base_model_id)
16base = AutoModelForCausalLM.from_pretrained(base_model_id, quantization_config=bnb_config, device_map="auto")
17model = PeftModel.from_pretrained(base, adapter_id)
18model.eval()
19
20SYSTEM_PROMPT = (
21 "You are CivicLens, a legal assistant specialized in Nepal's laws, "
22 "constitution, and governance documents. Answer questions accurately, "
23 "cite your sources, and respond in the same language as the question. "
24 "If you don't know, say so."
25)
26
27messages = [
28 {"role": "system", "content": SYSTEM_PROMPT},
29 {"role": "user", "content": "What are the fundamental rights guaranteed by the Constitution of Nepal?"},
30]
31
32prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
33inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
34outputs = model.generate(**inputs, max_new_tokens=256, do_sample=False)
35print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))