File size: 9,652 Bytes
d9f59ba
 
50eb679
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d9f59ba
 
50eb679
d9f59ba
50eb679
d9f59ba
 
 
 
 
50eb679
d9f59ba
50eb679
d9f59ba
50eb679
 
 
 
 
d9f59ba
50eb679
d9f59ba
50eb679
d9f59ba
 
 
 
 
50eb679
d9f59ba
50eb679
 
 
d9f59ba
 
 
50eb679
 
d9f59ba
 
 
50eb679
 
 
d9f59ba
 
 
50eb679
 
 
d9f59ba
 
 
50eb679
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d9f59ba
50eb679
 
 
 
 
 
 
 
 
d9f59ba
 
 
 
 
50eb679
d9f59ba
50eb679
 
 
 
 
d9f59ba
50eb679
d9f59ba
50eb679
d9f59ba
50eb679
 
 
 
 
 
 
 
 
 
d9f59ba
 
 
50eb679
 
d9f59ba
50eb679
d9f59ba
50eb679
d9f59ba
50eb679
 
 
 
d9f59ba
50eb679
d9f59ba
50eb679
 
 
 
d9f59ba
50eb679
d9f59ba
50eb679
 
 
d9f59ba
50eb679
d9f59ba
50eb679
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
---
library_name: transformers
tags:
  - law
  - legal
  - india
  - msme
  - contract-drafting
  - dispute-resolution
  - qwen2.5
  - lora
  - fine-tuned
  - legal-nlp
license: apache-2.0
language:
  - en
inference: false
---

# IndraLegal-1.5B

IndraLegal-1.5B is a lightweight, specialized Large Language Model (LLM) fine-tuned specifically for the Indian legal context. It is designed to act as an AI mediator and virtual negotiation assistant for Micro, Small and Medium Enterprises (MSMEs) facing delayed payment disputes.

## Model Details

### Model Description

IndraLegal-1.5B is built on top of the highly efficient `Qwen/Qwen2.5-Coder-1.5B-Instruct` base model. It has been fine-tuned using LoRA (Low-Rank Adaptation) on a curated corpus of Indian statutory laws (IPC, CrPC, CPC), thousands of standard Indian contract clauses, and outcome judgments from the National Company Law Tribunal (NCLT). 

The model's primary objective is to solve **Problem Statement 1: AI Enabled Virtual Negotiation Assistance** for the IndiaAI Innovation Challenge by empowering MSMEs with accessible legal knowledge, neutral dispute summarization, and automated settlement drafting without requiring expensive legal counsel.

- **Developed by:** Purushottam / Team Indra
- **Model type:** Causal Language Model (Fine-tuned via PEFT/LoRA)
- **Language(s):** English
- **License:** Apache 2.0 (same as base model Qwen2.5)
- **Finetuned from model:** `Qwen/Qwen2.5-Coder-1.5B-Instruct`

### Model Sources

- **Repository:** Submitting as part of IndiaAI Innovation Challenge.

## Uses

### Direct Use

The model is designed to be used directly via the `transformers` library, preferably utilizing the ChatML template for best results. It is intended to be plugged into the backend of a dispute resolution platform (e.g., the MSME Samadhaan portal).

- **Legal Drafting:** Drafting standard agreements, force majeure clauses, arbitration clauses, and formal "Record of Settlement" documents.
- **Statutory Interpretation:** Explaining sections of Indian law (e.g., MSMED Act, IPC, CPC) in plain English to laypersons.
- **Dispute Analysis:** Summarizing the core legal contentions between a petitioner and respondent neutrally.

### Out-of-Scope Use

- **Definitive Legal Counsel:** IndraLegal-1.5B is an AI assistant, not a human lawyer. It should not be used as a final substitute for certified professional legal advice in high-stakes litigation.
- **General Chatting:** While capable, the model is highly specialized for legal terminology and may perform poorly on casual conversation or coding tasks outside of its fine-tuned domain.

## Bias, Risks, and Limitations

- **Hallucination Risk:** Like all generative models, it may occasionally hallucinate legal sections or precedents that do not exist. Users must verify critical citations.
- **Context Length:** It is trained on smaller chunk sizes to maintain speed and efficiency; extremely long legal judgments might exceed its effective context window.
- **Jurisdictional Bias:** The model is strictly trained on Indian law. It will respond inaccurately if queried about US, UK, or other international laws.

### Recommendations

- Always use the `ChatML` template format (using `tokenizer.apply_chat_template`) during inference to prevent infinite loops and ensure structural integrity.
- Apply a `repetition_penalty` of roughly `1.15` during generation to maximize output quality.
- Include a disclaimer in any UI stating that the tool is for negotiation assistance and not definitive legal advice.

## How to Get Started with the Model

Use the code below to load the model in 4-bit precision and run inference:

