Nyaya-7B is a domain-adapted, instruction-finetuned version of
Mistral-7B-Instruct-v0.3, trained on
10,000+ Indian Supreme Court and High Court judgments to extract structured legal information into clean, validated JSON — at
zero API cost, fully offline.
Given raw Indian court judgment text, Nyaya-7B extracts a full structured JSON covering:
1from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline, BitsAndBytesConfig
2import torch, json
3
4MODEL_ID = "mrroyaleace/nyaya-7b" # replace with your HuggingFace repo
5
6bnb_config = BitsAndBytesConfig(
7 load_in_4bit=True,
8 bnb_4bit_quant_type="nf4",
9 bnb_4bit_compute_dtype=torch.float16,
10)
11
12tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
13tokenizer.pad_token = tokenizer.eos_token
14
15model = AutoModelForCausalLM.from_pretrained(
16 MODEL_ID,
17 quantization_config=bnb_config,
18 device_map="auto",
19)
20
21pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
1judgment_text = """
2IN THE SUPREME COURT OF INDIA
3Criminal Appeal No. 1234 of 2022
4
5State of Punjab ...Appellant
6Versus
7Gurpreet Singh ...Respondent
8
9JUDGMENT
10
11The appellant challenges the High Court's order acquitting the respondent
12of charges under Section 302 IPC read with Section 34 IPC...
13"""
14
15messages = [
16 {"role": "system", "content": "You are Nyaya, a specialized Indian legal extraction model."},
17 {"role": "user", "content": f"Extract structured data from this judgment and return JSON:\n\n{judgment_text}"}
18]
19
20prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
21
22raw_output = pipe(
23 prompt,
24 max_new_tokens=512,
25 do_sample=False,
26 return_full_text=False,
27 pad_token_id=tokenizer.eos_token_id,
28)[0]["generated_text"]
29
30result = json.loads(raw_output.strip())
31print(result)
1{
2 "case_name": "State of Punjab v. Gurpreet Singh",
3 "citation": null,
4 "court": "Supreme Court of India",
5 "year": 2022,
6 "petitioner": "State of Punjab",
7 "respondent": "Gurpreet Singh",
8 "subject_matter": "Criminal",
9 "statutes_cited": [
10 {"act": "Indian Penal Code", "section": "302", "description": "Punishment for murder"},
11 {"act": "Indian Penal Code", "section": "34", "description": "Acts done by several persons in furtherance of common intention"}
12 ],
13 "precedents_cited": [],
14 "legal_issues": [
15 "Whether the High Court was justified in acquitting the respondent under Section 302 IPC?"
16 ],
17 "holding": "The Supreme Court examined the evidence and found the High Court's reasoning sound...",
18 "outcome": "dismissed"
19}
1model = AutoModelForCausalLM.from_pretrained(
2 MODEL_ID,
3 torch_dtype=torch.float32,
4 device_map="cpu",
5 low_cpu_mem_usage=True,
6)
7# Note: CPU inference is significantly slower (~5–15 min per judgment)
The model was trained on ~2,000 Indian court judgment pairs curated and labeled from:
1{
2 "case_name": str, # "Petitioner v. Respondent"
3 "citation": str | None, # "AIR 1997 SC 3986" or null
4 "court": str, # Full court name
5 "year": int | None, # 4-digit year
6 "petitioner": str,
7 "respondent": str,
8 "subject_matter": str | None, # Criminal | Civil | Constitutional | ...
9 "statutes_cited": [{"act": str, "section": str, "description": str}],
10 "precedents_cited": [{"citation": str, "case_name": str | None}],
11 "legal_issues": [str],
12 "holding": str, # 1-3 sentence summary
13 "outcome": str # dismissed | allowed | disposed | remanded | modified
14}
1@misc{nyaya7b2026,
2 title = {Nyaya-7B: A QLoRA Fine-tuned LLM for Indian Legal Judgment Parsing},
3 author = {Shubham Suman},
4 year = {2026},
5 url = {https://huggingface.co/mrroyaleace/nyaya-7b},
6 note = {Fine-tuned from mistralai/Mistral-7B-Instruct-v0.3 on 2,000+ Indian SC/HC judgments}
7}