Nyaya-1.5B (Indian-Legal-Qwen2.5-1.5B)
Domain-Adapted Legal Reasoning Model for India’s 2023 Criminal Law Reforms
Overview
Nyaya-1.5B (Indian-Legal-Qwen2.5-1.5B) is a compact, domain-adapted large language model fine-tuned on Qwen 2.5 (1.5B Instruct) for Indian criminal jurisprudence. It is trained across all 1,059 statutory sections of India’s 2023 criminal law framework, which superseded the colonial-era Indian Penal Code (1860), Code of Criminal Procedure (1973), and Indian Evidence Act (1872):
- Bharatiya Nyaya Sanhita (BNS 2023) — replacing IPC (1860)
- Bharatiya Nagarik Suraksha Sanhita (BNSS 2023) — replacing CrPC (1973)
- Bharatiya Sakshya Adhiniyam (BSA 2023) — replacing Indian Evidence Act (1872)
Using 6,354 multi-perspective instruction pairs from GSMS-B/Indian-Legal-QA-BNS-BNSS-BSA, the model is structured to deliver concise, section-grounded legal analysis with low memory and latency requirements—suitable for local inference, edge deployments, and retrieval-augmented generation (RAG) pipelines.
Key Highlights
- Complete 3-Act Statutory Coverage: Trained on all 358 sections of BNS, 531 sections of BNSS, and 170 sections of BSA.
- 6-Dimensional Section Decomposition: Each statutory section is modeled across six complementary perspectives:
definitional_topic— conceptual scope and subject matterdefinitional_section— exact statutory text and framingscenario— real-world fact-pattern applicationelements— Actus Reus and Mens Rea prerequisitesexceptions— statutory provisos, defenses, and safe harboursconsequence— punishments, bailability, and cognizability
- Lightweight Footprint: Fits in under 3.5 GB VRAM in 16-bit precision for fast inference on consumer GPUs and cloud instances.
- Merged 16-bit Weights: Distributed as standalone
safetensorsweights—ready to load directly without separate LoRA adapter merging.
Statutory Coverage
| Statutory Code | Full Title | Historic Predecessor | Sections Covered | Instruction Pairs |
|---|---|---|---|---|
| BNS 2023 | Bharatiya Nyaya Sanhita | Indian Penal Code (1860) | 358 | 2,148 |
| BNSS 2023 | Bharatiya Nagarik Suraksha Sanhita | Code of Criminal Procedure (1973) | 531 | 3,186 |
| BSA 2023 | Bharatiya Sakshya Adhiniyam | Indian Evidence Act (1872) | 170 | 1,020 |
| Total | Unified Criminal Law Framework | — | 1,059 | 6,354 |
Quickstart
1. Python (transformers)
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
model_id = "NamanAnand66/Nyaya-1.5B"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype=torch.float16,
device_map="auto",
)
SYSTEM_PROMPT = (
"You are Nyaya-1.5B, a legal assistant specialized in Indian Criminal "
"Jurisprudence (BNS, BNSS, and BSA 2023). Provide accurate, structured legal "
"analysis citing relevant sections, essential legal elements, and statutory consequences."
)
def ask_legal_assistant(query: str) -> str:
messages = [
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": query},
]
prompt = tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=True
)
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
with torch.no_grad():
outputs = model.generate(
**inputs,
max_new_tokens=400,
temperature=0.1,
top_p=0.9,
repetition_penalty=1.1,
pad_token_id=tokenizer.eos_token_id,
)
return tokenizer.decode(
outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True
)
print(
ask_legal_assistant(
"Explain the procedure and legal admissibility of electronic records under Section 61 and 63 of BSA 2023."
)
)
2. High-Throughput Serving (vLLM)
Serve the model as an OpenAI-compatible REST endpoint:
pip install vllm
vllm serve NamanAnand66/Nyaya-1.5B \
--dtype bfloat16 \
--max-model-len 4096 \
--port 8000
Query with the OpenAI Python SDK:
from openai import OpenAI
client = OpenAI(base_url="http://localhost:8000/v1", api_key="local-key")
response = client.chat.completions.create(
model="NamanAnand66/Nyaya-1.5B",
messages=[
{"role": "system", "content": "You are Nyaya-1.5B, an expert in BNS, BNSS, and BSA 2023."},
{"role": "user", "content": "Under BNSS 2023, what is the mandatory timeline for producing an arrested person before a Magistrate?"},
],
temperature=0.1,
)
print(response.choices[0].message.content)
3. Local CLI (Ollama)
ollama run hf.co/NamanAnand66/Nyaya-1.5B
Architecture & Training Details
flowchart LR
A["Statutory Legal Corpus<br/>BNS, BNSS, BSA 2023"] --> B["6-Perspective Structuring<br/>6 Archetypes / Section"]
B --> C[("6,354 Instruction Pairs<br/>ChatML Format")]
D["Qwen 2.5 1.5B Instruct"] --> E["QLoRA Fine-Tuning<br/>r=64, alpha=128, 8-bit AdamW"]
C --> E
E --> F["Weight Merge (16-bit)"]
F --> G["Indian-Legal-Qwen2.5-1.5B<br/>Merged Safetensors"]
Hyperparameters
| Configuration | Specification |
|---|---|
| Base Model | unsloth/Qwen2.5-1.5B-Instruct-bnb-4bit (Qwen/Qwen2.5-1.5B-Instruct) |
| Dataset | GSMS-B/Indian-Legal-QA-BNS-BNSS-BSA |
| Fine-Tuning Method | QLoRA (r = 64, lora_alpha = 128) |
| Target Modules | q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj |
| Epochs | 3 |
| Batch Size | 4 per device (Gradient Accumulation: 2) |
| Learning Rate | 2e-4 (Cosine schedule) |
| Optimizer | adamw_8bit |
| Context Length | 4,096 tokens |
| Training Stack | Unsloth + TRL SFTTrainer |
Recommended Use Cases
- RAG-Grounded Legal Assistants: Pair with hybrid retrieval (BM25 + dense embeddings) over statutory texts and case law to synthesize section-cited answers.
- Legacy-to-Reform Mapping: Assist in identifying outdated IPC, CrPC, and Evidence Act references in drafts or FIRs and mapping them to BNS, BNSS, and BSA equivalents.
- Procedural & Compliance Reference: Rapid lookup of arrest protocols, bail eligibility, cognizability, and evidentiary admissibility criteria.
- Academic & Judicial Exam Preparation: Structured Q&A study companion for law students, advocates, and judicial service aspirants.
Legal Disclaimer
IMPORTANT NOTICE
Nyaya-1.5B (Indian-Legal-Qwen2.5-1.5B) is an AI research model intended solely for informational, educational, and assistive purposes. It does not constitute legal advice and does not create an attorney-client relationship.Statutory provisions and judicial interpretations by High Courts and the Supreme Court of India evolve continuously. Always verify model outputs against official Government of India Gazette notifications and consult a qualified legal practitioner before relying on them in legal proceedings.
Credits
- Model Author & Publisher: NamanAnand66
- Training Dataset: GSMS-B/Indian-Legal-QA-BNS-BNSS-BSA
- Base Model: unsloth/Qwen2.5-1.5B-Instruct-bnb-4bit
- Fine-Tuning Framework: Unsloth