LegalTrace-Qwen3-4B-LSI
LegalTrace-Qwen3-4B-LSI is a domain-adapted instruction-tuned model specialized in Legal Statute Identification (LSI) under Indian Criminal Law. It maps narrative case facts and FIR/charge sheet descriptions directly to relevant Indian Penal Code (IPC) sections across 100 core statute categories.
This repository contains the merged 16-bit standalone weights (bfloat16) derived from fine-tuning Qwen/Qwen3-4B-Instruct-2507 using QLoRA over the ILTUR criminal case corpus.
🏆 Key Benchmark Results
Evaluated against 1,000 held-out zero-leakage Indian court judgments (test_subset):
| Model / Approach | Training Set | Macro-F1 | Micro-F1 | Example-F1 | Invalid Format Rate | Inference Latency |
|---|---|---|---|---|---|---|
| Zero-Shot Base Qwen3-4B | 0 | 0.0569 | 0.1028 | 0.0877 | 24.2% | 2.15s / case |
| Rule-Based Trivial Top-4 | 8,000 | 0.0145 | 0.2112 | 0.2029 | 0.0% | <0.01s / case |
| TF-IDF + Logistic Regression (OvR) | 8,000 | 0.1716 | 0.3846 | 0.3492 | 0.0% | <0.01s / case |
| LegalTrace-Qwen3-4B (Ours) | 8,000 | 0.2443 | 0.3789 | 0.3843 | 0.5% | 0.45s / case |
- +329% Macro-F1 Improvement over zero-shot base LLM.
- +42% Macro-F1 Gain over the strong non-neural TF-IDF baseline.
- 0.5% Invalid Output Rate (down from 24.2% hallucination rate on the base model).
⚡ Quickstart with Transformers
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
model_id = "spicysweetner/LegalTrace-Qwen3-4B-LSI"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype=torch.bfloat16,
device_map="auto"
)
system_prompt = """Identify the Indian Penal Code sections relevant to the case facts below.
Valid sections: 2, 3, 4, 5, 13, 34, 107, 109, 114, 120, 120B, 143, 147, 148, 149, 155, 156, 161, 164, 173, 174A, 186, 188, 190, 193, 200, 201, 228, 229A, 279, 294, 294(b), 299, 300, 302, 304, 304A, 304B, 306, 307, 308, 313, 320, 323, 324, 325, 326, 332, 336, 337, 338, 341, 342, 353, 354, 363, 364, 365, 366, 366A, 375, 376, 376(2), 379, 380, 384, 389, 392, 394, 395, 397, 406, 409, 411, 415, 417, 419, 420, 427, 436, 437, 438, 447, 448, 450, 452, 457, 465, 467, 468, 471, 482, 494, 498, 498A, 500, 504, 506, 509, 511
Answer with the section numbers only, separated by commas, in ascending order."""
case_facts = "The deceased was attacked by the appellants with sharp-edged weapons (dharani and axe) on his head and neck resulting in his instantaneous death on the spot."
messages = [
{"role": "system", "content": system_prompt},
{"role": "user", "content": case_facts}
]
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=128,
temperature=0.0,
do_sample=False
)
response = tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)
print("Predicted IPC Sections:", response.strip())
# Output: 302
💻 Ollama & GGUF Support
Looking for optimized edge deployment (Mac, Windows, Linux, RTX GPUs)?
Check the companion GGUF repository:
spicysweetner/LegalTrace-Qwen3-4B-LSI-GGUF
Or run directly:
ollama run hf.co/spicysweetner/LegalTrace-Qwen3-4B-LSI-GGUF