Update README.md
Browse files
README.md
CHANGED
|
@@ -1,202 +1,214 @@
|
|
| 1 |
-
|
| 2 |
-
base_model: unsloth/gemma-3-4b-it-unsloth-bnb-4bit
|
| 3 |
-
library_name: peft
|
| 4 |
-
---
|
| 5 |
-
|
| 6 |
-
# Model Card for Model ID
|
| 7 |
-
|
| 8 |
-
<!-- Provide a quick summary of what the model is/does. -->
|
| 9 |
-
|
| 10 |
-
|
| 11 |
|
| 12 |
## Model Details
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
- **Developed by:** [More Information Needed]
|
| 21 |
-
- **Funded by [optional]:** [More Information Needed]
|
| 22 |
-
- **Shared by [optional]:** [More Information Needed]
|
| 23 |
-
- **Model type:** [More Information Needed]
|
| 24 |
-
- **Language(s) (NLP):** [More Information Needed]
|
| 25 |
-
- **License:** [More Information Needed]
|
| 26 |
-
- **Finetuned from model [optional]:** [More Information Needed]
|
| 27 |
-
|
| 28 |
-
### Model Sources [optional]
|
| 29 |
-
|
| 30 |
-
<!-- Provide the basic links for the model. -->
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
|
| 36 |
## Uses
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
[More Information Needed]
|
| 57 |
|
| 58 |
## Bias, Risks, and Limitations
|
| 59 |
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
|
| 69 |
|
| 70 |
## How to Get Started with the Model
|
| 71 |
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
## Training Details
|
| 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 |
## Evaluation
|
| 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 |
-
## Model Examination [optional]
|
| 136 |
-
|
| 137 |
-
<!-- Relevant interpretability work for the model goes here -->
|
| 138 |
-
|
| 139 |
-
[More Information Needed]
|
| 140 |
|
| 141 |
## Environmental Impact
|
| 142 |
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
- **Hardware Type:** [More Information Needed]
|
| 148 |
-
- **Hours used:** [More Information Needed]
|
| 149 |
-
- **Cloud Provider:** [More Information Needed]
|
| 150 |
-
- **Compute Region:** [More Information Needed]
|
| 151 |
-
- **Carbon Emitted:** [More Information Needed]
|
| 152 |
-
|
| 153 |
-
## Technical Specifications [optional]
|
| 154 |
-
|
| 155 |
-
### Model Architecture and Objective
|
| 156 |
|
| 157 |
-
|
| 158 |
|
| 159 |
-
|
|
|
|
|
|
|
|
|
|
| 160 |
|
| 161 |
-
|
|
|
|
|
|
|
| 162 |
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
## Citation [optional]
|
| 172 |
-
|
| 173 |
-
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
| 174 |
-
|
| 175 |
-
**BibTeX:**
|
| 176 |
-
|
| 177 |
-
[More Information Needed]
|
| 178 |
-
|
| 179 |
-
**APA:**
|
| 180 |
-
|
| 181 |
-
[More Information Needed]
|
| 182 |
-
|
| 183 |
-
## Glossary [optional]
|
| 184 |
-
|
| 185 |
-
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
| 186 |
-
|
| 187 |
-
[More Information Needed]
|
| 188 |
-
|
| 189 |
-
## More Information [optional]
|
| 190 |
-
|
| 191 |
-
[More Information Needed]
|
| 192 |
-
|
| 193 |
-
## Model Card Authors [optional]
|
| 194 |
-
|
| 195 |
-
[More Information Needed]
|
| 196 |
|
| 197 |
## Model Card Contact
|
| 198 |
-
|
| 199 |
-
[More Information Needed]
|
| 200 |
-
### Framework versions
|
| 201 |
-
|
| 202 |
-
- PEFT 0.14.0
|
|
|
|
| 1 |
+
# Model Card: Gemma-3 Indian Penal Code Legal Assistant
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
## Model Details
|
| 4 |
|
| 5 |
+
**Model Description**
|
| 6 |
+
* **Developed by:** Independent researcher
|
| 7 |
+
* **Model type:** LoRA fine-tuned LLM for Indian legal assistance
|
| 8 |
+
* **Language(s):** English with focus on Indian legal terminology
|
| 9 |
+
* **License:** Apache 2.0 (same as base model)
|
| 10 |
+
* **Finetuned from model:** unsloth/gemma-3-4b-it-unsloth-bnb-4bit
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
**Model Sources**
|
| 13 |
+
* **Base model:** [Google's Gemma 3](https://ai.google.dev/gemma)
|
| 14 |
+
* **Fine-tuning framework:** [Unsloth](https://github.com/unslothai/unsloth)
|
| 15 |
|
| 16 |
## Uses
|
| 17 |
|
| 18 |
+
**Direct Use**
|
| 19 |
+
This model is designed to provide accurate information about the Indian Penal Code (IPC). It can be used by:
|
| 20 |
+
- Legal professionals seeking quick reference to IPC sections
|
| 21 |
+
- Law students studying Indian criminal law
|
| 22 |
+
- Individuals seeking to understand their legal rights and responsibilities
|
| 23 |
+
- Paralegals and legal assistants drafting documents
|
| 24 |
+
|
| 25 |
+
**Downstream Use**
|
| 26 |
+
- Integration into legal assistance chatbots
|
| 27 |
+
- Incorporation into legal research tools
|
| 28 |
+
- Development of educational materials on Indian criminal law
|
| 29 |
+
|
| 30 |
+
**Out-of-Scope Use**
|
| 31 |
+
This model should NOT be used for:
|
| 32 |
+
- Providing definitive legal advice that replaces professional legal counsel
|
| 33 |
+
- Making judicial decisions or determinations
|
| 34 |
+
- Predicting case outcomes in specific legal scenarios
|
| 35 |
+
- Generating legal documents without professional review
|
|
|
|
| 36 |
|
| 37 |
## Bias, Risks, and Limitations
|
| 38 |
|
| 39 |
+
- The model may have incomplete knowledge of the most recent amendments to the Indian Penal Code
|
| 40 |
+
- It may provide information that is technically correct but lacks important contextual nuance
|
| 41 |
+
- The model cannot account for jurisdiction-specific interpretations or case law
|
| 42 |
+
- Performance may vary when dealing with complex legal questions involving multiple sections
|
| 43 |
+
- The model should not be relied upon for actual legal proceedings
|
| 44 |
|
| 45 |
+
**Recommendations**
|
| 46 |
+
- Always verify information with official legal sources
|
| 47 |
+
- Consult with qualified legal professionals before making legal decisions
|
| 48 |
+
- Use the model as a supplementary tool, not a replacement for proper legal research
|
| 49 |
+
- Be aware that the model may occasionally generate inaccurate or outdated information
|
|
|
|
|
|
|
| 50 |
|
| 51 |
## How to Get Started with the Model
|
| 52 |
|
| 53 |
+
```python
|
| 54 |
+
from unsloth import FastModel
|
| 55 |
+
import torch
|
| 56 |
+
from unsloth.chat_templates import get_chat_template
|
| 57 |
+
|
| 58 |
+
# Load the base model first
|
| 59 |
+
base_model_name = "unsloth/gemma-3-4b-it-unsloth-bnb-4bit"
|
| 60 |
+
model, tokenizer = FastModel.from_pretrained(
|
| 61 |
+
model_name = base_model_name,
|
| 62 |
+
max_seq_length = 2048,
|
| 63 |
+
load_in_4bit = True,
|
| 64 |
+
load_in_8bit = False,
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
# Load the adapter separately
|
| 68 |
+
from peft import PeftModel
|
| 69 |
+
adapter_path = "username/gemma-3-indian-penal-code-model" # Replace with actual path
|
| 70 |
+
model = PeftModel.from_pretrained(model, adapter_path)
|
| 71 |
+
|
| 72 |
+
# Set up the chat template
|
| 73 |
+
tokenizer = get_chat_template(
|
| 74 |
+
tokenizer,
|
| 75 |
+
chat_template = "gemma-3",
|
| 76 |
+
)
|
| 77 |
+
|
| 78 |
+
# Function to generate responses
|
| 79 |
+
def generate_response(question):
|
| 80 |
+
# Include system prompt in user message for Gemma 3
|
| 81 |
+
user_message = "You are an expert legal assistant providing accurate answers based on the Indian Penal Code (IPC). " + question
|
| 82 |
+
|
| 83 |
+
messages = [
|
| 84 |
+
{"role": "user", "content": user_message}
|
| 85 |
+
]
|
| 86 |
+
|
| 87 |
+
text = tokenizer.apply_chat_template(
|
| 88 |
+
messages,
|
| 89 |
+
tokenize=False,
|
| 90 |
+
add_generation_prompt=True
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
inputs = tokenizer([text], return_tensors="pt").to("cuda" if torch.cuda.is_available() else "cpu")
|
| 94 |
+
|
| 95 |
+
with torch.no_grad():
|
| 96 |
+
outputs = model.generate(
|
| 97 |
+
**inputs,
|
| 98 |
+
max_new_tokens=512,
|
| 99 |
+
temperature=0.7,
|
| 100 |
+
top_p=0.95,
|
| 101 |
+
top_k=64,
|
| 102 |
+
)
|
| 103 |
+
|
| 104 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 105 |
+
|
| 106 |
+
# Example usage
|
| 107 |
+
query = "What is the punishment for theft under Section 379 of the IPC?"
|
| 108 |
+
response = generate_response(query)
|
| 109 |
+
print(response)
|
| 110 |
+
```
|
| 111 |
|
| 112 |
## Training Details
|
| 113 |
|
| 114 |
+
**Training Data**
|
| 115 |
+
- The model was fine-tuned on a curated dataset of Indian Penal Code sections, explanations, and legal interpretations
|
| 116 |
+
- Training data was structured in a conversational format in the file "IPC_cleaned_fine_tuning.json"
|
| 117 |
+
- The dataset covers various sections of the IPC with specific focus on commonly referenced sections
|
| 118 |
+
|
| 119 |
+
**Training Procedure**
|
| 120 |
+
|
| 121 |
+
**Preprocessing**
|
| 122 |
+
- Legal texts were structured into conversational format for instruction fine-tuning
|
| 123 |
+
- Data was formatted with appropriate role tags (user/system/model)
|
| 124 |
+
- The Gemma 3 chat template was applied to format the conversations
|
| 125 |
+
|
| 126 |
+
**Training Hyperparameters**
|
| 127 |
+
* **Training regime:** LoRA (Low-Rank Adaptation) fine-tuning with Unsloth optimization
|
| 128 |
+
* **Rank (r):** 8
|
| 129 |
+
* **Alpha:** 8
|
| 130 |
+
* **Dropout:** 0
|
| 131 |
+
* **Learning rate:** 3e-4
|
| 132 |
+
* **Per device batch size:** 2
|
| 133 |
+
* **Gradient accumulation steps:** 4
|
| 134 |
+
* **Training steps:** 100
|
| 135 |
+
* **Warmup steps:** 2
|
| 136 |
+
* **Optimizer:** AdamW 8-bit
|
| 137 |
+
* **Weight decay:** 0.01
|
| 138 |
+
* **LR scheduler:** Linear
|
| 139 |
+
* **Seed:** 3407
|
| 140 |
+
* **Model bits:** 4-bit quantization (QLoRA)
|
| 141 |
+
* **Max sequence length:** 2048
|
| 142 |
+
|
| 143 |
+
**Training Configuration**
|
| 144 |
+
- Fine-tuned attention and MLP modules
|
| 145 |
+
- Used response-only training to focus on improving the model's outputs
|
| 146 |
+
- Utilized 4-bit quantization for memory efficiency
|
| 147 |
+
|
| 148 |
+
**Speeds, Sizes, Times**
|
| 149 |
+
- Training was completed in Google Colab environment
|
| 150 |
+
- Total training time was approximately 2-3 hours on a single GPU
|
| 151 |
+
- The adapter size is approximately 20MB
|
| 152 |
+
- Memory usage was optimized through 4-bit quantization
|
| 153 |
|
| 154 |
## Evaluation
|
| 155 |
|
| 156 |
+
**Testing Data, Factors & Metrics**
|
| 157 |
+
|
| 158 |
+
**Testing Data**
|
| 159 |
+
- A set of 8 test questions covering various aspects of the Indian Penal Code:
|
| 160 |
+
1. Punishment for theft
|
| 161 |
+
2. Difference between culpable homicide and murder
|
| 162 |
+
3. Concept of 'mens rea' in Indian criminal law
|
| 163 |
+
4. Punishments for different degrees of hurt
|
| 164 |
+
5. Criminal conspiracy under Section 120A
|
| 165 |
+
6. Self-defense as a valid defense
|
| 166 |
+
7. Legal definition of 'dowry death' under Section 304B
|
| 167 |
+
8. Concept of 'abetment' under the IPC
|
| 168 |
+
|
| 169 |
+
**Factors**
|
| 170 |
+
- Accuracy of legal information provided
|
| 171 |
+
- Completeness of responses
|
| 172 |
+
- Adherence to the specific sections of the IPC
|
| 173 |
+
- Handling of complex legal concepts
|
| 174 |
+
|
| 175 |
+
**Metrics**
|
| 176 |
+
- Accuracy of section citations
|
| 177 |
+
- Correctness of punishment terms
|
| 178 |
+
- Completeness of legal explanations
|
| 179 |
+
- Consistency with official IPC text
|
| 180 |
+
|
| 181 |
+
**Results**
|
| 182 |
+
- The model demonstrates strong understanding of core IPC concepts
|
| 183 |
+
- It accurately cites relevant sections and their corresponding punishments
|
| 184 |
+
- Legal explanations are comprehensive and contextually appropriate
|
| 185 |
+
- The model can differentiate between related but distinct legal concepts
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
|
| 187 |
## Environmental Impact
|
| 188 |
|
| 189 |
+
* **Hardware Type:** GPU (Google Colab)
|
| 190 |
+
* **Hours used:** Approximately 2-3 hours for fine-tuning
|
| 191 |
+
* **Cloud Provider:** Google Colab
|
| 192 |
+
* **Carbon Emitted:** Minimal due to short training time and efficient fine-tuning approach
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 193 |
|
| 194 |
+
## Technical Specifications
|
| 195 |
|
| 196 |
+
**Model Architecture and Objective**
|
| 197 |
+
- Base model: Gemma 3 4B instruction-tuned model
|
| 198 |
+
- Fine-tuning method: LoRA adapters with Unsloth optimization
|
| 199 |
+
- Objective: Provide accurate information about the Indian Penal Code while maintaining the base model's general capabilities
|
| 200 |
|
| 201 |
+
**Compute Infrastructure**
|
| 202 |
+
- Fine-tuning performed on Google Colab
|
| 203 |
+
- Used 4-bit quantization for memory efficiency
|
| 204 |
|
| 205 |
+
**Software**
|
| 206 |
+
- Python 3.x
|
| 207 |
+
- PyTorch
|
| 208 |
+
- Transformers (v4.49.0-Gemma-3)
|
| 209 |
+
- PEFT
|
| 210 |
+
- Unsloth library for optimization
|
| 211 |
+
- TRL for fine-tuning
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 212 |
|
| 213 |
## Model Card Contact
|
| 214 |
+
For questions or feedback about this model, please contact the author through the Hugging Face model repository.
|
|
|
|
|
|
|
|
|
|
|
|