potsunwu commited on
Commit
8ff586c
·
verified ·
1 Parent(s): e329bb8

Upload folder using huggingface_hub

Browse files
README.md ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - zh
4
+ - nan
5
+ license: apache-2.0
6
+ base_model: yentinglin/Taiwan-LLM-7B-v2.1-chat
7
+ tags:
8
+ - taiwanese
9
+ - taigi
10
+ - reading-comprehension
11
+ - lora
12
+ - peft
13
+ library_name: peft
14
+ ---
15
+
16
+ # Taiwan-LLM Taigi Reading Comprehension LoRA
17
+
18
+ 台語閱讀理解任務的 LoRA adapter,基於 Taiwan-LLM-7B-v2.1-chat 微調。
19
+
20
+ ## 📊 模型效能
21
+
22
+ - **Test Accuracy**: 73.33%
23
+ - **Validation Loss**: 0.573 (最佳 checkpoint)
24
+ - **Baseline**: 53.7% (2020 競賽最佳成績)
25
+ - **提升**: +19.63 百分點
26
+
27
+ ## 🎯 模型資訊
28
+
29
+ - **基礎模型**: yentinglin/Taiwan-LLM-7B-v2.1-chat
30
+ - **訓練任務**: 台語閱讀理解多選題
31
+ - **訓練資料**: 13,550 筆台語文章 + 12,195 筆 Alpaca 台語對話
32
+ - **LoRA Rank**: 32
33
+ - **LoRA Alpha**: 32
34
+ - **Target Modules**: q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj
35
+
36
+ ## 💻 使用方法
37
+
38
+ ### 安裝依賴
39
+
40
+ ```bash
41
+ pip install transformers peft torch unsloth
42
+ ```
43
+
44
+ ### 載入模型
45
+
46
+ ```python
47
+ from unsloth import FastLanguageModel
48
+ from peft import PeftModel
49
+
50
+ # 1. 載入基礎模型
51
+ base_model, tokenizer = FastLanguageModel.from_pretrained(
52
+ model_name="yentinglin/Taiwan-LLM-7B-v2.1-chat",
53
+ max_seq_length=2048,
54
+ dtype=None,
55
+ load_in_4bit=True,
56
+ )
57
+
58
+ # 2. 載入 LoRA adapter
59
+ model = PeftModel.from_pretrained(
60
+ base_model,
61
+ "YOUR_USERNAME/taiwan-llm-taigi-lora" # 記得改成你的用戶名
62
+ )
63
+
64
+ # 3. 切換到推論模式
65
+ FastLanguageModel.for_inference(model)
66
+ ```
67
+
68
+ ### 推論範例
69
+
70
+ ```python
71
+ # 準備 prompt
72
+ prompt = """USER: 請仔細閱讀以下台文文章,並回答問題。
73
+
74
+ 文章:
75
+ 明年元旦起,交通部新規定,汽車輪胎胎紋深度將納入定期檢驗項之一,一旦深度未達一.六公厘,佮一個月內無換胎,將會去予吊銷牌仔照。
76
+
77
+ 問題:汽車胎紋未到達多毫米將會予人吊銷牌?
78
+
79
+ 選項:
80
+ 1. 一.五公厘
81
+ 2. 一.四厘
82
+ 3. 一.三公厘
83
+ 4. 一.六公厘
84
+
85
+ 請回答: ASSISTANT:"""
86
+
87
+ # 生成答案
88
+ inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
89
+ outputs = model.generate(
90
+ **inputs,
91
+ max_new_tokens=10,
92
+ temperature=0.1,
93
+ do_sample=False,
94
+ )
95
+
96
+ answer = tokenizer.decode(outputs[0], skip_special_tokens=True)
97
+ print(answer) # 輸出: 4
98
+ ```
99
+
100
+ ## 🔧 訓練細節
101
+
102
+ ### 訓練超參數
103
+
104
+ - Epochs: 3
105
+ - Learning Rate: 2e-4 → 5e-5 (cosine decay)
106
+ - Batch Size: 16 (4 per device × 4 gradient accumulation)
107
+ - Optimizer: AdamW 8-bit
108
+ - Weight Decay: 0.01
109
+ - Warmup Ratio: 0.1
110
+
111
+ ### LoRA 配置
112
+
113
+ ```python
114
+ {
115
+ "r": 32,
116
+ "lora_alpha": 32,
117
+ "lora_dropout": 0.05,
118
+ "bias": "none",
119
+ "target_modules": [
120
+ "q_proj", "k_proj", "v_proj", "o_proj",
121
+ "gate_proj", "up_proj", "down_proj"
122
+ ]
123
+ }
124
+ ```
125
+
126
+ ### 訓練過程
127
+
128
+ - Total Steps: ~45,500
129
+ - Best Checkpoint: Step 30,000-31,000
130
+ - Training Loss: 1.697 → 0.428
131
+ - Validation Loss: 1.741 → 0.506
132
+
133
+ ## 📈 訓練曲線
134
+
135
+ 最佳驗證點在 Step 30,000 左右,之後出現輕微過擬合。
136
+
137
+ ## ⚠️ 限制
138
+
139
+ - 僅適用於台語閱讀理解任務
140
+ - 需要特定的 prompt 格式(USER: ... ASSISTANT:)
141
+ - 繼承 Taiwan-LLM-7B 的所有限制
142
+ - 對於非台語文本可能表現不佳
143
+
144
+ ## 📄 授權
145
+
146
+ Apache 2.0
147
+
148
+ ## 🙏 致謝
149
+
150
+ - 基礎模型: [Taiwan-LLM](https://huggingface.co/yentinglin/Taiwan-LLM-7B-v2.1-chat)
151
+ - 訓練框架: [Unsloth](https://github.com/unslothai/unsloth)
adapter_config.json ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "alora_invocation_tokens": null,
3
+ "alpha_pattern": {},
4
+ "arrow_config": null,
5
+ "auto_mapping": {
6
+ "base_model_class": "LlamaForCausalLM",
7
+ "parent_library": "transformers.models.llama.modeling_llama",
8
+ "unsloth_fixed": true
9
+ },
10
+ "base_model_name_or_path": "yentinglin/Taiwan-LLM-7B-v2.1-chat",
11
+ "bias": "none",
12
+ "corda_config": null,
13
+ "ensure_weight_tying": false,
14
+ "eva_config": null,
15
+ "exclude_modules": null,
16
+ "fan_in_fan_out": false,
17
+ "inference_mode": true,
18
+ "init_lora_weights": true,
19
+ "layer_replication": null,
20
+ "layers_pattern": null,
21
+ "layers_to_transform": null,
22
+ "loftq_config": {},
23
+ "lora_alpha": 32,
24
+ "lora_bias": false,
25
+ "lora_dropout": 0.05,
26
+ "megatron_config": null,
27
+ "megatron_core": "megatron.core",
28
+ "modules_to_save": null,
29
+ "peft_type": "LORA",
30
+ "peft_version": "0.18.0",
31
+ "qalora_group_size": 16,
32
+ "r": 32,
33
+ "rank_pattern": {},
34
+ "revision": null,
35
+ "target_modules": [
36
+ "o_proj",
37
+ "gate_proj",
38
+ "v_proj",
39
+ "up_proj",
40
+ "q_proj",
41
+ "k_proj",
42
+ "down_proj"
43
+ ],
44
+ "target_parameters": null,
45
+ "task_type": "CAUSAL_LM",
46
+ "trainable_token_indices": null,
47
+ "use_dora": false,
48
+ "use_qalora": false,
49
+ "use_rslora": false
50
+ }
adapter_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4edf1e8fba0510ad016b088922193585060e59e5a2bb1149728ad4fa55008117
3
+ size 319876032
chat_template.jinja ADDED
@@ -0,0 +1 @@
 
 
1
+ {% if not add_generation_prompt is defined %}{% set add_generation_prompt = false %}{% endif %}{% if messages[0]['role'] == 'system' %}{% set loop_messages = messages[1:] %}{% set system_message = messages[0]['content'].strip() %}{% else %}{% set loop_messages = messages %}{% set system_message = '你是人工智慧助理,以下是用戶和人工智能助理之間的對話。你要對用戶的問題提供有用、安全、詳細和禮貌的回答。' %}{% endif %}{{system_message + eos_token}}{% for message in loop_messages %}{% if message['role'] == 'user' %}USER: {{ message['content'].strip() + eos_token }}{% elif message['role'] == 'system' %}{{message['content'].strip() + eos_token}}{% elif message['role'] == 'assistant' %}ASSISTANT: {{ message['content'].strip() + eos_token }}{% endif %}{% endfor %}{% if add_generation_prompt %}{{'ASSISTANT:'}}{% endif %}
special_tokens_map.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": {
3
+ "content": "<s>",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "eos_token": {
10
+ "content": "</s>",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "pad_token": {
17
+ "content": "<unk>",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ },
23
+ "unk_token": {
24
+ "content": "<unk>",
25
+ "lstrip": false,
26
+ "normalized": false,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ }
30
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9e556afd44213b6bd1be2b850ebbbd98f5481437a8021afaf58ee7fb1818d347
3
+ size 499723
tokenizer_config.json ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": true,
3
+ "add_eos_token": false,
4
+ "add_prefix_space": null,
5
+ "added_tokens_decoder": {
6
+ "0": {
7
+ "content": "<unk>",
8
+ "lstrip": false,
9
+ "normalized": false,
10
+ "rstrip": false,
11
+ "single_word": false,
12
+ "special": true
13
+ },
14
+ "1": {
15
+ "content": "<s>",
16
+ "lstrip": false,
17
+ "normalized": false,
18
+ "rstrip": false,
19
+ "single_word": false,
20
+ "special": true
21
+ },
22
+ "2": {
23
+ "content": "</s>",
24
+ "lstrip": false,
25
+ "normalized": false,
26
+ "rstrip": false,
27
+ "single_word": false,
28
+ "special": true
29
+ }
30
+ },
31
+ "bos_token": "<s>",
32
+ "clean_up_tokenization_spaces": false,
33
+ "eos_token": "</s>",
34
+ "extra_special_tokens": {},
35
+ "legacy": false,
36
+ "model_max_length": 4096,
37
+ "pad_token": "<unk>",
38
+ "padding_side": "left",
39
+ "sp_model_kwargs": {},
40
+ "spaces_between_special_tokens": false,
41
+ "tokenizer_class": "LlamaTokenizer",
42
+ "unk_token": "<unk>",
43
+ "use_default_system_prompt": true
44
+ }