PEFT
Safetensors
GGUF
English
Bengali
conversational
millat commited on
Commit
4527dfe
·
verified ·
1 Parent(s): 1677b59

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +235 -150
README.md CHANGED
@@ -1,202 +1,287 @@
1
  ---
2
  base_model: Qwen/Qwen2.5-7B-Instruct
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
- ### Model Description
15
-
16
- <!-- Provide a longer summary of what this model is. -->
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
- - **Repository:** [More Information Needed]
33
- - **Paper [optional]:** [More Information Needed]
34
- - **Demo [optional]:** [More Information Needed]
35
-
36
- ## Uses
37
-
38
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
-
40
- ### Direct Use
41
-
42
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
43
-
44
- [More Information Needed]
45
-
46
- ### Downstream Use [optional]
47
-
48
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
49
-
50
- [More Information Needed]
51
-
52
- ### Out-of-Scope Use
53
-
54
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
55
-
56
- [More Information Needed]
57
-
58
- ## Bias, Risks, and Limitations
59
-
60
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
61
-
62
- [More Information Needed]
63
-
64
- ### Recommendations
65
-
66
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
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
- Use the code below to get started with the model.
73
-
74
- [More Information Needed]
75
-
76
- ## Training Details
77
-
78
- ### Training Data
79
-
80
- <!-- 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. -->
81
-
82
- [More Information Needed]
83
-
84
- ### Training Procedure
85
-
86
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
87
-
88
- #### Preprocessing [optional]
89
-
90
- [More Information Needed]
91
-
92
-
93
- #### Training Hyperparameters
94
-
95
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
96
-
97
- #### Speeds, Sizes, Times [optional]
98
-
99
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
-
101
- [More Information Needed]
102
-
103
- ## Evaluation
104
-
105
- <!-- This section describes the evaluation protocols and provides the results. -->
106
-
107
- ### Testing Data, Factors & Metrics
108
-
109
- #### Testing Data
110
-
111
- <!-- This should link to a Dataset Card if possible. -->
112
-
113
- [More Information Needed]
114
 
115
- #### Factors
116
 
117
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
 
119
- [More Information Needed]
120
 
121
- #### Metrics
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
 
123
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
124
 
125
- [More Information Needed]
126
 
127
- ### Results
128
 
129
- [More Information Needed]
 
 
 
 
 
 
130
 
131
- #### Summary
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
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
144
 
145
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
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
- [More Information Needed]
 
158
 
159
- ### Compute Infrastructure
160
 
161
- [More Information Needed]
162
 
163
- #### Hardware
164
 
165
- [More Information Needed]
 
 
 
 
 
 
 
 
166
 
167
- #### Software
168
 
169
- [More Information Needed]
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.13.0
 
 
 
1
  ---
2
  base_model: Qwen/Qwen2.5-7B-Instruct
3
  library_name: peft
4
+ license: apache-2.0
5
+ datasets:
6
+ - millat/BDLawCorpus-Dataset-V1
7
+ language:
8
+ - en
9
+ - bn
10
  ---
11
 
12
+ # Qwen 2.5 7B Instruct - Bangladesh Legal LoRA Adapter
13
 
