Instructions to use pkheria7/indian-legal-opposing-counsel with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use pkheria7/indian-legal-opposing-counsel with PEFT:
Task type is invalid.
- Notebooks
- Google Colab
- Kaggle
⚖️ Indian Legal Opposing Counsel
A fine-tuned Qwen2.5-7B-Instruct model specialized as an opposing counsel for Indian law students to practice court arguments and deepen their understanding of the Indian Constitution.
🎯 What This Model Does
This model acts as a rigorous opposing counsel that:
- Challenges legal arguments using the Indian Constitution (448 Articles, 12 Schedules)
- Applies Legal Syllogism: Major Premise (law) → Minor Premise (facts) → Conclusion (argument)
- Cites landmark precedents: Kesavananda Bharati, Maneka Gandhi, Vishaka, and other Supreme Court judgments
- Presents counter-arguments with alternative interpretations, reasonable restrictions, and procedural challenges
- Educates while arguing: Highlights strengths and suggests areas for improvement
🏗️ Training Details
Research Foundation
This model's training recipe is based on published legal AI research:
| Paper | Contribution |
|---|---|
| INLegalLlama | LoRA SFT hyperparameters for Indian legal domain (~90% F1) |
| SaulLM-7B | Legal domain adaptation with synthetic conversations |
| DISC-LawLLM | Legal syllogism reasoning pattern |
| AgentCourt | Adversarial courtroom simulation approach |
Datasets (26,326 combined examples)
| Dataset | Rows | Content |
|---|---|---|
| viber1/indian-law-dataset | 24,607 | Writs, PIL, civil procedure, constitutional law, IPC |
| nisaar/Lawyer_GPT_India | 150 | Landmark cases, IPC, contract law, constitutional principles |
| RMani1/indian-legal-dataset-indian-law | 1,569 | Indian statutes, acts, legal provisions |
Hyperparameters
| Parameter | Value |
|---|---|
| Base model | Qwen/Qwen2.5-7B-Instruct |
| Method | LoRA SFT (Parameter-Efficient Fine-Tuning) |
| LoRA rank | 32 |
| LoRA alpha | 64 |
| LoRA target | all-linear layers |
| Learning rate | 1e-4 (cosine schedule) |
| Effective batch size | 16 (2 × 8 accumulation) |
| Epochs | 3 |
| Max sequence length | 2048 |
| Precision | bfloat16 |
| Loss | assistant-only (system/user prompts masked) |
| Optimizer | AdamW fused |
💻 Quick Start
Installation
pip install transformers peft torch
Inference
from transformers import pipeline
pipe = pipeline("text-generation", model="pkheria7/indian-legal-opposing-counsel")
messages = [
{"role": "system", "content": "You are an experienced opposing counsel specializing in the Indian Constitution."},
{"role": "user", "content": """I argue that my client's right to privacy under Article 21 of the Indian Constitution
has been violated by the government's surveillance program. The Supreme Court in Justice K.S. Puttaswamy v.
Union of India (2017) established that privacy is a fundamental right. Therefore, this surveillance is unconstitutional."""}
]
response = pipe(messages, max_new_tokens=512, do_sample=True, temperature=0.7)
print(response[0]["generated_text"][-1]["content"])
With PEFT (LoRA adapter)
from peft import AutoPeftModelForCausalLM
from transformers import AutoTokenizer
model = AutoPeftModelForCausalLM.from_pretrained("pkheria7/indian-legal-opposing-counsel")
tokenizer = AutoTokenizer.from_pretrained("pkheria7/indian-legal-opposing-counsel")
messages = [
{"role": "system", "content": "You are an experienced opposing counsel specializing in the Indian Constitution."},
{"role": "user", "content": "I argue that Section 377 IPC violates Article 14 and Article 21..."}
]
inputs = tokenizer.apply_chat_template(messages, return_tensors="pt", add_generation_prompt=True)
outputs = model.generate(inputs.to(model.device), max_new_tokens=512, temperature=0.7, do_sample=True)
print(tokenizer.decode(outputs[0][inputs.shape[1]:], skip_special_tokens=True))
🏋️ Train It Yourself
On Google Colab (A100 recommended)
# Install dependencies
pip install torch transformers trl peft datasets accelerate bitsandbytes flash-attn
# Clone and run
git clone https://huggingface.co/pkheria7/indian-legal-opposing-counsel
cd indian-legal-opposing-counsel
python train.py
For T4 GPUs (16GB VRAM) — Use QLoRA
Edit train.py and set:
USE_QLORA = True
Hardware Requirements
| GPU | VRAM | Mode | Est. Training Time |
|---|---|---|---|
| A100 80GB | 80 GB | Full LoRA + Flash Attn | ~2-3 hours |
| A100 40GB | 40 GB | Full LoRA | ~3-4 hours |
| A10G 24GB | 24 GB | QLoRA (4-bit) | ~4-5 hours |
| T4 16GB | 16 GB | QLoRA (4-bit) | ~6-8 hours |
📊 Example Interactions
Example 1: Privacy Rights
Student: "Article 21 guarantees right to privacy. The Puttaswamy judgment says surveillance is unconstitutional."
Opposing Counsel: "While I acknowledge the landmark nature of Puttaswamy, counsel's argument oversimplifies the Court's holding. The nine-judge bench in Puttaswamy explicitly held that the right to privacy is NOT absolute — it is subject to reasonable restrictions satisfying the triple test: (1) legality, (2) legitimate aim, and (3) proportionality. The surveillance program satisfies all three..."
Example 2: Reservation Policy
Student: "Article 15(4) and Article 16(4) permit reservations. The 50% ceiling from Indra Sawhney is arbitrary."
Opposing Counsel: "Counsel's characterization of the 50% ceiling as 'arbitrary' ignores the constitutional reasoning in Indra Sawhney v. Union of India (1992). The Supreme Court held that exceeding 50% would violate Article 14's guarantee of equality..."
⚠️ Limitations
- Not a substitute for legal advice: This model is for educational purposes only
- Knowledge cutoff: The model's legal knowledge comes from training data and may not reflect the latest amendments or judgments
- May hallucinate citations: Always verify case citations and article references independently
- Dataset size: Training data is ~26K examples — more data (especially from IndianKanoon.org court judgments) would improve quality
- Single-turn focus: The current training data is primarily single-turn Q&A; multi-turn adversarial debates would improve courtroom simulation
📚 References
- INLegalLlama: Indian Legal LLM
- SaulLM-7B: Legal LLM
- DISC-LawLLM: Legal Syllogism
- AgentCourt: Adversarial Simulation
- MASER: Multi-Agent Legal Training
📄 License
Apache 2.0 — based on Qwen2.5-7B-Instruct (Apache 2.0 licensed)
- Downloads last month
- -