Update README.md
Browse filesadd english model card
README.md
CHANGED
|
@@ -10,25 +10,27 @@ tags:
|
|
| 10 |
pipeline_tag: text-generation
|
| 11 |
---
|
| 12 |
|
| 13 |
-
# Qwen-7B LoRA 微调模型(中文指令微调)
|
| 14 |
|
| 15 |
-
本模型基于阿里巴巴通义千问 Qwen-7B-Chat,采用 LoRA 技术,使用 Alpaca-Zh-51k 数据集进行中文指令微调
|
| 16 |
|
| 17 |
-
|
| 18 |
|
| 19 |
-
|
| 20 |
-
- **微调方法**:LoRA
|
| 21 |
-
- **数据集**:Alpaca-Zh-51k
|
| 22 |
-
- **训练脚本**:见仓库 `train_qwen7b_lora.py`
|
| 23 |
-
- **推理/对比脚本**:见仓库 `test_compare.py`
|
| 24 |
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
```python
|
| 28 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 29 |
from peft import PeftModel
|
| 30 |
|
| 31 |
-
# 替换为你的 Hugging Face 用户名和模型名
|
| 32 |
model_name = "Josh1207/qwen7b-alpaca-lora"
|
| 33 |
|
| 34 |
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
|
@@ -38,4 +40,42 @@ model = PeftModel.from_pretrained(base_model, model_name)
|
|
| 38 |
prompt = "指令: 请介绍一下你自己。"
|
| 39 |
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
|
| 40 |
outputs = model.generate(**inputs, max_new_tokens=512)
|
| 41 |
-
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
pipeline_tag: text-generation
|
| 11 |
---
|
| 12 |
|
| 13 |
+
# 📌 中文简介:Qwen-7B LoRA 微调模型(中文指令微调)
|
| 14 |
|
| 15 |
+
本模型基于阿里巴巴通义千问 Qwen-7B-Chat,采用 LoRA 技术,使用 Alpaca-Zh-51k 数据集进行了中文指令微调,适用于中文任务的理解与生成。
|
| 16 |
|
| 17 |
+
注: 对Chat进行微调后效果反而变差了,或许对base版本微调会好一些
|
| 18 |
|
| 19 |
+
## 🧾 模型信息
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
+
- **基座模型**:[`Qwen/Qwen-7B-Chat`](https://huggingface.co/Qwen/Qwen-7B-Chat)
|
| 22 |
+
- **微调方法**:LoRA(使用 PEFT 库)
|
| 23 |
+
- **训练数据集**:Alpaca-Zh-51k
|
| 24 |
+
- **训练脚本**:`train_qwen7b_lora.py`
|
| 25 |
+
- **推理脚本**:`test_compare.py`
|
| 26 |
+
- ⚠️ 本模型仅包含 LoRA adapter,不包含原始基座权重
|
| 27 |
+
|
| 28 |
+
## 🚀 使用示例
|
| 29 |
|
| 30 |
```python
|
| 31 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 32 |
from peft import PeftModel
|
| 33 |
|
|
|
|
| 34 |
model_name = "Josh1207/qwen7b-alpaca-lora"
|
| 35 |
|
| 36 |
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
|
|
|
| 40 |
prompt = "指令: 请介绍一下你自己。"
|
| 41 |
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
|
| 42 |
outputs = model.generate(**inputs, max_new_tokens=512)
|
| 43 |
+
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
| 44 |
+
````
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
---
|
| 48 |
+
|
| 49 |
+
# 📌 English Overview: Qwen-7B LoRA Fine-tuned Model (Chinese Instruction Tuning)
|
| 50 |
+
|
| 51 |
+
This model is fine-tuned from Alibaba’s Qwen-7B-Chat using LoRA technique on the Alpaca-Zh-51k dataset. It is suitable for instruction-following tasks in Chinese.
|
| 52 |
+
|
| 53 |
+
(I found that after making adjustments to Chat model, the effect actually got worse. Perhaps making adjustments to the base version would be better)
|
| 54 |
+
|
| 55 |
+
## 🧾 Model Information
|
| 56 |
+
|
| 57 |
+
* **Base model**: [`Qwen/Qwen-7B-Chat`](https://huggingface.co/Qwen/Qwen-7B-Chat)
|
| 58 |
+
* **Tuning method**: LoRA (via `peft`)
|
| 59 |
+
* **Dataset**: Alpaca-Zh-51k
|
| 60 |
+
* **Training script**: `train_qwen7b_lora.py`
|
| 61 |
+
* **Inference script**: `test_compare.py`
|
| 62 |
+
* ⚠️ This repository includes only LoRA adapter weights, not the original base model.
|
| 63 |
+
|
| 64 |
+
## 🚀 Usage Example
|
| 65 |
+
|
| 66 |
+
```python
|
| 67 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 68 |
+
from peft import PeftModel
|
| 69 |
+
|
| 70 |
+
model_name = "Josh1207/qwen7b-alpaca-lora"
|
| 71 |
+
|
| 72 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
| 73 |
+
base_model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen-7B-Chat", trust_remote_code=True)
|
| 74 |
+
model = PeftModel.from_pretrained(base_model, model_name)
|
| 75 |
+
|
| 76 |
+
prompt = "指令: 请介绍一下你自己。"
|
| 77 |
+
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
|
| 78 |
+
outputs = model.generate(**inputs, max_new_tokens=512)
|
| 79 |
+
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
| 80 |
+
```
|
| 81 |
+
|