--- language: - zh tags: - t5 - pytorch - prompt - zh - Text2Text-Generation license: "apache-2.0" widget: - text: "宫颈癌的早期会有哪些危险信号" - text: "夏季如何进行饮食调养养生?" --- 中文版对话机器人 在1000w+问答和对话数据上做有监督预训练 ## 注意事项 请使用下面方式调用模型输出结果,Hosted inference API的结果因为我无法修改后台推理程序,不能保证模型输出效果,只是举了两个例子展示。 模型采用top p的解码方式,每次运行可能结果都略微有些不同。 Install package: ``` pip install transformers ``` ```python import os os.environ["CUDA_VISIBLE_DEVICES"] = '-1' import torch from torch import cuda from transformers import AutoTokenizer, AutoModelForSeq2SeqLM tokenizer = AutoTokenizer.from_pretrained("mxmax/Chinese_Chat_T5_Base") model = AutoModelForSeq2SeqLM.from_pretrained("mxmax/Chinese_Chat_T5_Base") device = 'cuda' if cuda.is_available() else 'cpu' model_trained.to(device) def postprocess(text): return text.replace(".", "").replace('','') def answer_fn(text, sample=False, top_p=0.6): encoding = tokenizer(text=[text], truncation=True, padding=True, max_length=256, return_tensors="pt").to(device) 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) result = tokenizer.batch_decode(out["sequences"], skip_special_tokens=True) return postprocess(result[0]) text="宫颈癌的早期会有哪些危险信号" result=answer_fn(text, sample=True, top_p=0.6) print('prompt:',text) print("result:",result) ``` ## 预测示例 #### 普通百科问答 ```bash Input: 关于基金啥叫前端申购代码,后端申购代码.有啥区别.有甚么作用. Model output: 前端申购代码: 1在基金公司网站上输入"赎回申请书(或直接到证券公司的柜台),填写“委托人及受托银行”的注册信息 2将指定金额提交给投资者 3根据提示完成操作 4确认并修改交易规则,确定是否需要转换为其他方式进行投资。 ``` ```bash Input: 深圳哪家店火锅好吃? Model output: 火锅店 地址:深圳宝安区沙井路20号(深大对面)。 ``` ```bash Input: 北京有哪些景点方好玩呢推荐下 Model output: 故宫的门票是5元,如果去的话可以先到北京故宫博物院看看。 ```