```python
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
from peft import PeftModel

BASE_MODEL = "Qwen/Qwen2.5-Coder-1.5B-Instruct"
ADAPTER_PATH = "RockySinghRajput/IndraLegal-1.5B-Adapter" # Replace with your actual repo name

bnb_config = BitsAndBytesConfig(
    load_in_4bit=True,
    bnb_4bit_quant_type="nf4",
    bnb_4bit_compute_dtype=torch.float16,
)

tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL, trust_remote_code=True)
base = AutoModelForCausalLM.from_pretrained(
    BASE_MODEL, 
    quantization_config=bnb_config, 
    device_map="auto"
)
model = PeftModel.from_pretrained(base, ADAPTER_PATH)

SYSTEM_PROMPT = """You are IndraLegal, an expert AI legal and virtual negotiation assistant specialized in Indian Law.
Your role is to assist with legal drafting, contract analysis, dispute resolution, and interpreting Indian statutes (IPC, CrPC, etc.) accurately and neutrally.
When analyzing cases or drafting settlements, provide sound legal reasoning based on Indian judicial precedents."""

messages = [
    {"role": "system", "content": SYSTEM_PROMPT},
    {"role": "user", "content": "What is the liability of a buyer for delayed payments under the MSMED Act, 2006?"}
]

prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)

with torch.no_grad():
    outputs = model.generate(
        **inputs,
        max_new_tokens=512,
        temperature=0.3, # Low temperature for factual legal answers
        top_p=0.9,
        repetition_penalty=1.15,
        do_sample=True,
        eos_token_id=tokenizer.eos_token_id,
        pad_token_id=tokenizer.eos_token_id
    )

response = tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)
print(response.strip())
```

## Model Details

| Property | Value |
|----------|-------|
| **Base Model** | [Qwen/Qwen2.5-Coder-1.5B-Instruct](https://huggingface.co/Qwen/Qwen2.5-Coder-1.5B-Instruct) |
| **Parameters** | 1.5B |
| **Type** | Causal Language Model (LoRA fine-tune) |
| **Languages** | English |
| **License** | Apache 2.0 |
| **Developed by** | Team Indra / RockySinghRajput |
| **Target Use Case** | Problem Statement 1: AI Enabled Virtual Negotiation Assistance (Ministry of MSME) |

## Training Details

### Training Data

Fine-tuned on a heavily curated blend of structured Indian legal datasets:

| Dataset | Purpose | Content |
|---------|---------|---------|
| [Indian-Law-Penal-Code-Json](https://github.com/shantanuo/Indian-Law-Penal-Code-Json) | Statutory Knowledge | Complete sections from IPC, CrPC, CPC, HMA, IDA, IEA, NIA |
| [Legal Indian Contract Clauses](https://www.kaggle.com/datasets/nishantkadiyan/legal-indian-contract-clauses-dataset) | Automated Drafting | Thousands of professionally structured commercial contract clauses |
| [NCLT Cause Lists V1](https://huggingface.co/datasets/NCLT) | Corporate Disputes | Tribunal corporate insolvency, petitioner, and respondent metadata |

All data was parsed into strictly formatted instruction-following pairs (System/User/Assistant) using a custom `ChatML` template.

### Training Procedure

- **Method**: LoRA (Low-Rank Adaptation)
- **LoRA Config**: r=16, alpha=16, dropout=0.05
- **Target Modules**: q_proj, k_proj, v_proj, o_proj
- **Epochs**: 3
- **Learning Rate**: 2e-4
- **Optimizer**: paged_adamw_8bit
- **Sequence Length**: 2048 tokens
- **Precision**: FP16 mixed precision
- **Quantization**: 4-bit NF4 (QLoRA) during training
- **Batch Size**: 2 (Gradient Accumulation Steps: 4)

### Compute Infrastructure

- **Hardware**: Single NVIDIA GPU (e.g., T4/P100)
- **Frameworks**: `transformers`, `peft`, `trl`, `bitsandbytes`

## Capabilities

### βœ… What IndraLegal Can Do

- **Interpret Indian Law** β€” Instantly explain provisions from major Indian statutes (IPC, CrPC, CPC, etc.)
- **Draft Legal Agreements** β€” Generate structurally sound MSME settlement agreements, force majeure clauses, and non-disclosure terms
- **Mediate MSME Disputes** β€” Clarify the legal liabilities of buyers and rights of suppliers under the MSMED Act, 2006
- **Neutral Analysis** β€” Avoid taking aggressive sides; instead, it provides balanced, factual legal standing for all parties in a virtual negotiation

### ⚠️ Limitations

- **Not Definitive Legal Counsel** β€” This is an AI assistant, not a human lawyer. It should not be used as a final substitute for certified professional legal advice in high-stakes litigation.
- **1.5B model** β€” Due to its lightweight parameter count, extremely lengthy or multi-document dispute analyses may exceed its contextual reasoning capabilities.
- **May hallucinate** β€” Always verify specific section numbers, historical precedents, and generated citations.
- **Jurisdictional Boundary** β€” Strictly trained on Indian law. It will respond inaccurately if queried about US, UK, or other international laws.

### ❌ Out-of-Scope Use

- Serving as the sole arbiter in legally binding tribunals without human oversight
- Providing certified medical or financial advice
- Generating harmful or discriminatory legal loopholes

## Evaluation

| Test Area | Task | Result |
|-----------|------|--------|
| **Legal Drafting** | Draft a standard 'Force Majeure' clause under Indian Law | βœ… Highly structured, professional formatting, and legally accurate coverage of delay limits |
| **Statutory Interpretation** | Explain Section 420 of the Indian Penal Code | βœ… Neutrally quoted the section's stance on fraud and cheating, including potential punishments |
| **MSME Dispute** | Evaluate buyer liability for a 60-day delayed payment of Rs 5 Lakhs | βœ… Correctly identified the buyer's liability to pay the sum under the MSMED Act |

## Citation

```bibtex
@misc{indralegal2026,
  title={IndraLegal-1.5B: An Indian Law AI Assistant for Virtual Negotiation},
  author={Team Indra},
  year={2026},
  publisher={HuggingFace},
}
```