Downloads · 30 days
71
40% of all-time downloads
saitejasathiraju/indian-legal-reranker
indian-legal-reranker is a text classification model from saitejasathiraju. Use it when you need a label for a piece of text. The card lists the license as apache-2.0.
A pointwise reranker fine-tuned from Qwen/Qwen3-Reranker-0.6B for Indian criminal law retrieval: BNS 2023 (Bharatiya Nyaya Sanhita), BNSS 2023 (Bharatiya Nagarik Suraksha Sanhita), and BSA 2023 (Bharatiya Sakshya Adhi…
Downloads · 30 days
71
40% of all-time downloads
All-time downloads
176
Public
Parameters
596M
1.2 GB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors1.2 GB · 99%
From the Hugging Face model README
A pointwise reranker fine-tuned from Qwen/Qwen3-Reranker-0.6B for Indian criminal law retrieval: BNS 2023 (Bharatiya Nyaya Sanhita), BNSS 2023 (Bharatiya Nagarik Suraksha Sanhita), and BSA 2023 (Bharatiya Sakshya Adhiniyam) — the acts that replaced the IPC, CrPC, and Indian Evidence Act in July 2024.
Given a query and a candidate passage, the model judges relevance as "yes" or "no", and the relative logit between those two tokens gives a continuous relevance score — designed to be dropped into a RAG reranking step over retrieved statute/case-law chunks.
Standalone generation from small legal-domain LLMs (including the base 0.6B/1.5B/3B Qwen models fine-tuned only on QA pairs) reliably hallucinates specific section citations for BNS/BNSS/BSA 2023 — these acts are too recent (in force July 2024) to be well represented in most pretraining data, and QA-pair fine-tuning teaches style, not facts. This reranker is intended as the reranking stage of a retrieval-augmented pipeline (BM25/dense retrieval over the actual bare-act text, reranked by this model, then fed to a generator) rather than a standalone answer engine.
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
MODEL_ID = "saitejasathiraju/indian-legal-reranker"
INSTRUCTION = ("Given a legal query about Indian statutes and case law, retrieve the "
"passage that directly and correctly answers the query")
SYSTEM_PREFIX = ('<|im_start|>system\nJudge whether the Document meets the requirements based on the '
'Query and the Instruct provided. Note that the answer can only be "yes" or "no".'
'<|im_end|>\n<|im_start|>user\n')
SUFFIX = "<|im_end|>\n<|im_start|>assistant\n<think>\n\n</think>\n\n"
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, padding_side="left")
model = AutoModelForCausalLM.from_pretrained(MODEL_ID, dtype=torch.bfloat16).to("cuda").eval()
token_true_id = tokenizer.convert_tokens_to_ids("yes")
token_false_id = tokenizer.convert_tokens_to_ids("no")
def score(query, doc):
body = f"<Instruct>: {INSTRUCTION}\n<Query>: {query}\n<Document>: {doc}"
ids = tokenizer.encode(SYSTEM_PREFIX + body + SUFFIX, add_special_tokens=False)
inp = torch.tensor([ids], device=model.device)
with torch.no_grad():
logits = model(input_ids=inp, attention_mask=torch.ones_like(inp), logits_to_keep=1).logits[0, -1, :]
pair = torch.stack([logits[token_false_id], logits[token_true_id]])
return torch.nn.functional.log_softmax(pair, dim=0)[1].exp().item()
print(score(
"What does Section 103 of BNS 2023 deal with?",
"Section 103 of BNS 2023 - Punishment for murder.--(1) Whoever commits murder shall be "
"punished with death or imprisonment for life, and shall also be liable to fine."
)) # -> ~1.0
For reranking multiple candidates, score each (query, doc) pair and sort by score descending.
/api/generate without raw-prompt mode) will silently degrade quality — see the chat_template behavior described in this repo's files before wrapping it in a different serving stack.Apache 2.0, inherited from the base model.