Upload README.md
Browse files
README.md
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: mit
|
3 |
+
language:
|
4 |
+
- ru
|
5 |
+
pipeline_tag: text2text-generation
|
6 |
+
widget:
|
7 |
+
- text: '<SC1>человек: Как тебя зовут?\nчатбот: Даша\nчеловек: А меня Денис\nчатбот: <extra_id_0>'
|
8 |
+
---
|
9 |
+
# Den4ikAI/FRED-T5-XL-chitchat
|
10 |
+
Болталка на основе FRED-T5-XL. Длина контекста модели 6-8 реплик.
|
11 |
+
|
12 |
+
# Пример использования
|
13 |
+
```python
|
14 |
+
import torch
|
15 |
+
import transformers
|
16 |
+
|
17 |
+
use_cuda = torch.cuda.is_available()
|
18 |
+
device = torch.device("cuda" if use_cuda else "cpu")
|
19 |
+
|
20 |
+
|
21 |
+
t5_tokenizer = transformers.GPT2Tokenizer.from_pretrained("Den4ikAI/FRED-T5-XL-chitchat")
|
22 |
+
t5_model = transformers.T5ForConditionalGeneration.from_pretrained("Den4ikAI/FRED-T5-XL-chitchat")
|
23 |
+
t5_model.to(device)
|
24 |
+
t5_model.eval()
|
25 |
+
|
26 |
+
while True:
|
27 |
+
print('-'*80)
|
28 |
+
dialog = []
|
29 |
+
while True:
|
30 |
+
msg = input('Вопрос :> ').strip()
|
31 |
+
if len(msg) == 0:
|
32 |
+
break
|
33 |
+
|
34 |
+
msg = msg[0].upper() + msg[1:]
|
35 |
+
dialog.append('человек: ' + msg)
|
36 |
+
prompt = '<SC1>' + '\n'.join(dialog) + '\nчатбот: <extra_id_0>'
|
37 |
+
|
38 |
+
input_ids = t5_tokenizer(prompt, return_tensors='pt').input_ids
|
39 |
+
out_ids = t5_model.generate(input_ids=input_ids.to(device),
|
40 |
+
max_length=200,
|
41 |
+
eos_token_id=t5_tokenizer.eos_token_id,
|
42 |
+
early_stopping=True,
|
43 |
+
do_sample=True,
|
44 |
+
temperature=1.0,
|
45 |
+
top_k=0,
|
46 |
+
top_p=0.95)
|
47 |
+
|
48 |
+
t5_output = t5_tokenizer.decode(out_ids[0][1:])
|
49 |
+
if '</s>' in t5_output:
|
50 |
+
t5_output = t5_output[:t5_output.find('</s>')].strip()
|
51 |
+
|
52 |
+
t5_output = t5_output.replace('<extra_id_0>', '').strip()
|
53 |
+
|
54 |
+
print('Ответ :> {}'.format(t5_output))
|
55 |
+
dialog.append('чатбот: ' + t5_output)
|
56 |
+
```
|
57 |
+
# Citation
|
58 |
+
```
|
59 |
+
@MISC{Den4ikAI/FRED-T5-XL-chitchat,
|
60 |
+
author = {Denis Petrov, Ilya Koziev},
|
61 |
+
title = {Russian chitchat model},
|
62 |
+
url = {https://huggingface.co/Den4ikAI/FRED-T5-XL-chitchat},
|
63 |
+
year = 2023
|
64 |
+
}
|
65 |
+
```
|