Views
No views yet
| 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. |
1from transformers import AutoModelForCausalLM, AutoTokenizer
2import torch
3
4
5tokenizer = AutoTokenizer.from_pretrained("shalpin87/dialoGPT-homer-simpson")
6model = AutoModelForCausalLM.from_pretrained("shalpin87/dialoGPT-homer-simpson")
7
8# Let's chat for 5 lines
9for step in range(5):
10 # encode the new user input, add the eos_token and return a tensor in Pytorch
11 new_user_input_ids = tokenizer.encode(input(">> User:") + tokenizer.eos_token, return_tensors='pt')
12
13 # append the new user input tokens to the chat history
14 bot_input_ids = torch.cat([chat_history_ids, new_user_input_ids], dim=-1) if step > 0 else new_user_input_ids
15
16 # generated a response while limiting the total chat history to 1000 tokens,
17 chat_history_ids = model.generate(bot_input_ids, max_length=1000, pad_token_id=tokenizer.eos_token_id)
18
19 # pretty print last ouput tokens from bot
20 print("DialoG-PT-HomerBot: {}".format(tokenizer.decode(chat_history_ids[:, bot_input_ids.shape[-1]:][0], skip_special_tokens=True)))1from transformers import AutoModelForCausalLM, AutoTokenizer
2import torch
3
4
5tokenizer = AutoTokenizer.from_pretrained("shalpin87/dialoGPT-homer-simpson")
6model = AutoModelForCausalLM.from_pretrained("shalpin87/dialoGPT-homer-simpson")
7
8questions = [
9 "What is your name?",
10 "Who are you?",
11 "Where do you work?",
12 "Who really killed Mr Burns?",
13 "Have you ever stolen from the Kwik-E-Mart?",
14 "Did you kill Frank Grimes?",
15 "Who was the worst member of the Be Sharps?",
16 "Hey where did Barney go?",
17 "What is your favorite bar to have a beer?",
18 "What is the best beer in Springfield?",
19 "Is Bart working for the Mob?",
20 "I think there was an incident in sector 7 G",
21 "Is Ned Flanders house okay?",
22 "Oh my god it's Sideshow Bob",
23 "What is a Flaming Moe?",
24 "What is happening to Apu?",
25 "Who quit the band?"
26]
27
28# Let's chat
29for step in range(len(questions)):
30 print("***************************************")
31 print("Q. {}".format(questions[step]))
32 new_user_input_ids = tokenizer.encode(questions[step] + tokenizer.eos_token, return_tensors='pt')
33 # new_user_input_ids = tokenizer.encode(input(">> User:") + tokenizer.eos_token, return_tensors='pt')
34
35 bot_input_ids = new_user_input_ids
36
37 num_return_seqs=1
38
39 chat_history_ids = model.generate(
40 bot_input_ids,
41 max_length=200,
42 pad_token_id=tokenizer.eos_token_id,
43 no_repeat_ngram_size=3,
44 do_sample=True,
45 top_k=200,
46 top_p=0.55,
47 temperature = 0.85,
48 num_return_sequences=num_return_seqs
49 )
50
51 botname = "HomerBot"
52 for i in range(0,num_return_seqs):
53 print("{}:{}: {}".format(i, botname, tokenizer.decode(chat_history_ids[:, bot_input_ids.shape[-1]:][i], skip_special_tokens=True)))
54
55 chat_history_ids = []***************************************
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.