tree193nn commited on
Commit
5ff5c15
Β·
verified Β·
1 Parent(s): 23279aa

Update Model Card with comprehensive English documentation

Browse files
Files changed (1) hide show
  1. README.md +256 -134
README.md CHANGED
@@ -1,209 +1,331 @@
1
  ---
2
- base_model: MLP-KTLim/llama-3-Korean-Bllossom-8B
 
 
3
  library_name: peft
4
- pipeline_tag: text-generation
5
  tags:
6
- - base_model:adapter:MLP-KTLim/llama-3-Korean-Bllossom-8B
7
- - lora
8
- - sft
9
- - transformers
10
- - trl
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  ---
12
 
13
- # Model Card for Model ID
14
-
15
- <!-- Provide a quick summary of what the model is/does. -->
16
-
17
-
18
-
19
- ## Model Details
20
-
21
- ### Model Description
22
-
23
- <!-- Provide a longer summary of what this model is. -->
24
-
25
-
26
-
27
- - **Developed by:** [More Information Needed]
28
- - **Funded by [optional]:** [More Information Needed]
29
- - **Shared by [optional]:** [More Information Needed]
30
- - **Model type:** [More Information Needed]
31
- - **Language(s) (NLP):** [More Information Needed]
32
- - **License:** [More Information Needed]
33
- - **Finetuned from model [optional]:** [More Information Needed]
34
-
35
- ### Model Sources [optional]
36
-
37
- <!-- Provide the basic links for the model. -->
38
-
39
- - **Repository:** [More Information Needed]
40
- - **Paper [optional]:** [More Information Needed]
41
- - **Demo [optional]:** [More Information Needed]
42
-
43
- ## Uses
44
 
45
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
46
 
47
- ### Direct Use
 
 
 
48
 
49
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
50
 
51
- [More Information Needed]
52
 
53
- ### Downstream Use [optional]
54
 
55
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
56
 
57
- [More Information Needed]
 
 
 
 
58
 
59
- ### Out-of-Scope Use
60
-
61
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
62
-
63
- [More Information Needed]
64
-
65
- ## Bias, Risks, and Limitations
66
-
67
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
68
-
69
- [More Information Needed]
70
-
71
- ### Recommendations
72
-
73
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
74
-
75
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
76
-
77
- ## How to Get Started with the Model
78
-
79
- Use the code below to get started with the model.
80
-
81
- [More Information Needed]
82
 
83
- ## Training Details
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
 
85
- ### Training Data
 
 
 
 
 
 
 
86
 
87
- <!-- 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. -->
88
 
89
- [More Information Needed]
 
 
 
 
 
90
 
91
- ### Training Procedure
92
 
93
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
 
 
 
94
 
95
- #### Preprocessing [optional]
96
 
97
- [More Information Needed]
98
 
 
 
 
99
 
100
- #### Training Hyperparameters
101
 
102
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
 
 
 
103
 
104
- #### Speeds, Sizes, Times [optional]
 
 
 
 
 
 
105
 
106
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
 
 
 
 
 
 
 
 
107
 
108
- [More Information Needed]
 
 
109
 
110
- ## Evaluation
 
111
 
112
- <!-- This section describes the evaluation protocols and provides the results. -->
113
 
114
- ### Testing Data, Factors & Metrics
115
 
116
- #### Testing Data
117
 
118
- <!-- This should link to a Dataset Card if possible. -->
119
 
120
- [More Information Needed]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
 
122
- #### Factors
 
 
 
123
 
124
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
125
-
126
- [More Information Needed]
127
 
128
- #### Metrics
 
 
 
129
 
130
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
131
 
132
- [More Information Needed]
133
 
134
- ### Results
 
 
 
 
135
 
136
- [More Information Needed]
137
 
138
- #### Summary
 
 
139
 
 
140
 
 
141
 
142
- ## Model Examination [optional]
 
 
 
143
 
144
- <!-- Relevant interpretability work for the model goes here -->
145
 
146
- [More Information Needed]
147
 
148
- ## Environmental Impact
 
 
 
149
 
150
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
 
 
 
151
 
152
- 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).
153
 
