|
--- |
|
thumbnail: https://huggingface.co/front/thumbnails/dialogpt.png |
|
tags: |
|
- conversational |
|
license: mit |
|
--- |
|
|
|
## dialogGPT-homer-simpson |
|
|
|
This model has been fine tuned with the entire scripts of Homer Simpson from the T.V. show The Simpsons |
|
It will give some nice answers seemingly from Homers brain in the Simpsons Universe during single turn conversation, letting you chat to Homer Simpson |
|
|
|
## A State-of-the-Art Large-scale Pretrained Response generation model (DialoGPT) |
|
|
|
DialoGPT is a SOTA large-scale pretrained dialogue response generation model for multiturn conversations. |
|
The [human evaluation results](https://github.com/dreasysnail/Dialogpt_dev#human-evaluation) indicate that the response generated from DialoGPT is comparable to human response quality under a single-turn conversation Turing test. |
|
The model is trained on 147M multi-turn dialogue from Reddit discussion thread. |
|
|
|
* Multi-turn generation examples from an interactive environment: |
|
|
|
|Role | Response | |
|
|---------|--------| |
|
|User | Who are you? | |
|
| HomerBot | Homer Simpson .| |
|
|User | What is your favorite Restaurant ? | |
|
| HomerBot | Moes Tavern. | |
|
|User | Have you ever been in a band?! | |
|
| HomerBot | no. | |
|
|
|
Please find the information about preprocessing, training and full details of the DialoGPT in the [original DialoGPT repository](https://github.com/microsoft/DialoGPT) |
|
|
|
ArXiv paper: [https://arxiv.org/abs/1911.00536](https://arxiv.org/abs/1911.00536) |
|
|
|
### How to use Multi-Turn |
|
|
|
#### NOTE: Multi-Turn seems to be broken, after a few exchanges the output will mostly be exclamation marks. |
|
|
|
Now we are ready to try out how the model works as a chatting partner! |
|
|
|
```python |
|
from transformers import AutoModelForCausalLM, AutoTokenizer |
|
import torch |
|
|
|
|
|
tokenizer = AutoTokenizer.from_pretrained("shalpin87/dialoGPT-homer-simpson") |
|
model = AutoModelForCausalLM.from_pretrained("shalpin87/dialoGPT-homer-simpson") |
|
|
|
# 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("DialoG-PT-HomerBot: {}".format(tokenizer.decode(chat_history_ids[:, bot_input_ids.shape[-1]:][0], skip_special_tokens=True))) |
|
``` |
|
|
|
### How to use Single Turn |
|
|
|
```python |
|
from transformers import AutoModelForCausalLM, AutoTokenizer |
|
import torch |
|
|
|
|
|
tokenizer = AutoTokenizer.from_pretrained("shalpin87/dialoGPT-homer-simpson") |
|
model = AutoModelForCausalLM.from_pretrained("shalpin87/dialoGPT-homer-simpson") |
|
|
|
questions = [ |
|
"What is your name?", |
|
"Who are you?", |
|
"Where do you work?", |
|
"Who really killed Mr Burns?", |
|
"Have you ever stolen from the Kwik-E-Mart?", |
|
"Did you kill Frank Grimes?", |
|
"Who was the worst member of the Be Sharps?", |
|
"Hey where did Barney go?", |
|
"What is your favorite bar to have a beer?", |
|
"What is the best beer in Springfield?", |
|
"Is Bart working for the Mob?", |
|
"I think there was an incident in sector 7 G", |
|
"Is Ned Flanders house okay?", |
|
"Oh my god it's Sideshow Bob", |
|
"What is a Flaming Moe?", |
|
"What is happening to Apu?", |
|
"Who quit the band?" |
|
] |
|
|
|
# Let's chat |
|
for step in range(len(questions)): |
|
print("***************************************") |
|
print("Q. {}".format(questions[step])) |
|
new_user_input_ids = tokenizer.encode(questions[step] + tokenizer.eos_token, return_tensors='pt') |
|
# new_user_input_ids = tokenizer.encode(input(">> User:") + tokenizer.eos_token, return_tensors='pt') |
|
|
|
bot_input_ids = new_user_input_ids |
|
|
|
num_return_seqs=1 |
|
|
|
chat_history_ids = model.generate( |
|
bot_input_ids, |
|
max_length=200, |
|
pad_token_id=tokenizer.eos_token_id, |
|
no_repeat_ngram_size=3, |
|
do_sample=True, |
|
top_k=200, |
|
top_p=0.55, |
|
temperature = 0.85, |
|
num_return_sequences=num_return_seqs |
|
) |
|
|
|
botname = "HomerBot" |
|
for i in range(0,num_return_seqs): |
|
print("{}:{}: {}".format(i, botname, tokenizer.decode(chat_history_ids[:, bot_input_ids.shape[-1]:][i], skip_special_tokens=True))) |
|
|
|
chat_history_ids = [] |
|
``` |
|
|
|
Sample Output |
|
``` |
|
*************************************** |
|
Q. What is your name? |
|
0:HomerBot: Homer Simpson. |
|
*************************************** |
|
Q. Who are you? |
|
0:HomerBot: Homer Simpson. |
|
*************************************** |
|
Q. Where do you work? |
|
0:HomerBot: I work at a nuclear power plant. |
|
*************************************** |
|
Q. Who really killed Mr Burns? |
|
0:HomerBot: I dunno. Some guy named Ot-to. |
|
*************************************** |
|
Q. Have you ever stolen from the Kwik-E-Mart? |
|
0:HomerBot: No. |
|
*************************************** |
|
Q. Did you kill Frank Grimes? |
|
0:HomerBot: No. |
|
*************************************** |
|
Q. Who was the worst member of the Be Sharps? |
|
0:HomerBot: Homer Simpson, sir. |
|
*************************************** |
|
Q. Hey where did Barney go? |
|
0:HomerBot: He's been eating that thing for a week. |
|
*************************************** |
|
Q. What is your favorite bar to have a beer? |
|
0:HomerBot: The Flanders' Club. |
|
*************************************** |
|
Q. What is the best beer in Springfield? |
|
0:HomerBot: Pepi! |
|
*************************************** |
|
Q. Is Bart working for the Mob? |
|
0:HomerBot: I think he's trying to tell us something. |
|
*************************************** |
|
Q. I think there was an incident in sector 7 G |
|
0:HomerBot: Uh, let's not jump to any conclusions. The dog didn't run away. |
|
``` |