Downloads · 30 days
0
tejasgowda05/Kanoonu-AI-Phi3-Finetuned
Kanoonu-AI-Phi3-Finetuned is a machine learning model from tejasgowda05. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for transformers. The card lists the license as apache-2.0.
Downloads · 30 days
0
Access
Public
Updated Mar 4, 2026
Repo size
910 MB
Likes
0
Public
Click a slice to open those files.
.safetensors239 MB · 77%
From the Hugging Face model README
A domain-specific legal assistant fine-tuned on Indian law, Constitution, IPC, and CrPC
</div>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.
| 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.
from peft import PeftModel
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
# Load base model + LoRA adapter
base_model = AutoModelForCausalLM.from_pretrained(
"microsoft/Phi-3-mini-4k-instruct",
torch_dtype = torch.float16,
device_map = "auto",
)
tokenizer = AutoTokenizer.from_pretrained("tejasgowda05/Kanoonu-AI-Phi3-Finetuned")
model = PeftModel.from_pretrained(base_model, "tejasgowda05/Kanoonu-AI-Phi3-Finetuned")
# Inference
def ask_kanoonu(question):
prompt = f"""<|system|>
You are Kanoonu AI, an expert Indian legal assistant created by Tejas Gowda.
Answer questions clearly and accurately based on Indian law, the Constitution
of India, IPC, CrPC, and other relevant statutes.<|end|>
<|user|>
{question}<|end|>
<|assistant|>
"""
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
outputs = model.generate(**inputs, max_new_tokens=200, do_sample=False)
return tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
print(ask_kanoonu("What is the difference between IPC and CrPC?"))
# Download the GGUF model
huggingface-cli download tejasgowda05/Kanoonu-AI-Phi3-GGUF --local-dir ./kanoonu_model
# Create Modelfile
echo 'FROM ./kanoonu_model/kanoonu-ai-phi3-q4_k_m.gguf
SYSTEM "You are Kanoonu AI, an expert Indian legal assistant created by Tejas Gowda."' > Modelfile
# Run with Ollama
ollama create kanoonu-ai -f Modelfile
ollama run kanoonu-ai "What are the fundamental rights in the Indian Constitution?"
from llama_cpp import Llama
llm = Llama(model_path="./kanoonu_model/kanoonu-ai-phi3-q4_k_m.gguf")
response = llm("What is an FIR and how is it filed in India?")
print(response["choices"][0]["text"])
microsoft/Phi-3-mini-4k-instruct (3.8B parameters)| Parameter | Value |
|---|---|
| Method | QLoRA (4-bit quantization + LoRA) |
| LoRA Rank (r) | 16 |
| LoRA Alpha | 32 |
| LoRA Dropout | 0.05 |
| Target Modules | q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj |
| Trainable Parameters | 29,884,416 (0.78% of total) |
| Parameter | Value |
|---|---|
| Platform | Kaggle GPU T4 |
| Batch Size (per device) | 2 |
| Gradient Accumulation | 16 steps |
| Effective Batch Size | 32 |
| Learning Rate | 2e-4 |
| LR Scheduler | Cosine decay |
| Warmup Ratio | 0.05 |
| Optimizer | AdamW 8-bit |
| Max Sequence Length | 512 |
| Sequence Packing | Enabled |
| Precision | FP16 |
| Total Training Time | ~205 minutes |
<|system|>
You are Kanoonu AI, an expert Indian legal assistant...<|end|>
<|user|>
{question}<|end|>
<|assistant|>
{answer}<|end|>
This model was trained on tejasgowda05/Indian-Kanoonu-Dataset — a Phi-3 formatted version of the original viber1/indian-law-dataset.
| Property | Value |
|---|---|
| Total Examples | 24,607 |
| Train Split | 23,377 (95%) |
| Eval Split | 1,230 (5%) |
| Domain | Indian Law |
| Topics | IPC, CrPC, Constitution, Civil Procedure, Family Law |
| Language | English |
Attribution: Original Q&A content from
viber1/indian-law-dataset(Apache 2.0). Formatted with Phi-3 chat template for this project.
| Resource | Link |
|---|---|
| 🤗 LoRA Adapter (this repo) | tejasgowda05/Kanoonu-AI-Phi3-Finetuned |
| 🤗 GGUF Model | tejasgowda05/Kanoonu-AI-Phi3-GGUF |
| 🤗 Formatted Dataset | tejasgowda05/Indian-Kanoonu-dataset |
| 📦 Base Model | microsoft/Phi-3-mini-4k-instruct |
| 📦 Original Dataset | viber1/indian-law-dataset |
Tejas Gowda N — tejasgowda05
Built as part of the Kanoonu AI project — making Indian legal information accessible through conversational AI.
This model is released under the Apache 2.0 License, inherited from the base model and original dataset.
If you use this model in your work, please cite:
@misc{tejasgowda2026kanoonuai,
author = {Tejas Gowda N},
title = {Kanoonu AI: Phi-3 Fine-tuned on Indian Law},
year = {2026},
publisher = {HuggingFace},
url = {https://huggingface.co/tejasgowda05/Kanoonu-AI-Phi3-Finetuned}
}