Transformers
English
File size: 6,461 Bytes
de2e475
 
 
 
 
 
 
 
 
962808c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4214f88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
962808c
 
4214f88
962808c
 
 
4214f88
 
 
 
962808c
4214f88
 
 
962808c
 
4214f88
 
962808c
4214f88
962808c
4214f88
962808c
4214f88
962808c
4214f88
 
 
 
 
 
 
962808c
4214f88
 
 
962808c
 
 
4214f88
962808c
4214f88
962808c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
license: apache-2.0
datasets:
- percins/IN-ABS
language:
- en
base_model:
- microsoft/Phi-3-mini-4k-instruct
library_name: transformers
---
# Model Card for Model ID

<!-- Provide a quick summary of what the model is/does. -->

This repository contains phi3-indian-law-assistant, a fine-tuned version of Microsoft's Phi-3-mini-4k-instruct. The model has been specialized to understand and summarize Indian legal documents through training on the IN-Abs dataset.

## Model Details

### Model Description

<!-- Provide a longer summary of what this model is. -->
The model is designed to act as a legal AI assistant. It takes the full text of a legal judgment as input and generates a concise, structured summary of its key points, reasoning, and decision.In its future version, the LLM will be able to cross reference similar decisions that are were made by the court which has set a legal precedance.


- **Developed by:** Aryan Kankheria
- **Model type:** 
- **License:** Apache License 2.0
- **Finetuned from model:** Microsoft's Phi-3-mini-4k-instruct

### Model Sources

<!-- Provide the basic links for the model. -->

- **Repository:** [Link](https://github.com/smuggypusss/Law-LLM)


## Uses

<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
This model is designed to be used as a specialized assistant for summarizing and answering questions about Indian legal documents, specifically Supreme Court of India judgments. It is intended for legal students and researchers as a tool to quickly understand the gist of a case. It follows instructions in a conversational format.
### Downstream Use
- **Legal document drafting and review.**

- **Contract analysis.**

- **Integration into a Retrieval-Augmented Generation (RAG) system for a comprehensive legal knowledge base.**


### Out-of-Scope Use

<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
This model should not be used to provide legal advice. It is not a qualified legal professional and its outputs may contain inaccuracies or hallucinations. The model's knowledge is limited to its training data and it has no awareness of real-time legal developments.

Misuse, such as generating fake legal documents or using it for legal decisions without professional oversight, is strictly out of scope.


## Bias, Risks, and Limitations

<!-- This section is meant to convey both technical and sociotechnical limitations. -->
The model is trained on historical judgments from the Supreme Court of India. The training data may contain societal, historical, or gender biases which the model can replicate in its outputs. Its knowledge is also limited to the style and scope of this specific dataset and does not cover all areas of Indian law.

The primary risk is over-reliance. Users may mistake the model's coherent outputs for factual and accurate legal advice, which could lead to incorrect conclusions.

### Recommendations

<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->

Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.

## How to Get Started with the Model
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
model_path = "ak331/Law_LLM" 
tokenizer = AutoTokenizer.from_pretrained(model_path)
model = AutoModelForCausalLM.from_pretrained(
    model_path,
    device_map="auto",
    torch_dtype=torch.bfloat16,
    trust_remote_code=True,
    attn_implementation='eager'
)

prompt = (
    f"<|im_start|>system\n"
    f"You are a specialized Indian legal AI assistant...\n"
    f"<|im_end|>\n"
    f"<|im_start|>user\n"
    f"Please analyze and summarize the following judgment...\n"
    f"<|im_end|>\n"
    f"<|im_start|>assistant\n"
)

inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
outputs = model.generate(**inputs, max_length=512)
response_text = tokenizer.decode(outputs[0], skip_special_tokens=True)

print(response_text)

## Training Details
Training behaviour for this model can be found on this wandb [link](https://api.wandb.ai/links/aryankankheria331-myself/50uerjc4)
### Training Data

<!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
The model was fine-tuned on a 1,000-sample subset of the percins/IN-ABS dataset. This dataset contains judgments from the Supreme Court of India and their corresponding human-written summaries.
### Training Procedure
The model was fine-tuned using the QLoRA method for parameter-efficient fine-tuning.
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->

#### Preprocessing 
Each data sample (judgment and summary) was formatted into the ChatML prompt structure to teach the model the conversational assistant persona. The format is:
<|im_start|>system\n{system_prompt}<|im_end|>\n<|im_start|>user\nJUDGMENT TEXT:\n{judgment}<|im_end|>\n<|im_start|>assistant\nSUMMARY:\n{summary}<|im_end|>


#### Training Hyperparameters
- **Base Model:** microsoft/Phi-3-mini-4k-instruct

-**Training Regime:** QLoRA (4-bit nf4 quantization with bfloat16 compute dtype)

-**per_device_train_batch_size:** 1

-**gradient_accumulation_steps:** 8 (effective batch size of 8)

- **paged_adamw_8bit**

-**learning_rate:** 2e-4

-**max_steps:** 500

-**max_seq_length:** 512

-**lora_r (rank):** 16

-**lora_alpha:** 32

#### Speeds, Sizes, Times [optional]

-**Hardware:** 1x NVIDIA GeForce GTX 1660 Ti (6 GB VRAM)

-**Training Time:** Approximately 7 hours and 26 minutes.

## Evaluation

<!-- This section describes the evaluation protocols and provides the results. -->

### Testing Data, Factors & Metrics

#### Testing Data

<!-- This should link to a Dataset Card if possible. -->

[More Information Needed]

#### Factors

<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->

[More Information Needed]

#### Metrics

<!-- These are the evaluation metrics being used, ideally with a description of why. -->

[More Information Needed]

### Results

[More Information Needed]

#### Summary