|
--- |
|
license: mit |
|
language: |
|
- ru |
|
pipeline_tag: text2text-generation |
|
widget: |
|
- text: '<SC6>Человек: Ответь на вопрос. Почему трава зеленая?\nБот: <extra_id_0>' |
|
- text: '<SC1>Тебя зовут Анфиса. Тебе интересно машинное обучение.\nСобеседник сказал: Привет\nТы ответил: <extra_id_0>' |
|
- text: '<SC6>Тебя зовут Анфиса. Тебе интересно машинное обучение.\nСобеседник сказал: Что делать, если шалят нервишки?\nТы ответил: <extra_id_0>' |
|
--- |
|
# Den4ikAI/FRED-T5-XL_instructor_chitchat |
|
Инструкционная модель на FRED-T5-XL. Обратите внимание на настройки генерации в примере чит-чата. |
|
# Пример использования [Instruct] |
|
```python |
|
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, GenerationConfig |
|
import torch |
|
use_cuda = torch.cuda.is_available() |
|
device = torch.device("cuda" if use_cuda else "cpu") |
|
tokenizer = AutoTokenizer.from_pretrained("Den4ikAI/FRED-T5-XL_instructor_chitchat") |
|
model = AutoModelForSeq2SeqLM.from_pretrained("Den4ikAI/FRED-T5-XL_instructor_chitchat", torch_dtype=torch.float16).to(device) |
|
model.eval() |
|
generation_config = GenerationConfig.from_pretrained("Den4ikAI/FRED-T5-XL_instructor_chitchat") |
|
def generate(prompt): |
|
data = tokenizer(f"<SC6>Человек: {prompt}\nБот: <extra_id_0>", return_tensors="pt").to(model.device) |
|
output_ids = model.generate( |
|
**data, |
|
generation_config=generation_config |
|
)[0] |
|
print(tokenizer.decode(data["input_ids"][0].tolist())) |
|
out = tokenizer.decode(output_ids.tolist()) |
|
return out |
|
while 1: |
|
generate(input(":> ")) |
|
|
|
``` |
|
# Пример использования [Chitchat] |
|
```python |
|
import torch |
|
import transformers |
|
|
|
use_cuda = torch.cuda.is_available() |
|
device = torch.device("cuda" if use_cuda else "cpu") |
|
|
|
t5_tokenizer = transformers.GPT2Tokenizer.from_pretrained("Den4ikAI/FRED-T5-XL_instructor_chitchat") |
|
t5_model = transformers.T5ForConditionalGeneration.from_pretrained("Den4ikAI/FRED-T5-XL_instructor_chitchat") |
|
generation_config = transformers.GenerationConfig.from_pretrained("Den4ikAI/FRED-T5-XL_instructor_chitchat") |
|
|
|
while True: |
|
print('-'*80) |
|
dialog = [] |
|
while True: |
|
msg = input('H:> ').strip() |
|
if len(msg) == 0: |
|
break |
|
msg = msg[0].upper() + msg[1:] |
|
dialog.append('Собеседник сказал: ' + msg) |
|
# Данный пример промпта позволяет вести диалог и писать инструкции. |
|
# prompt = '<SC6>Тебя зовут Анфиса. Тебе интересно машинное обучение.' + '\n'.join(dialog) + '\nТы ответил: <extra_id_0>' |
|
# Второй пример - промпт просто для диалогов. В таком режиме не будет глюков, когда модель кидает кусок промпта в ответ. |
|
prompt = '<SC6>Тебя зовут Анфиса. Тебе интересно машинное обучение.' + '\n'.join(dialog) + '\nТы ответил: <extra_id_0>' |
|
|
|
input_ids = t5_tokenizer(prompt, return_tensors='pt').input_ids |
|
out_ids = t5_model.generate(input_ids=input_ids.to(device), generation_config=generation_config) |
|
t5_output = t5_tokenizer.decode(out_ids[0][1:]) |
|
if '</s>' in t5_output: |
|
t5_output = t5_output[:t5_output.find('</s>')].strip() |
|
|
|
t5_output = t5_output.replace('<extra_id_0>', '').strip() |
|
t5_output = t5_output.split('Собеседник')[0].strip() |
|
print('B:> {}'.format(t5_output)) |
|
dialog.append('Ты ответил: ' + t5_output) |
|
``` |
|
# Citation |
|
``` |
|
@MISC{Den4ikAI/FRED-T5-XL_instructor_chitchat, |
|
author = {Denis Petrov}, |
|
title = {Russian Instruct and Chitchat model}, |
|
url = {https://huggingface.co/Den4ikAI/FRED-T5-XL_instructor_chitchat/}, |
|
year = 2023 |
|
} |
|
``` |