模型:

cedpsam/chatbot_fr

英文

一个在法国开放字幕上训练的dialoggpt模型用于自定义分词

用这个笔记本进行训练 https://colab.research.google.com/drive/1pfCV3bngAmISNZVfDvBMyEhQKuYw37Rl#scrollTo=AyImj9qZYLRi&uniqifier=3

使用 microsoft/DialoGPT-medium 配置文件,从2018 open subtitles 下载数据集,按照 https://github.com/PolyAI-LDN/conversational-datasets/tree/master/opensubtitles 这些准则生成数据集,使用这个笔记本 https://colab.research.google.com/drive/1uyh3vJ9nEjqOHI68VD73qxt4olJzODxi#scrollTo=deaacv4XfLMk

如何使用

现在我们可以试试这个模型作为聊天伙伴的效果了!

import torch
from transformers import AutoTokenizer, AutoModelWithLMHead

tokenizer = AutoTokenizer.from_pretrained("cedpsam/chatbot_fr")

model = AutoModelWithLMHead.from_pretrained("cedpsam/chatbot_fr")

for step in range(6):
    # 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')
    # print(new_user_input_ids)

    # 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,
        top_p=0.92, top_k = 50
    )
    
    # 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)))