Aero commited on
Commit
56b8d9e
1 Parent(s): 9e7708e

Updated to include Code

Browse files
Files changed (1) hide show
  1. README.md +33 -0
README.md CHANGED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ thumbnail: https://huggingface.co/front/thumbnails/dialogpt.png
3
+ tags:
4
+ - conversational
5
+ license: mit
6
+ ---
7
+ # DialoGPT Trained on the Speech of a Game Character
8
+ ```python
9
+ from transformers import AutoTokenizer, AutoModelWithLMHead
10
+
11
+ tokenizer = AutoTokenizer.from_pretrained("r3dhummingbird/DialoGPT-medium-joshua")
12
+ model = AutoModelWithLMHead.from_pretrained("r3dhummingbird/DialoGPT-medium-joshua")
13
+ # Let's chat for 4 lines
14
+ for step in range(4):
15
+ # encode the new user input, add the eos_token and return a tensor in Pytorch
16
+ new_user_input_ids = tokenizer.encode(input(">> User:") + tokenizer.eos_token, return_tensors='pt')
17
+ # print(new_user_input_ids)
18
+ # append the new user input tokens to the chat history
19
+ bot_input_ids = torch.cat([chat_history_ids, new_user_input_ids], dim=-1) if step > 0 else new_user_input_ids
20
+ # generated a response while limiting the total chat history to 1000 tokens,
21
+ chat_history_ids = model.generate(
22
+ bot_input_ids, max_length=200,
23
+ pad_token_id=tokenizer.eos_token_id,
24
+ no_repeat_ngram_size=3,
25
+ do_sample=True,
26
+ top_k=100,
27
+ top_p=0.7,
28
+ temperature=0.8
29
+ )
30
+
31
+ # pretty print last ouput tokens from bot
32
+ print("Tsubomi: {}".format(tokenizer.decode(chat_history_ids[:, bot_input_ids.shape[-1]:][0], skip_special_tokens=True)))
33
+ ```