154
- - **Hardware Type:** [More Information Needed]
155
- - **Hours used:** [More Information Needed]
156
- - **Cloud Provider:** [More Information Needed]
157
- - **Compute Region:** [More Information Needed]
158
- - **Carbon Emitted:** [More Information Needed]
 
159
 
160
- ## Technical Specifications [optional]
161
 
162
- ### Model Architecture and Objective
 
 
 
 
 
163
 
164
- [More Information Needed]
 
 
 
 
 
 
 
 
 
 
 
165
 
166
- ### Compute Infrastructure
167
 
168
- [More Information Needed]
169
 
170
- #### Hardware
 
 
171
 
172
- [More Information Needed]
173
 
174
- #### Software
 
 
 
175
 
176
- [More Information Needed]
177
 
178
- ## Citation [optional]
179
 
180
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
 
 
 
 
 
 
 
 
 
181
 
182
- **BibTeX:**
183
 
184
- [More Information Needed]
 
 
185
 
186
- **APA:**
187
 
188
- [More Information Needed]
 
 
189
 
190
- ## Glossary [optional]
191
 
192
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
 
193
 
194
- [More Information Needed]
195
 
196
- ## More Information [optional]
197
 
198
- [More Information Needed]
 
 
 
199
 
200
- ## Model Card Authors [optional]
201
 
202
- [More Information Needed]
203
 
204
- ## Model Card Contact
205
 
206
- [More Information Needed]
207
- ### Framework versions
208
 
209
- - PEFT 0.18.0
 
1
  ---
2
+ language:
3
+ - ko
4
+ license: llama3
5
  library_name: peft
 
6
  tags:
7
+ - patent
8
+ - legal
9
+ - qa
10
+ - qlora
11
+ - law
12
+ - korean
13
+ - intellectual-property
14
+ - trademark
15
+ - llama-3
16
+ base_model: MLP-KTLim/llama-3-Korean-Bllossom-8B
17
+ datasets:
18
+ - custom
19
+ metrics:
20
+ - accuracy
21
+ - perplexity
22
+ pipeline_tag: text-generation
23
+ model-index:
24
+ - name: patent-qa-llama3-qlora
25
+ results:
26
+ - task:
27
+ type: text-generation
28
+ name: Text Generation
29
+ dataset:
30
+ name: Korean Patent Decision QA
31
+ type: custom
32
+ metrics:
33
+ - type: token_accuracy
34
+ value: 0.810
35
+ name: Token Accuracy
36
+ - type: loss
37
+ value: 0.651
38
+ name: Validation Loss
39
+ - type: entropy
40
+ value: 0.665
41
+ name: Entropy
42
  ---
43
 
44
+ # Korean Patent QA - LLaMA-3 QLoRA Adapter
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
 
46
+ <div align="center">
47
 
