模型:
microsoft/GODEL-v1_1-base-seq2seq
GODEL 是一个用于目标导向对话的大规模预训练模型。它采用基于Transformer的编码器-解码器模型进行参数化,并通过在外部文本上进行训练来生成回复,这使得在需要将回复条件化为当前对话外部信息的对话任务上可以更有效地进行微调(例如,检索到的文档)。预训练模型可以经过有效的微调和调整,以完成一个新的对话任务,并只需少量任务特定的对话。v1.1 模型是根据来自Reddit讨论串的551M 多轮对话和5M 指令和知识为基础进行训练的。
来自交互环境的多轮生成示例:闲聊示例:
指令:给定对话上下文,您需要具有共情回应。 用户:金钱能买到幸福吗? 代理:这是一个问题。金钱可以买到很多东西,但不足以买到幸福。 用户:买到幸福的最好方法是什么? 代理:幸福是通过您的经历而不是金钱来获得的。
基于相关知识的回应生成示例:
指令:给定对话上下文和相关知识,您需要根据知识安全地作出回应。 知识:最好的Stardew Valley 调整贴 PCGamesN_0 / 关于SMAPI 用户:我最喜欢的游戏是Stardew Valley。Stardew Valley非常有趣。 代理:我喜欢Stardew Valley的调整贴,比如PCGamesN_0 / 关于SMAPI。
请在 project webpage 中找到有关预处理、训练和GODEL的完整细节。
ArXiv 论文: https://arxiv.org/abs/2206.11309
现在我们可以尝试将模型用作聊天伙伴!
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM tokenizer = AutoTokenizer.from_pretrained("microsoft/GODEL-v1_1-base-seq2seq") model = AutoModelForSeq2SeqLM.from_pretrained("microsoft/GODEL-v1_1-base-seq2seq") def generate(instruction, knowledge, dialog): if knowledge != '': knowledge = '[KNOWLEDGE] ' + knowledge dialog = ' EOS '.join(dialog) query = f"{instruction} [CONTEXT] {dialog} {knowledge}" input_ids = tokenizer(f"{query}", return_tensors="pt").input_ids outputs = model.generate(input_ids, max_length=128, min_length=8, top_p=0.9, do_sample=True) output = tokenizer.decode(outputs[0], skip_special_tokens=True) return output # Instruction for a chitchat task instruction = f'Instruction: given a dialog context, you need to response empathically.' # Leave the knowldge empty knowledge = '' dialog = [ 'Does money buy happiness?', 'It is a question. Money buys you a lot of things, but not enough to buy happiness.', 'What is the best way to buy happiness ?' ] response = generate(instruction, knowledge, dialog) print(response)
如果您在研究中使用此代码和数据,请引用我们的arxiv论文:
@misc{peng2022godel, author = {Peng, Baolin and Galley, Michel and He, Pengcheng and Brockett, Chris and Liden, Lars and Nouri, Elnaz and Yu, Zhou and Dolan, Bill and Gao, Jianfeng}, title = {GODEL: Large-Scale Pre-training for Goal-Directed Dialog}, howpublished = {arXiv}, year = {2022}, month = {June}, url = {https://www.microsoft.com/en-us/research/publication/godel-large-scale-pre-training-for-goal-directed-dialog/}, }