Kanoonu AI (कानून — Hindi for "Law") is a fine-tuned version of microsoft/Phi-3-mini-4k-instruct specialised for Indian legal domain question answering.
It was trained using QLoRA (Quantized Low-Rank Adaptation) on 23,370 Indian law Q&A pairs, covering the Indian Penal Code (IPC), Code of Criminal Procedure (CrPC), Constitution of India, and other statutes.
"Kanoonu AI" is part of a larger project to make Indian legal information accessible to everyone through conversational AI.
🏆 Training Results
Metric
Value
Final Train Loss
0.3478
Best Eval Loss
0.6568
Training Examples
23,370
Training Steps
731
Epochs
1
Trainable Parameters
29,884,416 (0.78%)
A final train loss of 0.3478 indicates excellent domain adaptation with no signs of overfitting.
🚀 Quick Start
Option 1 — Load LoRA Adapter (requires base model)
python
1from peft import PeftModel
2from transformers import AutoModelForCausalLM, AutoTokenizer
3import torch
45# Load base model + LoRA adapter6base_model = AutoModelForCausalLM.from_pretrained(7"microsoft/Phi-3-mini-4k-instruct",8 torch_dtype = torch.float16,9 device_map ="auto",10)11tokenizer = AutoTokenizer.from_pretrained("tejasgowda05/Kanoonu-AI-Phi3-Finetuned")12model = PeftModel.from_pretrained(base_model,"tejasgowda05/Kanoonu-AI-Phi3-Finetuned")1314# Inference15defask_kanoonu(question):16 prompt =f"""<|system|>
17You are Kanoonu AI, an expert Indian legal assistant created by Tejas Gowda.
18Answer questions clearly and accurately based on Indian law, the Constitution
19of India, IPC, CrPC, and other relevant statutes.<|end|>
20<|user|>
21{question}<|end|>
22<|assistant|>
23"""24 inputs = tokenizer(prompt, return_tensors="pt").to("cuda")25 outputs = model.generate(**inputs, max_new_tokens=200, do_sample=False)26return tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)2728print(ask_kanoonu("What is the difference between IPC and CrPC?"))
Option 2 — GGUF with Ollama (Recommended for local deployment)
bash
1# Download the GGUF model2huggingface-cli download tejasgowda05/Kanoonu-AI-Phi3-GGUF --local-dir ./kanoonu_model
34# Create Modelfile5echo'FROM ./kanoonu_model/kanoonu-ai-phi3-q4_k_m.gguf
6SYSTEM "You are Kanoonu AI, an expert Indian legal assistant created by Tejas Gowda."'> Modelfile
78# Run with Ollama9ollama create kanoonu-ai -f Modelfile
10ollama run kanoonu-ai "What are the fundamental rights in the Indian Constitution?"
Option 3 — GGUF with llama-cpp-python
python
1from llama_cpp import Llama
23llm = Llama(model_path="./kanoonu_model/kanoonu-ai-phi3-q4_k_m.gguf")4response = llm("What is an FIR and how is it filed in India?")5print(response["choices"][0]["text"])