GaryYang123 commited on
Commit
6c3fe38
·
verified ·
1 Parent(s): c30b438

Initial release: Meme culture trained Qwen model

Browse files
README.md ADDED
@@ -0,0 +1,189 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - zh
4
+ license: mit
5
+ tags:
6
+ - lora
7
+ - qwen2.5
8
+ - chinese
9
+ - sarcastic
10
+ - humor
11
+ library_name: peft
12
+ base_model: Qwen/Qwen2.5-7B-Instruct
13
+ ---
14
+
15
+ # GaryYang123/Meme-Qwen-7B-Instruct
16
+
17
+ 一个基于 Qwen2.5-7B 微调的幽默风趣中文对话模型(LoRA)
18
+
19
+ ## 模型简介
20
+
21
+ 这是一个使用 LoRA 方法微调的对话模型,专注于生成幽默、机智、略带调侃风格的中文回复。
22
+
23
+ ### 特点
24
+ - 💡 轻量级:仅 LoRA 权重(~200MB),需配合基座模型使用
25
+ - 🎭 风格化:幽默风趣,带有"阴阳怪气"的特色
26
+ - 🚀 高效:推理速度快,显存占用低
27
+ - 📊 质量:基于7,800+条精选对话数据训练
28
+
29
+ ## 快速使用
30
+
31
+ ### 安装依赖
32
+ ```bash
33
+ pip install transformers>=4.37.0 peft>=0.8.0 torch>=2.0.0
34
+ ```
35
+
36
+ ### 推理代码
37
+ ```python
38
+ import torch
39
+ from transformers import AutoTokenizer, AutoModelForCausalLM
40
+ from peft import PeftModel
41
+
42
+ # 加载模型
43
+ base_model = "Qwen/Qwen2.5-7B-Instruct"
44
+ lora_model = "GaryYang123/Meme-Qwen-7B-Instruct" # 你的 HF 路径
45
+
46
+ tokenizer = AutoTokenizer.from_pretrained(base_model, trust_remote_code=True)
47
+ model = AutoModelForCausalLM.from_pretrained(
48
+ base_model,
49
+ torch_dtype=torch.bfloat16,
50
+ device_map="auto",
51
+ trust_remote_code=True
52
+ )
53
+
54
+ # 加载 LoRA 权重
55
+ model = PeftModel.from_pretrained(model, lora_model)
56
+ model.eval()
57
+
58
+ # 对话函数
59
+ def chat(user_input):
60
+ messages = [
61
+ {"role": "system", "content": "你是一个幽默风趣的助手。"},
62
+ {"role": "user", "content": user_input}
63
+ ]
64
+
65
+ text = tokenizer.apply_chat_template(
66
+ messages, tokenize=False, add_generation_prompt=True
67
+ )
68
+ inputs = tokenizer(text, return_tensors="pt").to(model.device)
69
+
70
+ with torch.no_grad():
71
+ outputs = model.generate(
72
+ **inputs,
73
+ max_new_tokens=256,
74
+ temperature=0.7,
75
+ top_p=0.9,
76
+ do_sample=True,
77
+ )
78
+
79
+ response = tokenizer.decode(
80
+ outputs[0][inputs.input_ids.shape[1]:],
81
+ skip_special_tokens=True
82
+ )
83
+ return response.strip()
84
+
85
+ # 测试
86
+ print(chat("今天天气真好"))
87
+ ```
88
+
89
+ ## 训练细节
90
+
91
+ ### 数据集
92
+ - **来源**: Zhihu-KOL + 自定义高质量对话
93
+ - **规模**: 7,800+ 条对话
94
+ - **处理**: 长度过滤、关键词清洗、去重、打乱
95
+
96
+ ### 训练配置
97
+ ```yaml
98
+ 基座模型: Qwen/Qwen2.5-7B-Instruct
99
+ 方法: LoRA (Low-Rank Adaptation)
100
+
101
+ LoRA 参数:
102
+ rank: 16
103
+ alpha: 32
104
+ dropout: 0.05
105
+ target_modules: [q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj]
106
+
107
+ 训练参数:
108
+ learning_rate: 1e-4
109
+ batch_size: 8 (4 per_device × 2 gradient_accumulation)
110
+ epochs: 3
111
+ max_length: 512
112
+ warmup_ratio: 0.05
113
+ optimizer: AdamW
114
+ scheduler: cosine
115
+
116
+ 硬件: 1× NVIDIA A100 (40GB)
117
+ 训练时长: ~56 分钟
118
+ 可训练参数: 40.37M (0.53%)
119
+ ```
120
+
121
+ ### 性能指标
122
+ | 指标 | 数值 |
123
+ |------|------|
124
+ | 训练 Loss (final) | 0.8 |
125
+ | 验证 Loss (final) | 0.9 |
126
+ | 训练集 | 7,017 条 |
127
+ | 验证集 | 868 条 |
128
+ | 测试集 | 868 条 |
129
+
130
+ ## 样例展示
131
+
132
+ ### 示例 1
133
+ **用户**: 今天加班到很晚,好累啊
134
+ **模型**: 哎呀,这么努力,老板知道吗?知道的话会不会感动得给你再加点活儿?😏 不过玩笑归玩笑,身体才是革命的本钱,早点休息吧~
135
+
136
+ ### 示例 2
137
+ **用户**: 我的代码又出bug了
138
+ **模型**: 欢迎来到程序员的日常,bug 不找你,你都不好意思说自己在写代码😂 冷静分析,肯定能解决的!
139
+
140
+ ### 示例 3
141
+ **用户**: 感觉自己最近进步很慢
142
+ **模型**: 慢就对了,说明你在扎实前进啊!要是进步飞快,那可能是错觉哦~ 脚踏实地才是王道!
143
+
144
+ ## 适用场景
145
+
146
+ ✅ **推荐使用**:
147
+ - 休闲聊天机器人
148
+ - 社交媒体自动回复
149
+ - 娱乐向对话应用
150
+ - 需要幽默感的场景
151
+
152
+ ❌ **不推荐使用**:
153
+ - 正式商务沟通
154
+ - 专业咨询服务
155
+ - 客户服务场景
156
+ - 敏感话题讨论
157
+
158
+ ## 使用限制
159
+
160
+ 本模型为研究和娱乐用途,生成内容可能带有调侃、讽刺意味。请在合适的场景下使用,并对输出内容进行必要的审查。
161
+
162
+ ## 致谢
163
+
164
+ - **基座模型**: [Qwen2.5-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-7B-Instruct) by Alibaba Cloud
165
+ - **数据集**: [Zhihu-KOL](https://huggingface.co/datasets/wangrui6/Zhihu-KOL)
166
+ - **框架**: Hugging Face Transformers & PEFT
167
+
168
+ ## 许可证
169
+
170
+ 本项目采用 MIT License。基座模型遵循 Qwen 原始许可证。
171
+
172
+ ## 引用
173
+
174
+ 如果使用本模型,请引用:
175
+ ```bibtex
176
+ @misc{qwen-sarcastic-lora,
177
+ author = {Your Name},
178
+ title = {Qwen2.5 Sarcastic LoRA: A Humorous Chinese Dialog Model},
179
+ year = {2024},
180
+ publisher = {Hugging Face},
181
+ howpublished = {\url{https://huggingface.co/GaryYang123/Meme-Qwen-7B-Instruct}}
182
+ }
183
+ ```
184
+
185
+ ---
186
+
187
+ **更新日期**: 2024-03
188
+ **维护者**: [你的名字]
189
+ **联系方式**: [你的邮箱或GitHub]
adapter_config.json ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "alora_invocation_tokens": null,
3
+ "alpha_pattern": {},
4
+ "arrow_config": null,
5
+ "auto_mapping": null,
6
+ "base_model_name_or_path": "Qwen/Qwen2.5-7B-Instruct",
7
+ "bias": "none",
8
+ "corda_config": null,
9
+ "ensure_weight_tying": false,
10
+ "eva_config": null,
11
+ "exclude_modules": null,
12
+ "fan_in_fan_out": false,
13
+ "inference_mode": true,
14
+ "init_lora_weights": true,
15
+ "layer_replication": null,
16
+ "layers_pattern": null,
17
+ "layers_to_transform": null,
18
+ "loftq_config": {},
19
+ "lora_alpha": 32,
20
+ "lora_bias": false,
21
+ "lora_dropout": 0.05,
22
+ "megatron_config": null,
23
+ "megatron_core": "megatron.core",
24
+ "modules_to_save": null,
25
+ "peft_type": "LORA",
26
+ "peft_version": "0.18.1",
27
+ "qalora_group_size": 16,
28
+ "r": 16,
29
+ "rank_pattern": {},
30
+ "revision": null,
31
+ "target_modules": [
32
+ "up_proj",
33
+ "o_proj",
34
+ "gate_proj",
35
+ "v_proj",
36
+ "q_proj",
37
+ "k_proj",
38
+ "down_proj"
39
+ ],
40
+ "target_parameters": null,
41
+ "task_type": "CAUSAL_LM",
42
+ "trainable_token_indices": null,
43
+ "use_dora": false,
44
+ "use_qalora": false,
45
+ "use_rslora": false
46
+ }
adapter_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:aca8fd92ad0fc82f87fe2d942afb8f6df3e520f03622a93630e63967306003b7
3
+ size 161533192
tokenizer_config.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ "extra_special_tokens": [
9
+ "<|im_start|>",
10
+ "<|im_end|>",
11
+ "<|object_ref_start|>",
12
+ "<|object_ref_end|>",
13
+ "<|box_start|>",
14
+ "<|box_end|>",
15
+ "<|quad_start|>",
16
+ "<|quad_end|>",
17
+ "<|vision_start|>",
18
+ "<|vision_end|>",
19
+ "<|vision_pad|>",
20
+ "<|image_pad|>",
21
+ "<|video_pad|>"
22
+ ],
23
+ "is_local": false,
24
+ "model_max_length": 131072,
25
+ "pad_token": "<|endoftext|>",
26
+ "padding_side": "right",
27
+ "split_special_tokens": false,
28
+ "tokenizer_class": "Qwen2Tokenizer",
29
+ "unk_token": null
30
+ }
training_info.json ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "base_model": "Qwen/Qwen2.5-7B-Instruct",
3
+ "training_method": "LoRA",
4
+ "lora_config": {
5
+ "r": 16,
6
+ "lora_alpha": 32,
7
+ "lora_dropout": 0.05,
8
+ "target_modules": [
9
+ "q_proj",
10
+ "k_proj",
11
+ "v_proj",
12
+ "o_proj",
13
+ "gate_proj",
14
+ "up_proj",
15
+ "down_proj"
16
+ ]
17
+ },
18
+ "training_params": {
19
+ "learning_rate": 0.0001,
20
+ "num_epochs": 3,
21
+ "batch_size": 8,
22
+ "gradient_accumulation_steps": 2,
23
+ "max_length": 512,
24
+ "warmup_ratio": 0.05
25
+ }
26
+ }