模型:

microsoft/GODEL-v1_1-large-seq2seq

英文

大规模预训练的目标导向对话系统(GODEL)

GODEL是一种用于目标导向对话的大规模预训练模型。它采用基于Transformer的编码器-解码器模型进行参数化,并通过外部文本进行响应生成的训练,从而能更有效地进行对话任务的微调,这些任务要求将响应条件限制在当前对话之外的信息上(例如,检索到的文档)。预训练模型可以通过少量特定任务的对话进行高效微调和适应,以完成新的对话任务。v1.1模型是在Reddit讨论主题中的5.51亿多轮对话和500万个指令和知识相关对话上进行训练的。

来自交互环境的多轮生成示例:

闲聊示例:

指令: 给定一个对话上下文,你需要给出同理心的回复。用户: 金钱能买到幸福吗?机器人: 这是一个问题。金钱可以为你买到很多东西,但不足以买到幸福。用户: 购买幸福的最好方式是什么?机器人: 幸福是通过你的经历得来的,而不是金钱。

基于相关知识的响应生成示例:

指令: 给定一个对话上下文和相关知识,你需要基于知识安全回答。知识: 关于SMAPI的Stardew Valley最佳模组PCGamesN_0 / About SMAPI用户: 我最喜欢的游戏是Stardew Valley。Stardew Valley非常有趣。机器人: 我喜欢Stardew Valley的模组,比如PCGamesN_0 / About SMAPI。

请在该链接中找到关于预处理、训练和GODEL的详细信息: project webpage

ArXiv论文: https://arxiv.org/abs/2206.11309

如何使用

现在我们可以尝试将该模型用作闲聊伙伴的工具了!

from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
tokenizer = AutoTokenizer.from_pretrained("microsoft/GODEL-v1_1-large-seq2seq")
model = AutoModelForSeq2SeqLM.from_pretrained("microsoft/GODEL-v1_1-large-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/},
}