48
+ [![Hugging Face](https://img.shields.io/badge/πŸ€—-Hugging%20Face-yellow)](https://huggingface.co/tree193nn/patent-qa-llama3-qlora)
49
+ [![GitHub](https://img.shields.io/badge/GitHub-Code-blue)](https://github.com/CocoaSoymilk/patent-qa-llama3-qlora)
50
+ [![License](https://img.shields.io/badge/License-LLaMA3-green)](https://ai.meta.com/llama/)
51
+ [![Korean](https://img.shields.io/badge/Language-Korean-red)](https://en.wikipedia.org/wiki/Korean_language)
52
 
53
+ </div>
54
 
55
+ ## Model Description
56
 
57
+ This is a **QLoRA adapter** for [LLaMA-3-Korean-Bllossom-8B](https://huggingface.co/MLP-KTLim/llama-3-Korean-Bllossom-8B), fine-tuned on **8,502 Korean patent and trademark decision documents** from the Korean Intellectual Property Tribunal. The model specializes in answering questions about Korean patent law, trademark law, and design rights with high accuracy and confidence.
58
 
59
+ ### Key Features
60
 
61
+ - 🎯 **81% Token Accuracy** on validation set
62
+ - πŸ“‰ **Low Entropy (0.665)** indicating confident predictions
63
+ - πŸ’Ύ **Memory Efficient** using QLoRA (4-bit quantization)
64
+ - πŸ›οΈ **Legal Domain Expertise** in intellectual property law
65
+ - πŸ‡°πŸ‡· **Korean Language** optimized for Korean legal terminology
66
 
67
+ ## Model Details
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
 
69
+ ### Base Model
70
+
71
+ - **Model**: [MLP-KTLim/llama-3-Korean-Bllossom-8B](https://huggingface.co/MLP-KTLim/llama-3-Korean-Bllossom-8B)
72
+ - **Architecture**: LLaMA-3
73
+ - **Parameters**: 8 Billion
74
+ - **Language**: Korean
75
+
76
+ ### Training
77
+
78
+ - **Method**: QLoRA (Quantized Low-Rank Adaptation)
79
+ - **Quantization**: 4-bit (NF4) with double quantization
80
+ - **LoRA Rank**: 16
81
+ - **LoRA Alpha**: 32
82
+ - **Target Modules**: q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj
83
+ - **Training Time**: ~7.5 hours (3 epochs)
84
+ - **GPU**: NVIDIA GPU with CUDA support
85
 
86
+ ### Dataset
87
+
88
+ - **Source**: Korean Intellectual Property Tribunal Decision Documents
89
+ - **Size**: 8,502 QA pairs
90
+ - **Split**: 90% train (7,651), 10% validation (851)
91
+ - **Domain**: Patent Law, Trademark Law, Design Rights
92
+ - **Format**: Question-Answer pairs with legal citations
93
+ - **Language**: Korean
94
 
95
+ ## Performance
96
 
97
+ | Metric | Value | Description |
98
+ |--------|-------|-------------|
99
+ | Token Accuracy | 81.0% | Percentage of correctly predicted tokens |
100
+ | Validation Loss | 0.651 | Cross-entropy loss on validation set |
101
+ | Entropy | 0.665 | Low entropy indicates confident predictions |
102
+ | Training Loss | 0.494 | Final training loss (epoch 3) |
103
 
104
+ ### Training Curve
105
 
106
+ The model showed consistent improvement across 3 epochs:
107
+ - **Epoch 1**: Loss 0.777 β†’ 0.612, Accuracy 78.2% β†’ 80.2%
108
+ - **Epoch 2**: Loss 0.589 β†’ 0.480, Accuracy 80.9% β†’ 81.0%
109
+ - **Epoch 3**: Loss stabilized at 0.494, Accuracy maintained at 81.0%
110
 
111
+ ## Usage
112
 
113
+ ### Installation
114
 
115
+ ```bash
116
+ pip install torch transformers peft bitsandbytes accelerate
117
+ ```
118
 
119
+ ### Quick Start
120
 
121
+ ```python
122
+ import torch
123
+ from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
124
+ from peft import PeftModel
125
 
126
+ # Configuration for 4-bit quantization
127
+ bnb_config = BitsAndBytesConfig(
128
+ load_in_4bit=True,
129
+ bnb_4bit_use_double_quant=True,
130
+ bnb_4bit_quant_type="nf4",
131
+ bnb_4bit_compute_dtype=torch.bfloat16
132
+ )
133
 
134
+ # Load base model
135
+ base_model_name = "MLP-KTLim/llama-3-Korean-Bllossom-8B"
136
+ tokenizer = AutoTokenizer.from_pretrained(base_model_name)
137
+ base_model = AutoModelForCausalLM.from_pretrained(
138
+ base_model_name,
139
+ quantization_config=bnb_config,
140
+ device_map="auto",
141
+ torch_dtype=torch.bfloat16,
142
+ )
143
 
144
+ # Load LoRA adapter
145
+ model = PeftModel.from_pretrained(base_model, "tree193nn/patent-qa-llama3-qlora")
146
+ model.eval()
147
 
148
+ # Inference
149
+ question = "μƒν‘œκΆŒμ˜ λ³΄ν˜ΈκΈ°κ°„μ€ μ–Όλ§ˆλ‚˜ λ˜λ‚˜μš”?"
150
 
151
+ prompt = f"""<|begin_of_text|><|start_header_id|>system<|end_header_id|>
152
 
153
+ 당신은 μ§€μ‹μž¬μ‚°κΆŒλ²• μ „λ¬Έκ°€μž…λ‹ˆλ‹€. νŠΉν—ˆ 및 μƒν‘œ κ΄€λ ¨ 법λ₯  μ§ˆλ¬Έμ— λŒ€ν•΄ μ •ν™•ν•˜κ³  μƒμ„Έν•œ 닡변을 μ œκ³΅ν•΄μ£Όμ„Έμš”.<|eot_id|><|start_header_id|>user<|end_header_id|>
154
 
155
+ {question}<|eot_id|><|start_header_id|>assistant<|end_header_id|>
156
 
157
+ """
158
 
159
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
160
+ outputs = model.generate(
161
+ **inputs,
162
+ max_new_tokens=256,
163
+ temperature=0.7,
164
+ top_p=0.9,
165
+ do_sample=True,
166
+ pad_token_id=tokenizer.eos_token_id,
167
+ )
168
+ answer = tokenizer.decode(outputs[0], skip_special_tokens=True)
169
+ print(answer)
170
+ ```
171
+
172
+ ### Example Questions
173
+
174
+ ```python
175
+ questions = [
176
+ "μƒν‘œκΆŒμ˜ λ³΄ν˜ΈκΈ°κ°„μ€ μ–Όλ§ˆλ‚˜ λ˜λ‚˜μš”?", # How long is trademark protection?
177
+ "νŠΉν—ˆ μΆœμ› μ‹œ ν•„μš”ν•œ μ„œλ₯˜λŠ” λ¬΄μ—‡μΈκ°€μš”?", # What documents are needed for patent filing?
178
+ "λ””μžμΈκΆŒκ³Ό μ €μž‘κΆŒμ˜ μ°¨μ΄λŠ” λ¬΄μ—‡μΈκ°€μš”?", # What's the difference between design rights and copyright?
179
+ ]
180
+ ```
181
+
182
+ ## Intended Use
183
+
184
+ ### Primary Use Cases
185
 
186
+ βœ… **Question Answering** about Korean intellectual property law
187
+ βœ… **Legal Research** assistance for patent and trademark matters
188
+ βœ… **Educational Tool** for learning Korean IP law
189
+ βœ… **Information Retrieval** from patent decision documents
190
 
191
+ ### Out-of-Scope Use
 
 
192
 
193
+ ❌ **Legal Advice**: This model should NOT be used as a substitute for professional legal counsel
194
+ ❌ **Official Decisions**: Outputs are not legally binding
195
+ ❌ **Non-Korean Languages**: Optimized for Korean only
196
+ ❌ **General Purpose QA**: Specializes in IP law, may not perform well on general topics
197
 
198
+ ## Limitations
199
 
200
+ ### Known Limitations
201
 
202
+ 1. **Temporal Limitation**: Training data is from before 2024; recent legal changes may not be reflected
203
+ 2. **Domain Specificity**: Performs best on patent/trademark law; limited on other legal areas
204
+ 3. **Language**: Optimized for Korean; English or other languages not supported
205
+ 4. **Hallucination Risk**: May generate plausible but incorrect legal interpretations
206
+ 5. **Context Length**: Limited to 2048 tokens due to training configuration
207
 
208
+ ### Bias and Fairness
209
 
210
+ - **Training Data Bias**: Reflects biases present in Korean Intellectual Property Tribunal decisions
211
+ - **Geographic Focus**: Specific to Korean law; not applicable to other jurisdictions
212
+ - **Language Bias**: Korean legal terminology heavily featured
213
 
214
+ ## Ethical Considerations
215
 
216
+ ⚠️ **Important Notice**: This model is intended for research and educational purposes only. Users should:
217
 
218
+ - **Verify Information**: Always cross-reference with official legal sources
219
+ - **Seek Professional Advice**: Consult qualified legal professionals for actual cases
220
+ - **Understand Limitations**: Recognize the model's domain and temporal constraints
221
+ - **Use Responsibly**: Do not use for misleading or fraudulent purposes
222
 
223
+ ## Technical Specifications
224
 
225
+ ### Hardware Requirements
226
 
227
+ **Minimum**:
228
+ - GPU: 16GB VRAM (e.g., NVIDIA RTX 4080, A4000)
229
+ - RAM: 32GB
230
+ - Storage: 20GB (base model + adapter)
231
 
232
+ **Recommended**:
233
+ - GPU: 24GB+ VRAM (e.g., NVIDIA RTX 4090, A5000, A6000)
234
+ - RAM: 64GB
235
+ - Storage: 30GB
236
 
237
+ ### Software Requirements
238
 
239
+ - Python 3.8+
240
+ - PyTorch 2.0+
241
+ - Transformers 4.38.0+
242
+ - PEFT 0.8.0+
243
+ - BitsAndBytes 0.42.0+
244
+ - CUDA 11.8+ or 12.0+
245
 
246
+ ## Training Hyperparameters
247
 
248
+ ```yaml
249
+ # QLoRA Configuration
250
+ lora_r: 16
251
+ lora_alpha: 32
252
+ lora_dropout: 0.05
253
+ quantization: 4-bit (NF4)
254
 
255
+ # Training Configuration
256
+ epochs: 3
257
+ batch_size: 2 (per device)
258
+ gradient_accumulation_steps: 8
259
+ effective_batch_size: 16
260
+ learning_rate: 2e-4
261
+ lr_scheduler: cosine
262
+ warmup_ratio: 0.03
263
+ weight_decay: 0.01
264
+ optimizer: paged_adamw_32bit
265
+ max_seq_length: 2048
266
+ ```
267
 
268
+ ## Evaluation
269
 
270
+ ### Metrics Explanation
271
 
272
+ - **Token Accuracy (81%)**: Measures how many individual tokens (words/subwords) match the ground truth
273
+ - **Validation Loss (0.651)**: Lower is better; indicates model's prediction confidence
274
+ - **Entropy (0.665)**: Low entropy means the model makes confident predictions rather than being uncertain
275
 
276
+ ### Comparison to Base Model
277
 
278
+ The fine-tuned adapter shows significant improvements in the legal domain:
279
+ - Better understanding of Korean legal terminology
280
+ - More accurate citations of relevant laws and regulations
281
+ - Reduced hallucination on IP law topics
282
 
283
+ ## Citation
284
 
285
+ If you use this model in your research, please cite:
286
 
287
+ ```bibtex
288
+ @misc{patent-qa-llama3-qlora,
289
+ author = {tree193nn},
290
+ title = {Korean Patent QA with LLaMA-3 QLoRA},
291
+ year = {2024},
292
+ publisher = {Hugging Face},
293
+ howpublished = {\url{https://huggingface.co/tree193nn/patent-qa-llama3-qlora}},
294
+ note = {QLoRA adapter for Korean patent and trademark law question answering}
295
+ }
296
+ ```
297
 
298
+ ## License
299
 
300
+ - **Base Model**: LLaMA-3 License (Meta)
301
+ - **Adapter**: MIT License
302
+ - **Training Data**: Public Korean Intellectual Property Tribunal documents
303
 
304
+ ## Acknowledgments
305
 
306
+ - **Base Model**: [MLP-KTLim/llama-3-Korean-Bllossom-8B](https://huggingface.co/MLP-KTLim/llama-3-Korean-Bllossom-8B)
307
+ - **Training Method**: QLoRA by Dettmers et al. ([Paper](https://arxiv.org/abs/2305.14314))
308
+ - **Data Source**: Korean Intellectual Property Tribunal
309
 
310
+ ## Contact
311
 
312
+ - **GitHub**: [CocoaSoymilk/patent-qa-llama3-qlora](https://github.com/CocoaSoymilk/patent-qa-llama3-qlora)
313
+ - **Hugging Face**: [tree193nn](https://huggingface.co/tree193nn)
314
 
315
+ ## Version History
316
 
317
+ ### v1.0.0 (2024-12-07)
318
 
319
+ - Initial release
320
+ - Fine-tuned on 8,502 Korean patent decision documents
321
+ - Achieved 81% token accuracy
322
+ - QLoRA adapter with 4-bit quantization
323
 
324
+ ---
325
 
326
+ <div align="center">
327
 
328
+ **Built with ❀️ for the Korean legal AI community**
329
 
330
+ </div>
 
331