SmilePanda commited on
Commit
bcc436f
1 Parent(s): a8127db

Upload README.md

Browse files
Files changed (1) hide show
  1. README.md +70 -1
README.md CHANGED
@@ -5,4 +5,73 @@ datasets:
5
  - BelleGroup/train_2M_CN
6
  language:
7
  - zh
8
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  - BelleGroup/train_2M_CN
6
  language:
7
  - zh
8
+ ---
9
+ # Langboat_bloom-6b4-zh-instruct_finetune-chat
10
+ 是基于Langboat_bloom-6b4-zh模型,在firefly-train-1.1M和Belle-train_2m_cn数据集上采用的QLoRA方法微调的对话模型。
11
+ 在CEVAL上的评测结果:
12
+
13
+ | STEM | Social Sciences | Humanities | Others | Average | AVG(Hard) |
14
+ |------|-----------------|------------|--------|---------|-----------|
15
+ | 27.9 | 27.2 | 24.8 | 26.4 | 26.8 | 28.0 |
16
+
17
+ # 使用
18
+ ## 单轮指令生成
19
+ ```python
20
+ from transformers import AutoTokenizer, AutoModelForCausalLM
21
+
22
+ device = "cuda"
23
+ model = AutoModelForCausalLM.from_pretrained("SmilePanda/Langboat_bloom-6b4-zh-instruct_finetune-chat", device_map=device)
24
+ tokenizer = AutoTokenizer.from_pretrained("SmilePanda/Langboat_bloom-6b4-zh-instruct_finetune-chat", use_fast=False)
25
+
26
+ source_prefix = "human"
27
+ target_prefix = "assistant"
28
+ query = "你好"
29
+ sentence = f"{source_prefix}: \n{query}\n\n{target_prefix}: \n"
30
+ print("query: ", sentence)
31
+ input_ids = tokenizer(sentence, return_tensors='pt').input_ids.to(device)
32
+ outputs = model.generate(input_ids=input_ids, max_new_tokens=500,
33
+ do_sample=True,
34
+ top_p=0.8,
35
+ temperature=0.35,
36
+ repetition_penalty=1.2,
37
+ eos_token_id=tokenizer.eos_token_id)
38
+ rets = tokenizer.batch_decode(outputs, skip_special_tokens=True)[0].strip()
39
+ response = rets.replace(sentence, "")
40
+ print(response)
41
+ ```
42
+
43
+ ## 多轮对话
44
+ ```python
45
+ import os
46
+ from transformers import AutoTokenizer, AutoModelForCausalLM
47
+
48
+ device = "cuda"
49
+ model = AutoModelForCausalLM.from_pretrained("SmilePanda/Langboat_bloom-6b4-zh-instruct_finetune-chat", device_map=device)
50
+ tokenizer = AutoTokenizer.from_pretrained("SmilePanda/Langboat_bloom-6b4-zh-instruct_finetune-chat", use_fast=False)
51
+
52
+ source_prefix = "human"
53
+ target_prefix = "assistant"
54
+
55
+ history = ""
56
+
57
+ while True:
58
+ query = input("user: ").strip()
59
+ if not query:
60
+ continue
61
+ if query == 'q' or query == 'stop':
62
+ break
63
+ if history:
64
+ sentence = history + f"\n{source_prefix}: \n{query}\n\n{target_prefix}: \n"
65
+ else:
66
+ sentence = f"{source_prefix}: \n{query}\n\n{target_prefix}: \n"
67
+ input_ids = tokenizer(sentence, return_tensors='pt').input_ids.to(device)
68
+ outputs = model.generate(input_ids=input_ids, max_new_tokens=1024,
69
+ do_sample=True,
70
+ top_p=0.90,
71
+ temperature=0.1,
72
+ repetition_penalty=1.0,
73
+ eos_token_id=tokenizer.eos_token_id)
74
+ rets = tokenizer.batch_decode(outputs, skip_special_tokens=True)[0].strip()
75
+ print("bloom: {}".format(rets.replace(sentence, "")))
76
+ history = rets
77
+ ```