Update README.md
Browse files
README.md
CHANGED
@@ -1,122 +1,122 @@
|
|
1 |
-
---
|
2 |
-
model_name: "Qwen3-0.6B-en-law-qa"
|
3 |
-
finetuned_by: "Ahsan Ahmed Khan (Ontario)"
|
4 |
-
model_type: "Fine-tuned Causal Language Model for Legal Q&A"
|
5 |
-
base_model: "Qwen/Qwen3-0.6B"
|
6 |
-
language: "en"
|
7 |
-
finetuning_method: "LoRA (Low-Rank Adaptation)"
|
8 |
-
license: "apache-2.0"
|
9 |
-
datasets:
|
10 |
-
- "haistudy/en_law_qa"
|
11 |
-
tags:
|
12 |
-
- "legal"
|
13 |
-
- "question-answering"
|
14 |
-
- "law"
|
15 |
-
- "instruction-tuned"
|
16 |
-
---
|
17 |
-
|
18 |
-
# Model Card for Qwen3-0.6B-en-law-qa
|
19 |
-
|
20 |
-
## Model Details
|
21 |
-
- **Developed by:**
|
22 |
-
- **Base Model:** [Qwen/Qwen3-0.6B](https://huggingface.co/Qwen/Qwen3-0.6B)
|
23 |
-
- **Dataset:** [haistudy/en_law_qa](https://huggingface.co/datasets/haistudy/en_law_qa)
|
24 |
-
- **Language:** English
|
25 |
-
- **License:** Apache 2.0
|
26 |
-
- **Fine-tuning Approach:** Parameter-Efficient Fine-Tuning (LoRA)
|
27 |
-
|
28 |
-
## Model Description
|
29 |
-
Fine-tuned version of Qwen3-0.6B optimized for legal question answering. Trained on 5,560 legal QA pairs covering:
|
30 |
-
- Contract law
|
31 |
-
- Intellectual property
|
32 |
-
- Criminal law
|
33 |
-
- Family law
|
34 |
-
- Environmental law
|
35 |
-
|
36 |
-
## Intended Uses
|
37 |
-
✅ Legal research assistance
|
38 |
-
✅ Legal education
|
39 |
-
✅ Explaining legal concepts
|
40 |
-
❌ Actual legal advice
|
41 |
-
❌ Handling sensitive personal legal matters
|
42 |
-
|
43 |
-
## Training Configuration
|
44 |
-
training_parameters:
|
45 |
-
epochs: 73 (partial training)
|
46 |
-
batch_size: 16
|
47 |
-
gradient_accumulation_steps: 16
|
48 |
-
learning_rate: 2e-4
|
49 |
-
optimizer: "paged_adamw_8bit"
|
50 |
-
|
51 |
-
quantization:
|
52 |
-
load_in_4bit: true
|
53 |
-
bnb_4bit_quant_type: "nf4"
|
54 |
-
bnb_4bit_compute_dtype: "bfloat16"
|
55 |
-
|
56 |
-
lora_config:
|
57 |
-
r: 8
|
58 |
-
lora_alpha: 32
|
59 |
-
target_modules:
|
60 |
-
- "q_proj"
|
61 |
-
- "k_proj"
|
62 |
-
- "v_proj"
|
63 |
-
- "o_proj"
|
64 |
-
lora_dropout: 0.05
|
65 |
-
bias: "none"
|
66 |
-
|
67 |
-
Usage Example
|
68 |
-
|
69 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM
|
70 |
-
from peft import PeftModel
|
71 |
-
|
72 |
-
model_name = "Qwen/Qwen3-0.6B"
|
73 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
74 |
-
base_model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16, device_map="auto")
|
75 |
-
model = PeftModel.from_pretrained(base_model, "your-username/Qwen3-0.6B-en-law-qa")
|
76 |
-
|
77 |
-
# Create prompt
|
78 |
-
question = "What are the key elements of a valid contract?"
|
79 |
-
messages = [
|
80 |
-
{"role": "user", "content": question}
|
81 |
-
]
|
82 |
-
text = tokenizer.apply_chat_template(
|
83 |
-
messages,
|
84 |
-
tokenize=False,
|
85 |
-
add_generation_prompt=True
|
86 |
-
)
|
87 |
-
|
88 |
-
# Generate response
|
89 |
-
inputs = tokenizer(text, return_tensors="pt").to(model.device)
|
90 |
-
outputs = model.generate(**inputs, max_new_tokens=256)
|
91 |
-
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
92 |
-
Training Data
|
93 |
-
yaml
|
94 |
-
dataset_stats:
|
95 |
-
samples: 5560
|
96 |
-
format: |
|
97 |
-
<|im_start|>user
|
98 |
-
{Question}<|im_end|>
|
99 |
-
<|im_start|>assistant
|
100 |
-
{Answer}<|im_end|>
|
101 |
-
data_sources:
|
102 |
-
- Contract law
|
103 |
-
- Intellectual property
|
104 |
-
- Criminal law
|
105 |
-
- Family law
|
106 |
-
- Environmental law
|
107 |
-
Limitations
|
108 |
-
Limited to knowledge in training data (2023 cutoff)
|
109 |
-
|
110 |
-
May generate plausible but incorrect information
|
111 |
-
|
112 |
-
Not a substitute for professional legal advice
|
113 |
-
|
114 |
-
English-only capability
|
115 |
-
|
116 |
-
Environmental Impact
|
117 |
-
Hardware: 1 × NVIDIA T4 GPU (Google Colab)
|
118 |
-
CO2 Emissions: ≈0.8 kg (estimated during partial training)
|
119 |
-
Calculated using Machine Learning Impact calculator
|
120 |
-
|
121 |
-
Contact
|
122 |
For questions or feedback: ahsanahmedkhan@proton.me
|
|
|
1 |
+
---
|
2 |
+
model_name: "Qwen3-0.6B-en-law-qa"
|
3 |
+
finetuned_by: "Ahsan Ahmed Khan (Ontario)"
|
4 |
+
model_type: "Fine-tuned Causal Language Model for Legal Q&A"
|
5 |
+
base_model: "Qwen/Qwen3-0.6B"
|
6 |
+
language: "en"
|
7 |
+
finetuning_method: "LoRA (Low-Rank Adaptation)"
|
8 |
+
license: "apache-2.0"
|
9 |
+
datasets:
|
10 |
+
- "haistudy/en_law_qa"
|
11 |
+
tags:
|
12 |
+
- "legal"
|
13 |
+
- "question-answering"
|
14 |
+
- "law"
|
15 |
+
- "instruction-tuned"
|
16 |
+
---
|
17 |
+
|
18 |
+
# Model Card for Qwen3-0.6B-en-law-qa
|
19 |
+
|
20 |
+
## Model Details
|
21 |
+
- **Developed by:** Ontario (Ahsan Ahmed KHan)
|
22 |
+
- **Base Model:** [Qwen/Qwen3-0.6B](https://huggingface.co/Qwen/Qwen3-0.6B)
|
23 |
+
- **Dataset:** [haistudy/en_law_qa](https://huggingface.co/datasets/haistudy/en_law_qa)
|
24 |
+
- **Language:** English
|
25 |
+
- **License:** Apache 2.0
|
26 |
+
- **Fine-tuning Approach:** Parameter-Efficient Fine-Tuning (LoRA)
|
27 |
+
|
28 |
+
## Model Description
|
29 |
+
Fine-tuned version of Qwen3-0.6B optimized for legal question answering. Trained on 5,560 legal QA pairs covering:
|
30 |
+
- Contract law
|
31 |
+
- Intellectual property
|
32 |
+
- Criminal law
|
33 |
+
- Family law
|
34 |
+
- Environmental law
|
35 |
+
|
36 |
+
## Intended Uses
|
37 |
+
✅ Legal research assistance
|
38 |
+
✅ Legal education
|
39 |
+
✅ Explaining legal concepts
|
40 |
+
❌ Actual legal advice
|
41 |
+
❌ Handling sensitive personal legal matters
|
42 |
+
|
43 |
+
## Training Configuration
|
44 |
+
training_parameters:
|
45 |
+
epochs: 73 (partial training)
|
46 |
+
batch_size: 16
|
47 |
+
gradient_accumulation_steps: 16
|
48 |
+
learning_rate: 2e-4
|
49 |
+
optimizer: "paged_adamw_8bit"
|
50 |
+
|
51 |
+
quantization:
|
52 |
+
load_in_4bit: true
|
53 |
+
bnb_4bit_quant_type: "nf4"
|
54 |
+
bnb_4bit_compute_dtype: "bfloat16"
|
55 |
+
|
56 |
+
lora_config:
|
57 |
+
r: 8
|
58 |
+
lora_alpha: 32
|
59 |
+
target_modules:
|
60 |
+
- "q_proj"
|
61 |
+
- "k_proj"
|
62 |
+
- "v_proj"
|
63 |
+
- "o_proj"
|
64 |
+
lora_dropout: 0.05
|
65 |
+
bias: "none"
|
66 |
+
|
67 |
+
Usage Example
|
68 |
+
|
69 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
70 |
+
from peft import PeftModel
|
71 |
+
|
72 |
+
model_name = "Qwen/Qwen3-0.6B"
|
73 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
74 |
+
base_model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16, device_map="auto")
|
75 |
+
model = PeftModel.from_pretrained(base_model, "your-username/Qwen3-0.6B-en-law-qa")
|
76 |
+
|
77 |
+
# Create prompt
|
78 |
+
question = "What are the key elements of a valid contract?"
|
79 |
+
messages = [
|
80 |
+
{"role": "user", "content": question}
|
81 |
+
]
|
82 |
+
text = tokenizer.apply_chat_template(
|
83 |
+
messages,
|
84 |
+
tokenize=False,
|
85 |
+
add_generation_prompt=True
|
86 |
+
)
|
87 |
+
|
88 |
+
# Generate response
|
89 |
+
inputs = tokenizer(text, return_tensors="pt").to(model.device)
|
90 |
+
outputs = model.generate(**inputs, max_new_tokens=256)
|
91 |
+
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
92 |
+
Training Data
|
93 |
+
yaml
|
94 |
+
dataset_stats:
|
95 |
+
samples: 5560
|
96 |
+
format: |
|
97 |
+
<|im_start|>user
|
98 |
+
{Question}<|im_end|>
|
99 |
+
<|im_start|>assistant
|
100 |
+
{Answer}<|im_end|>
|
101 |
+
data_sources:
|
102 |
+
- Contract law
|
103 |
+
- Intellectual property
|
104 |
+
- Criminal law
|
105 |
+
- Family law
|
106 |
+
- Environmental law
|
107 |
+
Limitations
|
108 |
+
Limited to knowledge in training data (2023 cutoff)
|
109 |
+
|
110 |
+
May generate plausible but incorrect information
|
111 |
+
|
112 |
+
Not a substitute for professional legal advice
|
113 |
+
|
114 |
+
English-only capability
|
115 |
+
|
116 |
+
Environmental Impact
|
117 |
+
Hardware: 1 × NVIDIA T4 GPU (Google Colab)
|
118 |
+
CO2 Emissions: ≈0.8 kg (estimated during partial training)
|
119 |
+
Calculated using Machine Learning Impact calculator
|
120 |
+
|
121 |
+
Contact
|
122 |
For questions or feedback: ahsanahmedkhan@proton.me
|