Update README.md
Browse files
README.md
CHANGED
@@ -15,5 +15,35 @@ widget:
|
|
15 |
|
16 |
中文版对话机器人
|
17 |
|
|
|
18 |
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
中文版对话机器人
|
17 |
|
18 |
+
在1000w+问答和对话数据上做有监督预训练
|
19 |
|
20 |
+
请使用下面方式调用模型输出结果,Hosted inference API的结果因为我无法修改后台推理程序,不能保证模型输出效果,只是举了两个例子展示展示。
|
21 |
+
|
22 |
+
Install package:
|
23 |
+
```
|
24 |
+
pip install transformers
|
25 |
+
```
|
26 |
+
|
27 |
+
```python
|
28 |
+
import os
|
29 |
+
os.environ["CUDA_VISIBLE_DEVICES"] = '-1'
|
30 |
+
import torch
|
31 |
+
from torch import cuda
|
32 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
33 |
+
tokenizer = AutoTokenizer.from_pretrained("mxmax/Chinese_Chat_T5_Base")
|
34 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("mxmax/Chinese_Chat_T5_Base")
|
35 |
+
device = 'cuda' if cuda.is_available() else 'cpu'
|
36 |
+
model_trained.to(device)
|
37 |
+
def postprocess(text):
|
38 |
+
return text.replace(".", "").replace('</>','')
|
39 |
+
|
40 |
+
def answer_fn(text, sample=False, top_p=0.6):
|
41 |
+
encoding = tokenizer(text=[text], truncation=True, padding=True, max_length=256, return_tensors="pt").to(device)
|
42 |
+
out = model.generate(**encoding, return_dict_in_generate=True, output_scores=False, max_length=512,temperature=0.5,do_sample=True,repetition_penalty=6.0 ,top_p=top_p)
|
43 |
+
result = tokenizer.batch_decode(out["sequences"], skip_special_tokens=True)
|
44 |
+
return postprocess(result[0])
|
45 |
+
text="宫颈癌的早期会有哪些危险信号"
|
46 |
+
result=answer_fn(text, sample=True, top_p=0.6)
|
47 |
+
print('prompt:',text)
|
48 |
+
print("result:",result)
|
49 |
+
```
|