Downloads · 30 days
168
11% of all-time downloads
millat/Qwen2.5-7B-BDLAW-LoRA
Qwen2.5-7B-BDLAW-LoRA is a machine learning model from millat. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for peft. The card lists the license as apache-2.0.
Downloads · 30 days
168
11% of all-time downloads
All-time downloads
1.5K
Public
Repo size
57 GB
Likes
1
Public
Click a slice to open those files.
.gguf41.5 GB · 73%
From the Hugging Face model README
A fine-tuned LoRA adapter for Qwen 2.5 7B Instruct specialized in Bangladesh legal reasoning and legal document analysis.
| Property | Value |
|---|---|
| Base Model | Qwen/Qwen2.5-7B-Instruct |
| Adapter Type | LoRA (Low-Rank Adaptation) |
| LoRA Rank (r) | 64 |
| LoRA Alpha (α) | 128 |
| Target Modules | q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj |
| Training Dataset | BDLawCorpus Dataset V1 |
| Training Examples | 4,710 Bangla legal documents |
| Training Epochs | 3 |
| Training Hours | ~6.5 hours on 2x T4 GPU |
| Precision | FP16 mixed precision + 4-bit quantization |
| Batch Size | 8 (per device) |
| Learning Rate | 2e-4 |
| Quantization | 4-bit NF4 (train) / Optional for inference |
pip install transformers peft torch accelerate
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
from peft import PeftModel
# Base model
model_id = "Qwen/Qwen2.5-7B-Instruct"
adapter_id = "millat/qwen-2.5-7b-instruct-bdlaw-lora"
# Load base model (with optional 4-bit quantization)
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_use_double_quant=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.float16
)
model = AutoModelForCausalLM.from_pretrained(
model_id,
device_map="auto",
quantization_config=bnb_config,
torch_dtype=torch.float16,
trust_remote_code=True,
)
tokenizer = AutoTokenizer.from_pretrained(model_id)
# Attach LoRA adapter
model = PeftModel.from_pretrained(model, adapter_id)
model.eval()
# Bangla legal query
prompt = "বাংলাদেশে চুক্তি আইন কী এবং এর প্রধান বৈশিষ্ট্য কি?"
# Format with chat template
messages = [{"role": "user", "content": prompt}]
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
# Generate response
inputs = tokenizer(text, return_tensors="pt").to("cuda")
outputs = model.generate(
**inputs,
max_new_tokens=512,
temperature=0.7,
do_sample=True,
top_p=0.95,
pad_token_id=tokenizer.eos_token_id,
)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(response)
BDLawCorpus Dataset V1 contains:
# Quantization (4-bit)
load_in_4bit=True
bnb_4bit_use_double_quant=True
bnb_4bit_quant_type="nf4"
bnb_4bit_compute_dtype=torch.float16
# LoRA Configuration
r=64 # Rank
lora_alpha=128 # Scaling factor
lora_dropout=0.05
bias="none"
task_type="CAUSAL_LM"
# Training Arguments
num_train_epochs=3
per_device_train_batch_size=8
gradient_accumulation_steps=2
learning_rate=2e-4
weight_decay=0.01
warmup_steps=100
save_steps=200
save_total_limit=3
logging_steps=10
fp16=True
gradient_checkpointing=True
ddp_find_unused_parameters=False
This model is optimized for:
| Metric | Value |
|---|---|
| Training Loss | 0.112 |
| Samples/Second | 0.608 |
| Steps/Second | 0.076 |
| Total Training Steps | 1,764 |
| Memory Used (per GPU) | ~14.4 GB |
| Model Size (Adapter only) | ~131 MB |
To further fine-tune this adapter on your own data:
from transformers import TrainingArguments, Trainer
training_args = TrainingArguments(
output_dir="./my_adapter",
num_train_epochs=2,
per_device_train_batch_size=8,
learning_rate=1e-4,
save_steps=100,
logging_steps=10,
fp16=True,
)
trainer = Trainer(
model=model,
args=training_args,
train_dataset=your_dataset,
data_collator=data_collator,
)
trainer.train()
If you use this model, please cite:
@model{qwen_bdlaw_lora_2025,
title={Qwen 2.5 7B Instruct - Bangladesh Legal LoRA Adapter},
author={MD Millat Hosen},
organization={BDLaw Corpus Project},
year={2025},
howpublished={\url{https://huggingface.co/millat/qwen-2.5-7b-instruct-bdlaw-lora}},
}
This adapter is provided under the Creative Commons Attribution 4.0 International (CC-BY-4.0) license.
The base model (Qwen 2.5 7B) is licensed under the Qwen License Agreement. Please refer to the original model card for details.
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.
| Version | Date | Notes |
|---|---|---|
| v1.0 | May 2025 | Initial release - 4,710 training examples |
Last Updated: May 9, 2025
Model Version: 1.0
Status: ✅ Production Ready