Commit
·
f754e38
1
Parent(s):
3223321
Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language: English
|
3 |
+
datasets:
|
4 |
+
- Andrada Olteanu Rickmorty-Scripts
|
5 |
+
tags:
|
6 |
+
- Transformers
|
7 |
+
- gpt2
|
8 |
+
- Chatbot
|
9 |
+
- Rick&Morty
|
10 |
+
license: apache-2.0
|
11 |
+
metrics:
|
12 |
+
- Perplexity
|
13 |
+
---
|
14 |
+
## Evaluation
|
15 |
+
|
16 |
+
```python
|
17 |
+
tokenizer = AutoTokenizer.from_pretrained('kingabzpro/DialoGPT-small-Rick-Bot')
|
18 |
+
model = AutoModelWithLMHead.from_pretrained(kingabzpro/DialoGPT-small-Rick-Bot')
|
19 |
+
# Let's chat for 4 lines
|
20 |
+
for step in range(4):
|
21 |
+
# encode the new user input, add the eos_token and return a tensor in Pytorch
|
22 |
+
new_user_input_ids = tokenizer.encode(input(">> User:") + tokenizer.eos_token, return_tensors='pt')
|
23 |
+
# print(new_user_input_ids)
|
24 |
+
|
25 |
+
# append the new user input tokens to the chat history
|
26 |
+
bot_input_ids = torch.cat([chat_history_ids, new_user_input_ids], dim=-1) if step > 0 else new_user_input_ids
|
27 |
+
|
28 |
+
# generated a response while limiting the total chat history to 1000 tokens,
|
29 |
+
chat_history_ids = model.generate(
|
30 |
+
bot_input_ids, max_length=200,
|
31 |
+
pad_token_id=tokenizer.eos_token_id,
|
32 |
+
no_repeat_ngram_size=3,
|
33 |
+
do_sample=True,
|
34 |
+
top_k=100,
|
35 |
+
top_p=0.7,
|
36 |
+
temperature=0.8
|
37 |
+
)
|
38 |
+
|
39 |
+
# pretty print last ouput tokens from bot
|
40 |
+
print("RickBot: {}".format(tokenizer.decode(chat_history_ids[:, bot_input_ids.shape[-1]:][0], skip_special_tokens=True)))
|
41 |
+
```
|
42 |
+
|
43 |
+
**Result**: perplexity = 8.53
|