yuanzhoulvpi commited on
Commit
769ad7a
1 Parent(s): b562b9d

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +56 -0
README.md CHANGED
@@ -1,3 +1,59 @@
1
  ---
2
  license: bigscience-bloom-rail-1.0
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: bigscience-bloom-rail-1.0
3
+ language:
4
+ - zh
5
  ---
6
+
7
+ ## 介绍
8
+ 1. ✅ 对`bloom-7b`模型做了sft
9
+ 2. 🚀 训练代码和推理代码全部分享,可以查看链接[https://github.com/yuanzhoulvpi2017/zero_nlp/tree/main/chinese_bloom](https://github.com/yuanzhoulvpi2017/zero_nlp/tree/main/chinese_bloom)
10
+
11
+ ## 个人感受
12
+ 1. 🎯 `bloom`系列的模型,在中文领域,具有极大的潜力,在经过有监督微调训练之后,效果非常惊人!
13
+ 2. 🔄 `bloom`系列的模型,覆盖中文、英文、代码、法语、西班牙语等。即使拿来做翻译、拿来做代码生成,也都没问题!(后期将会分享相关教程)
14
+ 3. 😛 当前的这个`bloom-7b`模型,我是非常喜欢滴,特地在`8xA100`机器上训练了部分数据。整体效果非常不错~
15
+
16
+ ## 如何使用
17
+
18
+ ```python
19
+ from transformers import AutoModelForCausalLM, AutoTokenizer
20
+
21
+
22
+ checkpoint = "yuanzhoulvpi/chinese_bloom_7b_chat"#"bigscience/bloomz-3b" #"bigscience/bloom-7b1"# "output_dir/checkpoint-8260"#
23
+ tokenizer = AutoTokenizer.from_pretrained(checkpoint)
24
+ model = AutoModelForCausalLM.from_pretrained(checkpoint).half().cuda()
25
+
26
+ PROMPT_DICT = {
27
+ "prompt_input": (
28
+ "Below is an instruction that describes a task, paired with an input that provides further context. "
29
+ "Write a response that appropriately completes the request.\n\n"
30
+ "### Instruction:\n{instruction}\n\n### Input:\n{input}\n\n### Response:"
31
+ ),
32
+ "prompt_no_input": (
33
+ "Below is an instruction that describes a task. "
34
+ "Write a response that appropriately completes the request.\n\n"
35
+ "### Instruction:\n{instruction}\n\n### Response:"
36
+ ),
37
+ }
38
+
39
+ from typing import Optional
40
+ def generate_input(instruction:Optional[str]= None, input_str:Optional[str] = None) -> str:
41
+ if input_str is None:
42
+ return PROMPT_DICT['prompt_no_input'].format_map({'instruction':instruction})
43
+ else:
44
+ return PROMPT_DICT['prompt_input'].format_map({'instruction':instruction, 'input':input_str})
45
+
46
+
47
+ for i in range(5):
48
+ print("*"*80)
49
+
50
+ inputs = tokenizer.encode(generate_input(instruction="你是谁"), return_tensors="pt")
51
+ outputs = model.generate(inputs,num_beams=3,
52
+ max_new_tokens=512,
53
+ do_sample=False,
54
+ top_k=10,
55
+ penalty_alpha=0.6,
56
+ temperature=0.8,
57
+ repetition_penalty=1.2)
58
+ print(tokenizer.decode(outputs[0]))
59
+ ```