Den4ikAI commited on
Commit
702953a
1 Parent(s): 3f28bcc

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +78 -0
README.md CHANGED
@@ -1,3 +1,81 @@
1
  ---
2
  license: mit
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: mit
3
+ language:
4
+ - ru
5
+ pipeline_tag: text2text-generation
6
+ widget:
7
+ - text: '<SC6>Человек: Ответь на вопрос. Почему трава зеленая?\nБот: <extra_id_0>'
8
+ - text: '<SC1>Тебя зовут Анфиса. Тебе интересно машинное обучение.\nСобеседник сказал: Привет\nТы ответил: <extra_id_0>'
9
+ - text: '<SC6>Тебя зовут Анфиса. Тебе интересно машинное обучение.\nСобеседник сказал: Что делать, если шалят нервишки?\nТы ответил: <extra_id_0>'
10
  ---
11
+ # Den4ikAI/FRED-T5-XL_instructor_chitchat
12
+ Инструкционная модель на FRED-T5-XL. Обратите внимание на настройки генерации в примере чит-чата.
13
+ # Пример использования [Instruct]
14
+ ```python
15
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, GenerationConfig
16
+ import torch
17
+ use_cuda = torch.cuda.is_available()
18
+ device = torch.device("cuda" if use_cuda else "cpu")
19
+ tokenizer = AutoTokenizer.from_pretrained("Den4ikAI/FRED-T5-XL_instructor_chitchat")
20
+ model = AutoModelForSeq2SeqLM.from_pretrained("Den4ikAI/FRED-T5-XL_instructor_chitchat", torch_dtype=torch.float16).to(device)
21
+ model.eval()
22
+ generation_config = GenerationConfig.from_pretrained("Den4ikAI/FRED-T5-XL_instructor_chitchat")
23
+ def generate(prompt):
24
+ data = tokenizer(f"<SC6>Человек: {prompt}\nБот: <extra_id_0>", return_tensors="pt").to(model.device)
25
+ output_ids = model.generate(
26
+ **data,
27
+ generation_config=generation_config
28
+ )[0]
29
+ print(tokenizer.decode(data["input_ids"][0].tolist()))
30
+ out = tokenizer.decode(output_ids.tolist())
31
+ return out
32
+ while 1:
33
+ generate(input(":> "))
34
+
35
+ ```
36
+ # Пример использования [Chitchat]
37
+ ```python
38
+ import torch
39
+ import transformers
40
+
41
+ use_cuda = torch.cuda.is_available()
42
+ device = torch.device("cuda" if use_cuda else "cpu")
43
+
44
+ t5_tokenizer = transformers.GPT2Tokenizer.from_pretrained("Den4ikAI/FRED-T5-XL_instructor_chitchat")
45
+ t5_model = transformers.T5ForConditionalGeneration.from_pretrained("Den4ikAI/FRED-T5-XL_instructor_chitchat")
46
+ generation_config = transformers.GenerationConfig.from_pretrained("Den4ikAI/FRED-T5-XL_instructor_chitchat")
47
+
48
+ while True:
49
+ print('-'*80)
50
+ dialog = []
51
+ while True:
52
+ msg = input('H:> ').strip()
53
+ if len(msg) == 0:
54
+ break
55
+ msg = msg[0].upper() + msg[1:]
56
+ dialog.append('Собеседник сказал: ' + msg)
57
+ # Данный пример промпта позволяет вести диалог и писать инструкции.
58
+ # prompt = '<SC6>Тебя зовут Анфиса. Тебе интересно машинное обучение.' + '\n'.join(dialog) + '\nТы ответил: <extra_id_0>'
59
+ # Второй пример - промпт просто для диалогов. В таком режиме не будет глюков, когда модель кидает кусок промпта в ответ.
60
+ prompt = '<SC6>Тебя зовут Анфиса. Тебе интересно машинное обучение.' + '\n'.join(dialog) + '\nТы ответил: <extra_id_0>'
61
+
62
+ input_ids = t5_tokenizer(prompt, return_tensors='pt').input_ids
63
+ out_ids = t5_model.generate(input_ids=input_ids.to(device), generation_config=generation_config)
64
+ t5_output = t5_tokenizer.decode(out_ids[0][1:])
65
+ if '</s>' in t5_output:
66
+ t5_output = t5_output[:t5_output.find('</s>')].strip()
67
+
68
+ t5_output = t5_output.replace('<extra_id_0>', '').strip()
69
+ t5_output = t5_output.split('Собеседник')[0].strip()
70
+ print('B:> {}'.format(t5_output))
71
+ dialog.append('Ты ответил: ' + t5_output)
72
+ ```
73
+ # Citation
74
+ ```
75
+ @MISC{Den4ikAI/FRED-T5-XL_instructor_chitchat,
76
+ author = {Denis Petrov},
77
+ title = {Russian Instruct and Chitchat model},
78
+ url = {https://huggingface.co/Den4ikAI/FRED-T5-XL_instructor_chitchat/},
79
+ year = 2023
80
+ }
81
+ ```