qhduan commited on
Commit
f2397a4
1 Parent(s): f537b29

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +37 -0
README.md ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - zh
4
+ ---
5
+
6
+ https://github.com/FlagAI-Open/FlagAI/tree/master/examples/Aquila
7
+
8
+ ```python
9
+ import torch
10
+ from transformers import AutoTokenizer, AutoModelForCausalLM
11
+
12
+ tokenizer = AutoTokenizer.from_pretrained('qhduan/aquilachat-7b')
13
+ model = AutoModelForCausalLM.from_pretrained('qhduan/aquilachat-7b', trust_remote_code=True)
14
+ model = model.eval().half().cuda()
15
+
16
+ question = '北京为什么是中国的首都?'
17
+ prompt = (
18
+ '''A chat between a curious human and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the human's questions.'''
19
+ f'''###Human: {question}###Assistant:'''
20
+ )
21
+ with torch.no_grad():
22
+ ret = model.generate(
23
+ **tokenizer(prompt, return_tensors='pt').to('cuda'),
24
+ do_sample=False,
25
+ max_new_tokens=200,
26
+ use_cache=True
27
+ )
28
+ output_ids = ret[0].detach().cpu().numpy().tolist()
29
+ if 100007 in output_ids:
30
+ output_ids = output_ids[:output_ids.index(100007)]
31
+ elif 0 in output_ids:
32
+ output_ids = output_ids[:output_ids.index(0)]
33
+ # 北京之所以成为中国的首都,是因为它在中国历史和文化中的重要地位和政治、经济、文化等方面的影响力。
34
+ print(tokenizer.decode(output_ids))
35
+ ```
36
+
37
+ Aquila-7B和Aquila-33B开源模型使用 [智源Aquila系列模型许可协议](https://github.com/FlagAI-Open/FlagAI/blob/master/BAAI_Aquila_Model_License.pdf), 原始代码基于Apache Licence 2.0。