xczou commited on
Commit
a83e2a4
·
verified ·
1 Parent(s): f57d8fe

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,158 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: Qwen/Qwen2.5-7B-Instruct
3
+ datasets:
4
+ - FinLang/investopedia-instruction-tuning-dataset
5
+ language:
6
+ - en
7
+ library_name: peft
8
+ pipeline_tag: text-generation
9
+ tags:
10
+ - finance
11
+ - lora
12
+ - qwen2.5
13
+ - instruction-tuning
14
+ - investopedia
15
+ license: apache-2.0
16
+ model-index:
17
+ - name: Qwen2.5-7B Financial LoRA
18
+ results:
19
+ - task:
20
+ type: text-generation
21
+ name: Text Generation
22
+ dataset:
23
+ name: investopedia-instruction-tuning-dataset
24
+ type: FinLang/investopedia-instruction-tuning-dataset
25
+ split: test
26
+ metrics:
27
+ - type: perplexity
28
+ value: 3.33
29
+ name: Perplexity
30
+ - type: bertscore
31
+ value: 0.8986
32
+ name: BERTScore F1
33
+ ---
34
+
35
+ # Qwen2.5-7B Financial LoRA Adapter
36
+
37
+ A LoRA adapter fine-tuned on top of [Qwen/Qwen2.5-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-7B-Instruct) for financial question answering and explanation tasks. Trained on the full [Investopedia instruction-tuning dataset](https://huggingface.co/datasets/FinLang/investopedia-instruction-tuning-dataset) (206K examples, 1 epoch).
38
+
39
+ ## Model Details
40
+
41
+ - **Base model:** Qwen/Qwen2.5-7B-Instruct
42
+ - **Fine-tuning method:** LoRA (PEFT)
43
+ - **Training dataset:** FinLang/investopedia-instruction-tuning-dataset (206,000 examples)
44
+ - **Task:** Financial Q&A and instruction following
45
+ - **Language:** English
46
+ - **License:** Apache 2.0
47
+
48
+ ### LoRA Configuration
49
+
50
+ | Parameter | Value |
51
+ |-----------|-------|
52
+ | Rank (r) | 16 |
53
+ | Alpha | 32 |
54
+ | Dropout | 0 |
55
+ | Target modules | q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj |
56
+ | Bias | none |
57
+
58
+ ### Training Hyperparameters
59
+
60
+ | Parameter | Value |
61
+ |-----------|-------|
62
+ | Learning rate | 2e-4 |
63
+ | Batch size (per device) | 1 |
64
+ | Gradient accumulation steps | 8 |
65
+ | Effective batch size | 8 |
66
+ | Epochs | 1 |
67
+ | Optimizer | adamw_8bit |
68
+ | LR scheduler | linear |
69
+ | Precision | bf16 |
70
+ | Quantization | 4-bit (NF4) |
71
+ | Hardware | Kaggle T4 GPU (x1) |
72
+ | Training time | ~24 hours |
73
+
74
+ ## Usage
75
+
76
+ ```python
77
+ import torch
78
+ from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
79
+ from peft import PeftModel
80
+
81
+ base_model_id = "Qwen/Qwen2.5-7B-Instruct"
82
+ adapter_id = "xczou/qwen2.5-7b-financial-lora"
83
+
84
+ bnb_config = BitsAndBytesConfig(
85
+ load_in_4bit=True,
86
+ bnb_4bit_compute_dtype=torch.float16,
87
+ bnb_4bit_use_double_quant=True,
88
+ bnb_4bit_quant_type="nf4",
89
+ )
90
+
91
+ tokenizer = AutoTokenizer.from_pretrained(base_model_id, trust_remote_code=True)
92
+ base_model = AutoModelForCausalLM.from_pretrained(
93
+ base_model_id,
94
+ quantization_config=bnb_config,
95
+ device_map="auto",
96
+ trust_remote_code=True,
97
+ )
98
+
99
+ model = PeftModel.from_pretrained(base_model, adapter_id)
100
+ model.eval()
101
+
102
+ def ask(question, max_new_tokens=300):
103
+ prompt = (
104
+ f"<|im_start|>system\nYou are a financial expert.<|im_end|>\n"
105
+ f"<|im_start|>user\n{question}<|im_end|>\n"
106
+ f"<|im_start|>assistant\n"
107
+ )
108
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
109
+ with torch.no_grad():
110
+ outputs = model.generate(
111
+ **inputs,
112
+ max_new_tokens=max_new_tokens,
113
+ temperature=0.7,
114
+ top_p=0.9,
115
+ do_sample=True,
116
+ pad_token_id=tokenizer.eos_token_id,
117
+ )
118
+ return tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
119
+
120
+ print(ask("What is the difference between a Roth IRA and a Traditional IRA?"))
121
+ ```
122
+
123
+ ## Evaluation Results
124
+
125
+ Evaluated on the test split of `FinLang/investopedia-instruction-tuning-dataset` (100 held-out examples, never seen during training).
126
+
127
+ ### Perplexity (lower is better)
128
+
129
+ | Model | Perplexity |
130
+ |-------|-----------|
131
+ | Qwen2.5-7B-Instruct (base) | 84.80 |
132
+ | + Financial LoRA adapter | 3.33 |
133
+ | **Improvement** | **96.1%** |
134
+
135
+ ### BERTScore F1 (higher is better)
136
+
137
+ | Model | BERTScore F1 |
138
+ |-------|-------------|
139
+ | Qwen2.5-7B-Instruct (base) | 0.8373 |
140
+ | + Financial LoRA adapter | 0.8986 |
141
+ | **Improvement** | **7.3%** |
142
+
143
+ The large perplexity improvement reflects strong domain language adaptation. The BERTScore improvement reflects that generated answers are semantically closer to expert Investopedia reference answers. The base Qwen2.5-7B-Instruct model already has a high BERTScore baseline (0.8373) due to its broad pre-training, so the 7.3% gain represents meaningful domain specialization on top of an already capable model.
144
+
145
+ ## Scripts
146
+
147
+ - **Training script:** [qwenadaptertraining on Kaggle](https://www.kaggle.com/code/xczouxiaocheng/qwenadaptertraining)
148
+ - **Evaluation script:** [evaluate-qwen-financial-adapter on Kaggle](https://www.kaggle.com/code/xczouxiaocheng/evaluate-qwen-financial-adapter)
149
+
150
+ ## Training Data
151
+
152
+ Trained on [FinLang/investopedia-instruction-tuning-dataset](https://huggingface.co/datasets/FinLang/investopedia-instruction-tuning-dataset), a dataset of 206,000 financial Q&A pairs sourced from Investopedia, covering topics including stocks, bonds, ETFs, retirement accounts, derivatives, personal finance, and macroeconomics.
153
+
154
+ ## Limitations
155
+
156
+ - Responses reflect Investopedia's editorial style and may not cover all financial topics equally
157
+ - Not suitable for real-time financial data or market predictions
158
+ - Should not be used as a substitute for professional financial advice
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": "Qwen2ForCausalLM",
7
+ "parent_library": "transformers.models.qwen2.modeling_qwen2",
8
+ "unsloth_fixed": true
9
+ },
10
+ "base_model_name_or_path": "unsloth/qwen2.5-7b-instruct-unsloth-bnb-4bit",
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,
26
+ "megatron_config": null,
27
+ "megatron_core": "megatron.core",
28
+ "modules_to_save": null,
29
+ "peft_type": "LORA",
30
+ "peft_version": "0.18.1",
31
+ "qalora_group_size": 16,
32
+ "r": 16,
33
+ "rank_pattern": {},
34
+ "revision": null,
35
+ "target_modules": [
36
+ "q_proj",
37
+ "k_proj",
38
+ "o_proj",
39
+ "down_proj",
40
+ "gate_proj",
41
+ "up_proj",
42
+ "v_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:16cea635bcea002bb89dc4ff9af218c04e0c8a78bdf003e202c1cfdce18e7a40
3
+ size 161533192
chat_template.jinja ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {%- if tools %}
2
+ {{- '<|im_start|>system\n' }}
3
+ {%- if messages[0]['role'] == 'system' %}
4
+ {{- messages[0]['content'] }}
5
+ {%- else %}
6
+ {{- 'You are Qwen, created by Alibaba Cloud. You are a helpful assistant.' }}
7
+ {%- endif %}
8
+ {{- "\n\n# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }}
9
+ {%- for tool in tools %}
10
+ {{- "\n" }}
11
+ {{- tool | tojson }}
12
+ {%- endfor %}
13
+ {{- "\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call><|im_end|>\n" }}
14
+ {%- else %}
15
+ {%- if messages[0]['role'] == 'system' %}
16
+ {{- '<|im_start|>system\n' + messages[0]['content'] + '<|im_end|>\n' }}
17
+ {%- else %}
18
+ {{- '<|im_start|>system\nYou are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>\n' }}
19
+ {%- endif %}
20
+ {%- endif %}
21
+ {%- for message in messages %}
22
+ {%- if (message.role == "user") or (message.role == "system" and not loop.first) or (message.role == "assistant" and not message.tool_calls) %}
23
+ {{- '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>' + '\n' }}
24
+ {%- elif message.role == "assistant" %}
25
+ {{- '<|im_start|>' + message.role }}
26
+ {%- if message.content %}
27
+ {{- '\n' + message.content }}
28
+ {%- endif %}
29
+ {%- for tool_call in message.tool_calls %}
30
+ {%- if tool_call.function is defined %}
31
+ {%- set tool_call = tool_call.function %}
32
+ {%- endif %}
33
+ {{- '\n<tool_call>\n{"name": "' }}
34
+ {{- tool_call.name }}
35
+ {{- '", "arguments": ' }}
36
+ {{- tool_call.arguments | tojson }}
37
+ {{- '}\n</tool_call>' }}
38
+ {%- endfor %}
39
+ {{- '<|im_end|>\n' }}
40
+ {%- elif message.role == "tool" %}
41
+ {%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != "tool") %}
42
+ {{- '<|im_start|>user' }}
43
+ {%- endif %}
44
+ {{- '\n<tool_response>\n' }}
45
+ {{- message.content }}
46
+ {{- '\n</tool_response>' }}
47
+ {%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
48
+ {{- '<|im_end|>\n' }}
49
+ {%- endif %}
50
+ {%- endif %}
51
+ {%- endfor %}
52
+ {%- if add_generation_prompt %}
53
+ {{- '<|im_start|>assistant\n' }}
54
+ {%- endif %}
dataset-metadata.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "title": "Financial Qwen Adapter",
3
+ "id": "xczouxiaocheng/financial-qwen-adapter",
4
+ "licenses": [
5
+ {
6
+ "name": "CC0-1.0"
7
+ }
8
+ ]
9
+ }
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bd5948af71b4f56cf697f7580814c7ce8b80595ef985544efcacf716126a2e31
3
+ size 11422356
tokenizer_config.json ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "backend": "tokenizers",
4
+ "bos_token": null,
5
+ "clean_up_tokenization_spaces": false,
6
+ "eos_token": "<|im_end|>",
7
+ "errors": "replace",
8
+ "is_local": false,
9
+ "model_max_length": 32768,
10
+ "pad_token": "<|PAD_TOKEN|>",
11
+ "padding_side": "left",
12
+ "split_special_tokens": false,
13
+ "tokenizer_class": "Qwen2Tokenizer",
14
+ "unk_token": null,
15
+ "added_tokens_decoder": {
16
+ "151643": {
17
+ "content": "<|endoftext|>",
18
+ "single_word": false,
19
+ "lstrip": false,
20
+ "rstrip": false,
21
+ "normalized": false,
22
+ "special": true
23
+ },
24
+ "151644": {
25
+ "content": "<|im_start|>",
26
+ "single_word": false,
27
+ "lstrip": false,
28
+ "rstrip": false,
29
+ "normalized": false,
30
+ "special": true
31
+ },
32
+ "151645": {
33
+ "content": "<|im_end|>",
34
+ "single_word": false,
35
+ "lstrip": false,
36
+ "rstrip": false,
37
+ "normalized": false,
38
+ "special": true
39
+ },
40
+ "151646": {
41
+ "content": "<|object_ref_start|>",
42
+ "single_word": false,
43
+ "lstrip": false,
44
+ "rstrip": false,
45
+ "normalized": false,
46
+ "special": true
47
+ },
48
+ "151647": {
49
+ "content": "<|object_ref_end|>",
50
+ "single_word": false,
51
+ "lstrip": false,
52
+ "rstrip": false,
53
+ "normalized": false,
54
+ "special": true
55
+ },
56
+ "151648": {
57
+ "content": "<|box_start|>",
58
+ "single_word": false,
59
+ "lstrip": false,
60
+ "rstrip": false,
61
+ "normalized": false,
62
+ "special": true
63
+ },
64
+ "151649": {
65
+ "content": "<|box_end|>",
66
+ "single_word": false,
67
+ "lstrip": false,
68
+ "rstrip": false,
69
+ "normalized": false,
70
+ "special": true
71
+ },
72
+ "151650": {
73
+ "content": "<|quad_start|>",
74
+ "single_word": false,
75
+ "lstrip": false,
76
+ "rstrip": false,
77
+ "normalized": false,
78
+ "special": true
79
+ },
80
+ "151651": {
81
+ "content": "<|quad_end|>",
82
+ "single_word": false,
83
+ "lstrip": false,
84
+ "rstrip": false,
85
+ "normalized": false,
86
+ "special": true
87
+ },
88
+ "151652": {
89
+ "content": "<|vision_start|>",
90
+ "single_word": false,
91
+ "lstrip": false,
92
+ "rstrip": false,
93
+ "normalized": false,
94
+ "special": true
95
+ },
96
+ "151653": {
97
+ "content": "<|vision_end|>",
98
+ "single_word": false,
99
+ "lstrip": false,
100
+ "rstrip": false,
101
+ "normalized": false,
102
+ "special": true
103
+ },
104
+ "151654": {
105
+ "content": "<|vision_pad|>",
106
+ "single_word": false,
107
+ "lstrip": false,
108
+ "rstrip": false,
109
+ "normalized": false,
110
+ "special": true
111
+ },
112
+ "151655": {
113
+ "content": "<|image_pad|>",
114
+ "single_word": false,
115
+ "lstrip": false,
116
+ "rstrip": false,
117
+ "normalized": false,
118
+ "special": true
119
+ },
120
+ "151656": {
121
+ "content": "<|video_pad|>",
122
+ "single_word": false,
123
+ "lstrip": false,
124
+ "rstrip": false,
125
+ "normalized": false,
126
+ "special": true
127
+ },
128
+ "151657": {
129
+ "content": "<tool_call>",
130
+ "single_word": false,
131
+ "lstrip": false,
132
+ "rstrip": false,
133
+ "normalized": false,
134
+ "special": false
135
+ },
136
+ "151658": {
137
+ "content": "</tool_call>",
138
+ "single_word": false,
139
+ "lstrip": false,
140
+ "rstrip": false,
141
+ "normalized": false,
142
+ "special": false
143
+ },
144
+ "151659": {
145
+ "content": "<|fim_prefix|>",
146
+ "single_word": false,
147
+ "lstrip": false,
148
+ "rstrip": false,
149
+ "normalized": false,
150
+ "special": false
151
+ },
152
+ "151660": {
153
+ "content": "<|fim_middle|>",
154
+ "single_word": false,
155
+ "lstrip": false,
156
+ "rstrip": false,
157
+ "normalized": false,
158
+ "special": false
159
+ },
160
+ "151661": {
161
+ "content": "<|fim_suffix|>",
162
+ "single_word": false,
163
+ "lstrip": false,
164
+ "rstrip": false,
165
+ "normalized": false,
166
+ "special": false
167
+ },
168
+ "151662": {
169
+ "content": "<|fim_pad|>",
170
+ "single_word": false,
171
+ "lstrip": false,
172
+ "rstrip": false,
173
+ "normalized": false,
174
+ "special": false
175
+ },
176
+ "151663": {
177
+ "content": "<|repo_name|>",
178
+ "single_word": false,
179
+ "lstrip": false,
180
+ "rstrip": false,
181
+ "normalized": false,
182
+ "special": false
183
+ },
184
+ "151664": {
185
+ "content": "<|file_sep|>",
186
+ "single_word": false,
187
+ "lstrip": false,
188
+ "rstrip": false,
189
+ "normalized": false,
190
+ "special": false
191
+ },
192
+ "151665": {
193
+ "content": "<|PAD_TOKEN|>",
194
+ "single_word": false,
195
+ "lstrip": false,
196
+ "rstrip": false,
197
+ "normalized": false,
198
+ "special": true
199
+ }
200
+ }
201
+ }