File size: 4,247 Bytes
a13db05
 
 
 
 
3183010
 
 
 
 
 
 
a13db05
 
3183010
a13db05
3183010
a13db05
3183010
a13db05
3183010
 
 
 
 
a13db05
3183010
a13db05
3183010
a13db05
3183010
 
 
a13db05
3183010
a13db05
3183010
 
 
a13db05
3183010
 
 
 
 
 
a13db05
3183010
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a13db05
3183010
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
---
base_model: Qwen/Qwen2.5-0.5B-Instruct
library_name: peft
tags:
- lora
- qwen
- customer-service
- chinese
- conversational
license: mit
language:
- zh
---

# Qwen2.5-0.5B-Instruct 客服微调模型

这是一个基于 Qwen2.5-0.5B-Instruct 使用 LoRA 方法微调的客服对话模型。

## 模型详情

- **基础模型**: [Qwen/Qwen2.5-0.5B-Instruct](https://huggingface.co/Qwen/Qwen2.5-0.5B-Instruct)
- **微调方法**: LoRA (Low-Rank Adaptation)
- **参数量**: 基础模型 0.5B + LoRA 适配器 ~2MB
- **语言**: 中文
- **用途**: 客服对话、智能问答

## 使用方法

### 安装依赖

```bash
pip install transformers peft torch
```

### 加载和使用模型

```python
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel

# 加载基础模型
base_model = AutoModelForCausalLM.from_pretrained(
    "Qwen/Qwen2.5-0.5B-Instruct",
    torch_dtype="auto",
    device_map="auto"
)

# 加载 LoRA 适配器
model = PeftModel.from_pretrained(
    base_model,
    "pplboy/test"
)

# 加载分词器
tokenizer = AutoTokenizer.from_pretrained("pplboy/test")

# 使用模型
prompt = "你好,我想咨询一下产品"
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)

outputs = model.generate(
    **inputs,
    max_new_tokens=100,
    temperature=0.7,
    top_p=0.9,
    do_sample=True
)

response = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(response)
```

### 使用 Transformers Pipeline

```python
from transformers import pipeline
from peft import PeftModel, PeftConfig
from transformers import AutoModelForCausalLM, AutoTokenizer

# 加载模型
config = PeftConfig.from_pretrained("pplboy/test")
base_model = AutoModelForCausalLM.from_pretrained(
    config.base_model_name_or_path,
    torch_dtype="auto",
    device_map="auto"
)
model = PeftModel.from_pretrained(base_model, "pplboy/test")
tokenizer = AutoTokenizer.from_pretrained("pplboy/test")

# 创建 pipeline
pipe = pipeline(
    "text-generation",
    model=model,
    tokenizer=tokenizer,
    device_map="auto"
)

# 生成回复
result = pipe("你好,我想咨询一下产品", max_new_tokens=100)
print(result[0]['generated_text'])
```

## 模型信息

### LoRA 配置

- **LoRA rank (r)**: 8
- **LoRA alpha**: 16
- **LoRA dropout**: 0.1
- **Target modules**: q_proj, v_proj

### 训练信息

- **训练框架**: PEFT 0.16.0
- **训练方法**: LoRA 微调
- **基础模型**: Qwen2.5-0.5B-Instruct

## 使用场景

- 智能客服系统
- 自动问答
- 对话机器人
- 客户支持

## 限制和注意事项

1. **需要基础模型**: 这是一个 LoRA 适配器,使用前需要先加载基础模型 `Qwen/Qwen2.5-0.5B-Instruct`
2. **模型大小**: 基础模型约 1GB,LoRA 适配器约 2MB
3. **内存要求**: 建议至少 4GB 内存(使用 GPU 可减少内存占用)
4. **语言支持**: 主要支持中文,英文能力有限

## 示例

```python
# 完整示例
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel

# 加载
base_model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-0.5B-Instruct")
model = PeftModel.from_pretrained(base_model, "pplboy/test")
tokenizer = AutoTokenizer.from_pretrained("pplboy/test")

# 测试对话
conversations = [
    "你好,我想咨询一下产品",
    "这个产品有什么特点?",
    "如何退货?",
    "客服工作时间是什么时候?"
]

for prompt in conversations:
    inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
    outputs = model.generate(**inputs, max_new_tokens=100, temperature=0.7)
    response = tokenizer.decode(outputs[0], skip_special_tokens=True)
    print(f"Q: {prompt}")
    print(f"A: {response}\n")
```

## 引用

如果使用本模型,请引用:

```bibtex
@misc{pplboy-test-2024,
  title={Qwen2.5-0.5B-Instruct 客服微调模型},
  author={pplboy},
  year={2024},
  howpublished={\url{https://huggingface.co/pplboy/test}}
}
```

## 许可证

本模型基于 Qwen2.5-0.5B-Instruct,遵循 MIT 许可证。

## 相关链接

- [基础模型](https://huggingface.co/Qwen/Qwen2.5-0.5B-Instruct)
- [PEFT 文档](https://huggingface.co/docs/peft)
- [Transformers 文档](https://huggingface.co/docs/transformers)