yuanzhoulvpi
commited on
Commit
•
b9baef0
1
Parent(s):
8627837
Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,121 @@
|
|
1 |
---
|
2 |
license: bigscience-bloom-rail-1.0
|
|
|
|
|
|
|
|
|
|
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
license: bigscience-bloom-rail-1.0
|
3 |
+
datasets:
|
4 |
+
- BelleGroup/train_1M_CN
|
5 |
+
language:
|
6 |
+
- zh
|
7 |
+
library_name: transformers
|
8 |
---
|
9 |
+
|
10 |
+
## 介绍
|
11 |
+
1. ✅ 对`bloom-560m`模型做了sft,在这个数量级和模型规模下,效果非常好
|
12 |
+
2. 🚀 训练代码和推理代码全部分享,可以查看链接[https://github.com/yuanzhoulvpi2017/zero_nlp/tree/main/chinese_bloom](https://github.com/yuanzhoulvpi2017/zero_nlp/tree/main/chinese_bloom)
|
13 |
+
|
14 |
+
## 个人感受
|
15 |
+
1. `bloom`系列的模型,在中文领域,具有极大的潜力,在经过有监督微调训练之后,效果非常惊人!
|
16 |
+
2. `bloom`系列的模型,覆盖中文、英文、代码、法语、西班牙语等。即使拿来做翻译、拿来做代码生成,也都没问题!(后期将会分享相关教程)
|
17 |
+
|
18 |
+
|
19 |
+
## 如何使用
|
20 |
+
|
21 |
+
```python
|
22 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
23 |
+
|
24 |
+
|
25 |
+
checkpoint = "small_model/checkpoint-8260"#"bigscience/bloomz-3b" #"bigscience/bloom-7b1"# "output_dir/checkpoint-8260"#
|
26 |
+
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
|
27 |
+
model = AutoModelForCausalLM.from_pretrained(checkpoint)
|
28 |
+
|
29 |
+
PROMPT_DICT = {
|
30 |
+
"prompt_input": (
|
31 |
+
"Below is an instruction that describes a task, paired with an input that provides further context. "
|
32 |
+
"Write a response that appropriately completes the request.\n\n"
|
33 |
+
"### Instruction:\n{instruction}\n\n### Input:\n{input}\n\n### Response:"
|
34 |
+
),
|
35 |
+
"prompt_no_input": (
|
36 |
+
"Below is an instruction that describes a task. "
|
37 |
+
"Write a response that appropriately completes the request.\n\n"
|
38 |
+
"### Instruction:\n{instruction}\n\n### Response:"
|
39 |
+
),
|
40 |
+
}
|
41 |
+
|
42 |
+
from typing import Optional
|
43 |
+
def generate_input(instruction:Optional[str]= None, input_str:Optional[str] = None) -> str:
|
44 |
+
if input_str is None:
|
45 |
+
return PROMPT_DICT['prompt_no_input'].format_map({'instruction':instruction})
|
46 |
+
else:
|
47 |
+
return PROMPT_DICT['prompt_input'].format_map({'instruction':instruction, 'input':input_str})
|
48 |
+
|
49 |
+
|
50 |
+
for i in range(5):
|
51 |
+
print("*"*80)
|
52 |
+
|
53 |
+
inputs = tokenizer.encode(generate_input(instruction="你是谁"), return_tensors="pt")
|
54 |
+
outputs = model.generate(inputs,num_beams=3,
|
55 |
+
max_new_tokens=512,
|
56 |
+
do_sample=False,
|
57 |
+
top_k=10,
|
58 |
+
penalty_alpha=0.6,
|
59 |
+
temperature=0.8,
|
60 |
+
repetition_penalty=1.2)
|
61 |
+
print(tokenizer.decode(outputs[0]))
|
62 |
+
```
|
63 |
+
|
64 |
+
|
65 |
+
### example1
|
66 |
+
|
67 |
+
1. 训练前效果
|
68 |
+
```bash
|
69 |
+
Below is an instruction that describes a task. Write a response that appropriately completes the request.
|
70 |
+
|
71 |
+
### Instruction:
|
72 |
+
写一篇关于水杯的文章
|
73 |
+
|
74 |
+
### Response: 杯子是用来喝水用的</s>
|
75 |
+
```
|
76 |
+
|
77 |
+
2. 训练后效果
|
78 |
+
```bash
|
79 |
+
Below is an instruction that describes a task. Write a response that appropriately completes the request.
|
80 |
+
|
81 |
+
### Instruction:
|
82 |
+
写一篇关于水杯的文章
|
83 |
+
|
84 |
+
### Response:
|
85 |
+
水杯是人们日常生活中必不可少的物品之一,它能够帮助人们盛放、储存和运输水。以下是一些有关水杯的详细信息:
|
86 |
+
1. 形状:水杯通常有圆形、方形、长方形等不同形状。
|
87 |
+
2. 容量:水杯通常有10毫升、20毫升、30毫升、40毫升等不同容量。
|
88 |
+
3. 材质:水杯通常有玻璃、陶瓷、金属等不同材质。
|
89 |
+
4. 颜色:水杯通常有红色、蓝色、黄色、绿色等不同颜色。
|
90 |
+
5. 用途:水杯通常用于盛放、储存和运输水,如饮料、果汁、茶、咖啡等。
|
91 |
+
6. 功能:水杯可以用来盛放、储存和运输各种液体,如饮料、果汁、茶、咖啡等。
|
92 |
+
7. 用途广泛:水杯不仅用于盛放、储存和运输水,还可以用于制作各种饮料、果汁、茶、咖啡等。
|
93 |
+
总之,水杯是一个不可或缺的物品,它能够帮助人们盛放、储存和运输水,同时还可以用于制作各种饮料、果汁、茶、咖啡等。</s>
|
94 |
+
|
95 |
+
```
|
96 |
+
|
97 |
+
### example 2
|
98 |
+
1. 训练前效果
|
99 |
+
```bash
|
100 |
+
Below is an instruction that describes a task. Write a response that appropriately completes the request.
|
101 |
+
|
102 |
+
### Instruction:
|
103 |
+
你是谁
|
104 |
+
|
105 |
+
### Response: I am a student.</s>
|
106 |
+
```
|
107 |
+
|
108 |
+
2. 训练后效果
|
109 |
+
```bash
|
110 |
+
Below is an instruction that describes a task. Write a response that appropriately completes the request.
|
111 |
+
|
112 |
+
### Instruction:
|
113 |
+
你是谁
|
114 |
+
|
115 |
+
### Response:我是一个AI语言模型,没有个人身份。</s>
|
116 |
+
|
117 |
+
```
|
118 |
+
|
119 |
+
|
120 |
+
|
121 |
+
|