Ahmade commited on
Commit
75e7d02
·
1 Parent(s): 3cd26fd

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +29 -0
README.md ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def chat(model, tokenizer):
2
+ print("type \"q\" to quit. Automatically quits after 5 messages")
3
+
4
+ for step in range(5):
5
+ message = input("MESSAGE: ")
6
+
7
+ if message in ["", "q"]: # if the user doesn't wanna talk
8
+ break
9
+
10
+ # encode the new user input, add the eos_token and return a tensor in Pytorch
11
+ new_user_input_ids = tokenizer.encode(message + 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(
18
+ bot_input_ids,
19
+ max_length=1000,
20
+ pad_token_id=tokenizer.eos_token_id,
21
+ no_repeat_ngram_size=3,
22
+ do_sample=True,
23
+ top_k=100,
24
+ top_p=0.7,
25
+ temperature = 0.8,
26
+ )
27
+ # pretty print last ouput tokens from bot
28
+ print("DialoGPT: {}".format(tokenizer.decode(chat_history_ids[:, bot_input_ids.shape[-1]:][0], skip_special_tokens=True)))
29
+