14
+ ![Model Card](https://img.shields.io/badge/Model-Qwen%202.5%207B-blue)
15
+ ![LoRA](https://img.shields.io/badge/Training-LoRA-green)
16
+ ![Hardware](https://img.shields.io/badge/Hardware-2x%20T4%20GPU-yellow)
17
+ ![Language](https://img.shields.io/badge/Language-Bangla%20%7C%20English-orange)
18
 
19
+ A fine-tuned LoRA adapter for **Qwen 2.5 7B Instruct** specialized in **Bangladesh legal reasoning** and **legal document analysis**.
20
 
21
+ ---
22
 
23
+ ## 📋 Model Details
24
+
25
+ | Property | Value |
26
+ |----------|-------|
27
+ | **Base Model** | [Qwen/Qwen2.5-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-7B-Instruct) |
28
+ | **Adapter Type** | LoRA (Low-Rank Adaptation) |
29
+ | **LoRA Rank (r)** | 64 |
30
+ | **LoRA Alpha (α)** | 128 |
31
+ | **Target Modules** | q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj |
32
+ | **Training Dataset** | [BDLawCorpus Dataset V1](https://huggingface.co/datasets/millat/BDLawCorpus-Dataset-V1) |
33
+ | **Training Examples** | 4,710 Bangla legal documents |
34
+ | **Training Epochs** | 3 |
35
+ | **Training Hours** | ~6.5 hours on 2x T4 GPU |
36
+ | **Precision** | FP16 mixed precision + 4-bit quantization |
37
+ | **Batch Size** | 8 (per device) |
38
+ | **Learning Rate** | 2e-4 |
39
+ | **Quantization** | 4-bit NF4 (train) / Optional for inference |
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
+ ---
42
 
43
+ ## 🚀 Quick Start
44
+
45
+ ### Installation
46
+
47
+ ```bash
48
+ pip install transformers peft torch accelerate
49
+ ```
50
+
51
+ ### Loading the Model
52
+
53
+ ```python
54
+ import torch
55
+ from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
56
+ from peft import PeftModel
57
+
58
+ # Base model
59
+ model_id = "Qwen/Qwen2.5-7B-Instruct"
60
+ adapter_id = "millat/qwen-2.5-7b-instruct-bdlaw-lora"
61
+
62
+ # Load base model (with optional 4-bit quantization)
63
+ bnb_config = BitsAndBytesConfig(
64
+ load_in_4bit=True,
65
+ bnb_4bit_use_double_quant=True,
66
+ bnb_4bit_quant_type="nf4",
67
+ bnb_4bit_compute_dtype=torch.float16
68
+ )
69
+
70
+ model = AutoModelForCausalLM.from_pretrained(
71
+ model_id,
72
+ device_map="auto",
73
+ quantization_config=bnb_config,
74
+ torch_dtype=torch.float16,
75
+ trust_remote_code=True,
76
+ )
77
+
78
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
79
+
80
+ # Attach LoRA adapter
81
+ model = PeftModel.from_pretrained(model, adapter_id)
82
+ model.eval()
83
+ ```
84
+
85
+ ### Inference Example
86
+
87
+ ```python
88
+ # Bangla legal query
89
+ prompt = "বাংলাদেশে চুক্তি আইন কী এবং এর প্রধান বৈশিষ্ট্য কি?"
90
+
91
+ # Format with chat template
92
+ messages = [{"role": "user", "content": prompt}]
93
+ text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
94
+
95
+ # Generate response
96
+ inputs = tokenizer(text, return_tensors="pt").to("cuda")
97
+ outputs = model.generate(
98
+ **inputs,
99
+ max_new_tokens=512,
100
+ temperature=0.7,
101
+ do_sample=True,
102
+ top_p=0.95,
103
+ pad_token_id=tokenizer.eos_token_id,
104
+ )
105
+
106
+ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
107
+ print(response)
108
+ ```
109
 
110
+ ---
111
 
112
+ ## 📊 Training Details
113
+
114
+ ### Dataset
115
+
116
+ **BDLawCorpus Dataset V1** contains:
117
+ - **4,710** Bangla legal documents and case studies
118
+ - Multi-format: Chat templates with conversation pairs
119
+ - Topics: Contract Law, Criminal Law, Constitutional Law, Property Law, Labor Law
120
+ - Quality: Manually validated and cleaned
121
+
122
+ ### Training Configuration
123
+
124
+ ```python
125
+ # Quantization (4-bit)
126
+ load_in_4bit=True
127
+ bnb_4bit_use_double_quant=True
128
+ bnb_4bit_quant_type="nf4"
129
+ bnb_4bit_compute_dtype=torch.float16
130
+
131
+ # LoRA Configuration
132
+ r=64 # Rank
133
+ lora_alpha=128 # Scaling factor
134
+ lora_dropout=0.05
135
+ bias="none"
136
+ task_type="CAUSAL_LM"
137
+
138
+ # Training Arguments
139
+ num_train_epochs=3
140
+ per_device_train_batch_size=8
141
+ gradient_accumulation_steps=2
142
+ learning_rate=2e-4
143
+ weight_decay=0.01
144
+ warmup_steps=100
145
+ save_steps=200
146
+ save_total_limit=3
147
+ logging_steps=10
148
+ fp16=True
149
+ gradient_checkpointing=True
150
+ ddp_find_unused_parameters=False
151
+ ```
152
+
153
+ ### Training Environment
154
+
155
+ - **Hardware**: Kaggle 2x T4 GPU (15GB each)
156
+ - **Framework**: Hugging Face Transformers + PEFT + Accelerate
157
+ - **Parallelism**: Distributed Data Parallel (DDP)
158
+ - **Total Training Time**: ~6.5 hours
159
+ - **Final Loss**: 0.112
160
 
161
+ ---
162
 
163
+ ## 💡 Use Cases
164
 
165
+ This model is optimized for:
166
 
167
+ 1. **Legal Document Summarization** - Summarize Bangla legal texts and acts
168
+ 2. **Legal Question Answering** - Answer questions about Bangladesh law
169
+ 3. **Contract Analysis** - Analyze and explain contract clauses
170
+ 4. **Case Law Explanation** - Provide insights into court decisions
171
+ 5. **Regulatory Compliance** - Advise on Bangladesh legal compliance
172
+ 6. **Document Classification** - Categorize legal documents
173
+ 7. **Legal Research** - Retrieve relevant case law and precedents
174
 
175
+ ---
176
 
177
+ ## 📈 Performance Metrics
178
 
179
+ | Metric | Value |
180
+ |--------|-------|
181
+ | Training Loss | 0.112 |
182
+ | Samples/Second | 0.608 |
183
+ | Steps/Second | 0.076 |
184
+ | Total Training Steps | 1,764 |
185
+ | Memory Used (per GPU) | ~14.4 GB |
186
+ | Model Size (Adapter only) | ~131 MB |
187
 
188
+ ---
189
 
190
+ ## ⚖️ Limitations
191
 
192
+ - **Language-specific**: Optimized for Bangla legal documents; English queries may have lower accuracy
193
+ - **Domain-specific**: Trained on Bangladesh legal corpus; may not generalize to other domains
194
+ - **Knowledge cutoff**: Based on training data; may not reflect recent legal changes
195
+ - **LLM limitations**: Can hallucinate; always verify outputs with official sources
196
+ - **No real-time updates**: Requires retraining for new laws or amendments
197
 
198
+ ---
199
 
200
+ ## 🔧 Fine-tuning & Adaptation
201
 
202
+ To further fine-tune this adapter on your own data:
203
 
204
+ ```python
205
+ from transformers import TrainingArguments, Trainer
 
 
 
206
 
207
+ training_args = TrainingArguments(
208
+ output_dir="./my_adapter",
209
+ num_train_epochs=2,
210
+ per_device_train_batch_size=8,
211
+ learning_rate=1e-4,
212
+ save_steps=100,
213
+ logging_steps=10,
214
+ fp16=True,
215
+ )
216
 
217
+ trainer = Trainer(
218
+ model=model,
219
+ args=training_args,
220
+ train_dataset=your_dataset,
221
+ data_collator=data_collator,
222
+ )
223
 
224
+ trainer.train()
225
+ ```
226
 
227
+ ---
228
 
229
+ ## 📝 Citation
230
 
231
+ If you use this model, please cite:
232
 
233
+ ```bibtex
234
+ @model{qwen_bdlaw_lora_2025,
235
+ title={Qwen 2.5 7B Instruct - Bangladesh Legal LoRA Adapter},
236
+ author={MD Millat Hosen},
237
+ organization={BDLaw Corpus Project},
238
+ year={2025},
239
+ howpublished={\url{https://huggingface.co/millat/qwen-2.5-7b-instruct-bdlaw-lora}},
240
+ }
241
+ ```
242
 
243
+ ---
244
 
245
+ ## 📄 License
246
 
247
+ This adapter is provided under the **Creative Commons Attribution 4.0 International (CC-BY-4.0)** license.
248
 
249
+ The base model (Qwen 2.5 7B) is licensed under the **Qwen License Agreement**. Please refer to the [original model card](https://huggingface.co/Qwen/Qwen2.5-7B-Instruct) for details.
250
 
251
+ ---
252
 
253
+ ## 👥 Contact & Support
254
 
255
+ - **Model Developer**: MD Millat Hosen
256
+ - **Project**: [BDLawCorpus](https://github.com/millathosen/BDLawCorpus)
257
+ - **Email**: Contact via GitHub issues
258
+ - **Repository**: [BDLawCorpus GitHub](https://huggingface.co/millat)
259
 
260
+ ---
261
 
262
+ ## 🙏 Acknowledgments
263
 
264
+ - **Qwen Team** for the excellent base model architecture
265
+ - **Hugging Face** for the transformers library and model hosting
266
+ - **Kaggle** for providing free GPU compute
267
+ - **Bangladesh Legal Community** for data and domain expertise
268
 
269
+ ---
270
 
271
+ ## ⚠️ Disclaimer
272
 
273
+ This model is provided for educational and research purposes. While we strive for accuracy, legal advice should always be verified with qualified legal professionals. The model authors assume no responsibility for any consequences arising from the use of this model for legal decision-making.
274
 
275
+ ---
276
 
277
+ ## 🔄 Model Updates
278
 
279
+ | Version | Date | Notes |
280
+ |---------|------|-------|
281
+ | v1.0 | May 2025 | Initial release - 4,710 training examples |
282
 
283
+ ---
 
284
 
285
+ **Last Updated**: May 9, 2025
286
+ **Model Version**: 1.0
287
+ **Status**: ✅ Production Ready