Commit
•
e0fa1a3
1
Parent(s):
561d262
Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,154 @@
|
|
1 |
---
|
2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
title: chinese-alpaca-plus-7b
|
3 |
+
emoji: 📚
|
4 |
+
colorFrom: gray
|
5 |
+
colorTo: red
|
6 |
+
language:
|
7 |
+
- zh
|
8 |
+
tags:
|
9 |
+
- chatglm
|
10 |
+
- pytorch
|
11 |
+
- zh
|
12 |
+
- Text2Text-Generation
|
13 |
+
license: "other"
|
14 |
+
widget:
|
15 |
+
- text: "为什么天空是蓝色的?"
|
16 |
---
|
17 |
+
|
18 |
+
# Chinese Alpaca Plus 7B Model
|
19 |
+
|
20 |
+
**发布中文LLaMA, Alpaca Plus版(7B)**
|
21 |
+
推出中文LLaMA, Alpaca Plus版(7B),相比基础版本的改进点如下:
|
22 |
+
|
23 |
+
- 进一步扩充了训练数据,其中LLaMA扩充至120G文本(通用领域),Alpaca扩充至4M指令数据(重点增加了STEM相关数据)
|
24 |
+
- Alpaca训练时采用了更大的rank,相比原版具有更低的验证集损失
|
25 |
+
- 评测结果显示,Alpaca-Plus-7B相比基础版Alpaca-7B效果更优,部分任务接近或超过13B版本
|
26 |
+
- 这一轮比拼:7B获得65.3分,13B获得70.9分,Plus-7B效果75.3分,具体评测结果请参考[效果评测](https://github.com/ymcui/Chinese-LLaMA-Alpaca/blob/main/examples/README.md)
|
27 |
+
|
28 |
+
本模型是合并了`原生LLaMA-7B`和`中文Alpaca LoRA`后的模型权重,可以直接使用或者继续训练。
|
29 |
+
|
30 |
+
|
31 |
+
test case:
|
32 |
+
|input_text|predict|
|
33 |
+
|:-- |:--- |
|
34 |
+
|为什么天空是蓝色的?|天空是蓝色的,是因为大气层中的气体分子会散射太阳光中的蓝色光,使得我们看到的天空是蓝色的。|
|
35 |
+
|
36 |
+
|
37 |
+
## Usage
|
38 |
+
|
39 |
+
本项目开源在textgen项目:[textgen](https://github.com/shibing624/textgen),可支持llama模型,通过如下命令调用:
|
40 |
+
|
41 |
+
Install package:
|
42 |
+
```shell
|
43 |
+
pip install -U textgen
|
44 |
+
```
|
45 |
+
|
46 |
+
```python
|
47 |
+
from textgen import LlamaModel
|
48 |
+
model = LlamaModel("llama", "shibing624/chinese-alpaca-plus-7b")
|
49 |
+
r = model.predict(["用一句话描述地球为什么是独一无二的。"])
|
50 |
+
print(r) # ['地球是独一无二的,因为它拥有独特的大气层、水循环、生物多样性以及其他自然资源,这些都使它成为一个独特的生命支持系统。']
|
51 |
+
```
|
52 |
+
|
53 |
+
## Usage (HuggingFace Transformers)
|
54 |
+
Without [textgen](https://github.com/shibing624/textgen), you can use the model like this:
|
55 |
+
|
56 |
+
First, you pass your input through the transformer model, then you get the generated sentence.
|
57 |
+
|
58 |
+
Install package:
|
59 |
+
```
|
60 |
+
pip install sentencepiece
|
61 |
+
pip install transformers>=4.28.0
|
62 |
+
```
|
63 |
+
|
64 |
+
```python
|
65 |
+
import torch
|
66 |
+
import transformers
|
67 |
+
from transformers import LlamaTokenizer, LlamaForCausalLM
|
68 |
+
|
69 |
+
def generate_prompt(text):
|
70 |
+
return f"""Below is an instruction that describes a task. Write a response that appropriately completes the request.
|
71 |
+
|
72 |
+
### Instruction:
|
73 |
+
{text}
|
74 |
+
|
75 |
+
### Response:"""
|
76 |
+
|
77 |
+
|
78 |
+
tokenizer = LlamaTokenizer.from_pretrained('shibing624/chinese-alpaca-plus-7b')
|
79 |
+
model = LlamaForCausalLM.from_pretrained('shibing624/chinese-alpaca-plus-7b').half().cuda()
|
80 |
+
model.eval()
|
81 |
+
|
82 |
+
text = '为什么天空是蓝色的?'
|
83 |
+
prompt = generate_prompt(text)
|
84 |
+
input_ids = tokenizer.encode(prompt, return_tensors='pt').to('cuda')
|
85 |
+
|
86 |
+
|
87 |
+
with torch.no_grad():
|
88 |
+
output_ids = model.generate(
|
89 |
+
input_ids=input_ids,
|
90 |
+
max_new_tokens=128,
|
91 |
+
temperature=1,
|
92 |
+
top_k=40,
|
93 |
+
top_p=0.9,
|
94 |
+
repetition_penalty=1.15
|
95 |
+
).cuda()
|
96 |
+
output = tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
97 |
+
print(output.replace(text, '').strip())
|
98 |
+
```
|
99 |
+
|
100 |
+
|
101 |
+
output:
|
102 |
+
```shell
|
103 |
+
为什么天空是蓝色的?
|
104 |
+
天空是蓝色的,是因为大气层中的气体分子会散射太阳光中的蓝色光,使得我们看到的天空是蓝色的。
|
105 |
+
```
|
106 |
+
|
107 |
+
## 模型来源
|
108 |
+
|
109 |
+
基于 [多LoRA权重合并(适用于Chinese-Alpaca-Plus )](https://github.com/ymcui/Chinese-LLaMA-Alpaca/wiki/%E6%89%8B%E5%8A%A8%E6%A8%A1%E5%9E%8B%E5%90%88%E5%B9%B6%E4%B8%8E%E8%BD%AC%E6%8D%A2#%E5%A4%9Alora%E6%9D%83%E9%87%8D%E5%90%88%E5%B9%B6%E9%80%82%E7%94%A8%E4%BA%8Echinese-alpaca-plus-)方法手动合并而成,具体是使用 [decapoda-research/llama-7b-hf](https://huggingface.co/decapoda-research/llama-7b-hf) 底座模型 合并 Chinese-LLaMA-Plus-LoRA和Chinese-Alpaca-Plus-LoRA 两个LoRA权重 得到,并转化为HuggingFace版本权重(.bin文件)。
|
110 |
+
|
111 |
+
release合并后的模型权重,一次到位直接使用,省电、减少碳排放。
|
112 |
+
|
113 |
+
|
114 |
+
模型文件组成:
|
115 |
+
```
|
116 |
+
chinese-alpaca-plus-7b
|
117 |
+
config.json
|
118 |
+
generation_config.json
|
119 |
+
pytorch_model-00001-of-00002.bin
|
120 |
+
pytorch_model-00002-of-00002.bin
|
121 |
+
pytorch_model.bin.index.json
|
122 |
+
special_tokens_map.json
|
123 |
+
tokenizer.json
|
124 |
+
tokenizer.model
|
125 |
+
tokenizer_config.json
|
126 |
+
```
|
127 |
+
|
128 |
+
|
129 |
+
### 训练数据集
|
130 |
+
|
131 |
+
1. 50万条中文ChatGPT指令Belle数据集:[BelleGroup/train_0.5M_CN](https://huggingface.co/datasets/BelleGroup/train_0.5M_CN)
|
132 |
+
2. 100万条中文ChatGPT指令Belle数据集:[BelleGroup/train_1M_CN](https://huggingface.co/datasets/BelleGroup/train_1M_CN)
|
133 |
+
3. 5万条英文ChatGPT指令Alpaca数据集:[50k English Stanford Alpaca dataset](https://github.com/tatsu-lab/stanford_alpaca#data-release)
|
134 |
+
4. 2万条中文ChatGPT指令Alpaca数据集:[shibing624/alpaca-zh](https://huggingface.co/datasets/shibing624/alpaca-zh)
|
135 |
+
5. 69万条中文指令Guanaco数据集(Belle50万条+Guanaco19万条):[Chinese-Vicuna/guanaco_belle_merge_v1.0](https://huggingface.co/datasets/Chinese-Vicuna/guanaco_belle_merge_v1.0)
|
136 |
+
|
137 |
+
|
138 |
+
如果需要训练LLAMA模型,请参考[https://github.com/shibing624/textgen](https://github.com/shibing624/textgen)
|
139 |
+
|
140 |
+
|
141 |
+
## Citation
|
142 |
+
|
143 |
+
```latex
|
144 |
+
@software{textgen,
|
145 |
+
author = {Xu Ming},
|
146 |
+
title = {textgen: Implementation of language model finetune},
|
147 |
+
year = {2023},
|
148 |
+
url = {https://github.com/shibing624/textgen},
|
149 |
+
}
|
150 |
+
```
|
151 |
+
|
152 |
+
|
153 |
+
## Reference
|
154 |
+
- https://github.com/ymcui/Chinese-LLaMA-Alpaca
|