Views
No views yet
unsloth/Llama-3.2-3B-Instruct, fine-tuned using QLoRA on a structured question-answer dataset covering all 1,059 sections of India's three 2023 criminal justice acts:| Act | Full Name | Replaces | Sections |
|---|---|---|---|
| 📕 BNS 2023 | Bharatiya Nyaya Sanhita | IPC 1860 | 358 |
| 📗 BNSS 2023 | Bharatiya Nagarik Suraksha Sanhita | CrPC 1973 | 531 |
| 📘 BSA 2023 | Bharatiya Sakshya Adhiniyam | Indian Evidence Act 1872 | 170 |
| Variant | Repo | Best For |
|---|---|---|
| 🟢 Merged (this repo) | GSMS-B/Indian-Legal-Llama-3.2-3B | Out-of-the-box inference, Gradio/API deployment |
| 🔵 LoRA Adapter | GSMS-B/Indian-Legal-Llama-3.2-3B-Adapter | Lightweight loading on top of base model |
| 🟡 GGUF (Quantized) | GSMS-B/Indian-Legal-Llama-3.2-3B-GGUF | CPU inference via Ollama / llama.cpp |
1from transformers import AutoModelForCausalLM, AutoTokenizer
2import torch
3
4model_id = "GSMS-B/Indian-Legal-Llama-3.2-3B"
5tokenizer = AutoTokenizer.from_pretrained(model_id)
6model = AutoModelForCausalLM.from_pretrained(
7 model_id,
8 torch_dtype=torch.float16,
9 device_map="auto"
10)
11
12SYSTEM = "You are an expert legal assistant specializing in Indian criminal law — BNS, BNSS, and BSA 2023."
13
14def ask(question):
15 messages = [
16 {"role": "system", "content": SYSTEM},
17 {"role": "user", "content": question}
18 ]
19 text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
20 inputs = tokenizer(text, return_tensors="pt").to(model.device)
21 with torch.no_grad():
22 out = model.generate(**inputs, max_new_tokens=300, temperature=0.1,
23 do_sample=True, pad_token_id=tokenizer.eos_token_id)
24 return tokenizer.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
25
26print(ask("What is a Zero FIR under BNSS 2023?"))ollama run hf.co/GSMS-B/Indian-Legal-Llama-3.2-3B-GGUF⚠️ Important Note: This model has been domain-adapted on structured QA data and works best when used as a component in a larger system rather than as a standalone answer engine. Direct usage may produce incomplete or imprecise answers on complex legal queries.
| Use Case | How to Use |
|---|---|
| 🔍 RAG (Retrieval-Augmented Generation) | Use a retriever (BM25, vector search) to fetch relevant BNS/BNSS/BSA sections, then pass to this model as context for grounded answers |
| 🤖 Legal Chatbot Backend | Combine with a document store of the actual act texts; use this model for generation with retrieved context |
| 📚 Legal Education Tool | Build Q&A apps for law students learning the new 2023 acts |
| 🔎 Section Lookup Assistant | Pair with a section index to quickly surface which section of BNS/BNSS/BSA applies to a given situation |
| 🧪 Research & Experimentation | Fine-tune further on specific sub-domains (e.g., only BNSS procedure, only BSA evidence rules) |
| 📝 Structured Legal Summarization | Summarize specific sections when given the section text as input context |
| Property | Value |
|---|---|
| Base model | meta-llama/Llama-3.2-3B-Instruct |
| Fine-tuning method | QLoRA |
| LoRA rank | 64 |
| LoRA alpha | 128 |
| Target modules | q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj |
| Training data | 6,354 QA pairs — 1,059 sections × 6 question types |
| Epochs | 3 |
| Batch size (effective) | 4 |
| Learning rate | 2e-4 |
| Optimizer | adamw_8bit |
| Hardware | Google Colab T4 GPU |
| Framework | Unsloth + TRL SFTTrainer |
| Prompt format | ChatML |
| Dataset | Link |
|---|---|
| Indian Legal QA — BNS + BNSS + BSA 2023 | GSMS-B/Indian-Legal-QA-BNS-BNSS-BSA |
definitional_topic · definitional_section · scenario · elements · exceptions · consequence