--- language: - en license: apache-2.0 base_model: unsloth/llama-3.2-3b-instruct-unsloth-bnb-4bit tags: - legal - indian-law - BNS - BNSS - BSA - criminal-law - llama - llama3 - qlora - unsloth - domain-adaptation - instruction-tuning - question-answering - law - india datasets: - GSMS-B/Indian-Legal-QA-BNS-BNSS-BSA pipeline_tag: text-generation --- # โš–๏ธ Indian Legal Llama 3.2 โ€” 3B

Base Model Domain Method Acts License

--- ## ๐Ÿ“– Model Description **Indian Legal Llama 3.2 โ€” 3B** is a domain-adapted version of [`unsloth/Llama-3.2-3B-Instruct`](https://huggingface.co/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 | The model was trained on **6,354 instruction-format QA pairs** โ€” 6 questions per section covering definitions, scenarios, legal elements, exceptions, and consequences โ€” giving it broad coverage of Indian criminal law provisions. --- ## ๐Ÿ”— Model Variants | 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](https://huggingface.co/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](https://huggingface.co/GSMS-B/Indian-Legal-Llama-3.2-3B-GGUF) | CPU inference via Ollama / llama.cpp | --- ## ๐Ÿš€ Quick Start ```python from transformers import AutoModelForCausalLM, AutoTokenizer import torch model_id = "GSMS-B/Indian-Legal-Llama-3.2-3B" tokenizer = AutoTokenizer.from_pretrained(model_id) model = AutoModelForCausalLM.from_pretrained( model_id, torch_dtype=torch.float16, device_map="auto" ) SYSTEM = "You are an expert legal assistant specializing in Indian criminal law โ€” BNS, BNSS, and BSA 2023." def ask(question): messages = [ {"role": "system", "content": SYSTEM}, {"role": "user", "content": question} ] text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True) inputs = tokenizer(text, return_tensors="pt").to(model.device) with torch.no_grad(): out = model.generate(**inputs, max_new_tokens=300, temperature=0.1, do_sample=True, pad_token_id=tokenizer.eos_token_id) return tokenizer.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True) print(ask("What is a Zero FIR under BNSS 2023?")) ``` ### ๐Ÿ’ป Run locally with Ollama (GGUF) ```bash ollama run hf.co/GSMS-B/Indian-Legal-Llama-3.2-3B-GGUF ``` --- ## ๐ŸŽฏ Recommended Use Cases > โš ๏ธ **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. ### โœ… Where this model works well | 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 | ### โŒ Not recommended for - Standalone legal advice without a retrieval component - High-stakes legal decisions without human expert review - Jurisdictions outside BNS / BNSS / BSA 2023 scope --- ## ๐Ÿ‹๏ธ Training Details | 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 | --- ## ๐Ÿ“Š Training Data | Dataset | Link | |---|---| | Indian Legal QA โ€” BNS + BNSS + BSA 2023 | [GSMS-B/Indian-Legal-QA-BNS-BNSS-BSA](https://huggingface.co/datasets/GSMS-B/Indian-Legal-QA-BNS-BNSS-BSA) | 6 question types per section: `definitional_topic` ยท `definitional_section` ยท `scenario` ยท `elements` ยท `exceptions` ยท `consequence` --- ## ๐Ÿ‘ค Author **GSMS-B** โ€” Bugatha Ganasyam Mani Sankar --- ## โš ๏ธ Disclaimer This model is intended for **research and educational purposes only**. It does not constitute legal advice. Outputs should not be relied upon for any legal decision without review by a qualified legal professional. The model's responses reflect patterns in training data and may contain errors or omissions. --- *Fine-tuned using [Unsloth](https://github.com/unslothai/unsloth) for training efficiency.*