HuggingFace镜像/DialoGPT-large
模型介绍文件和版本分析
下载使用量0

先进的大规模预训练对话响应生成模型(DialoGPT)

DialoGPT 是一款用于多轮对话的先进大规模预训练对话响应生成模型。 人工评估结果表明,在单轮对话图灵测试中,DialoGPT 生成的响应质量可与人类响应相媲美。 该模型是在来自 Reddit 讨论线程的 1.47 亿条多轮对话数据上训练而成的。

  • 交互式环境中的多轮生成示例:
角色响应
用户金钱能买到幸福吗?
机器人这取决于你在幸福上花了多少钱。
用户买到幸福的最佳方式是什么?
机器人你只需在 20 岁出头就成为百万富翁,这样你就能幸福了。
用户这太难了!
机器人你根本不知道成为百万富翁并保持幸福有多难。富人拥有大量金钱是有原因的。

有关 DialoGPT 的预处理、训练和完整详细信息,请参见原始 DialoGPT 代码库

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

如何使用 openmind

现在,我们准备好尝试将该模型作为聊天伙伴使用了!

from openmind import AutoModelForCausalLM, AutoTokenizer
import torch


tokenizer = AutoTokenizer.from_pretrained("microsoft/DialoGPT-large")
model = AutoModelForCausalLM.from_pretrained("microsoft/DialoGPT-large")

# Let's chat for 5 lines
for step in range(5):
	# encode the new user input, add the eos_token and return a tensor in Pytorch
	new_user_input_ids = tokenizer.encode(input(">> User:") + tokenizer.eos_token, return_tensors='pt')

	# append the new user input tokens to the chat history
	bot_input_ids = torch.cat([chat_history_ids, new_user_input_ids], dim=-1) if step > 0 else new_user_input_ids

	# generated a response while limiting the total chat history to 1000 tokens, 
	chat_history_ids = model.generate(bot_input_ids, max_length=1000, pad_token_id=tokenizer.eos_token_id)

	# pretty print last ouput tokens from bot
	print("DialoGPT: {}".format(tokenizer.decode(chat_history_ids[:, bot_input_ids.shape[-1]:][0], skip_special_tokens=True)))