当前位置:网站首页>T5 learning
T5 learning
2022-07-27 16:30:00 【Sweet scented osmanthus is very fragrant, and the rising sun is】
#https://ai.googleblog.com/2020/02/exploring-transfer-learning-with-t5.html
#https://towardsdatascience.com/paraphrase-any-question-with-t5-text-to-text-transfer-transformer-pretrained-model-and-cbb9e35f1555
import torch
from transformers import T5ForConditionalGeneration,T5Tokenizer
#pip install transformers==2.8.0
#https://ai.googleblog.com/2020/02/exploring-transfer-learning-with-t5.html
#https://towardsdatascience.com/paraphrase-any-question-with-t5-text-to-text-transfer-transformer-pretrained-model-and-cbb9e35f1555
def set_seed(seed):
torch.manual_seed(seed)
if torch.cuda.is_available():
torch.cuda.manual_seed_all(seed)
set_seed(42)
model = T5ForConditionalGeneration.from_pretrained('ramsrigouthamg/t5_paraphraser')
tokenizer = T5Tokenizer.from_pretrained('ramsrigouthamg/t5_paraphraser')
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
print ("device ",device)
model = model.to(device)
sentence = "So I worked as a research associate in the field of research in the pharmaceutical industry. My job was to compare the similarities and differences in the processes of production and registration of generic and new medicines. The study aimed to determine which drugs can be successfully sold. The educational experience has been very fruitful for me. This is due to the fact that I was able to apply the concept of economy to the use of analytical force in the course of my work. In general, the orientation of the elderly and self-employment courses helped me a lot to finish my work on time and effectively."
# sentence = "What are the ingredients required to bake a perfect cake?"
# sentence = "What is the best possible approach to learn aeronautical engineering?"
# sentence = "Do apples taste better than oranges in general?"
text = "paraphrase: " + sentence + " </s>"
max_len = 256
encoding = tokenizer.encode_plus(text,pad_to_max_length=True, return_tensors="pt")
input_ids, attention_masks = encoding["input_ids"].to(device), encoding["attention_mask"].to(device)
# set top_k = 50 and set top_p = 0.95 and num_return_sequences = 3
beam_outputs = model.generate(
input_ids=input_ids, attention_mask=attention_masks,
do_sample=True,
max_length=256,
top_k=120,
top_p=0.98,
early_stopping=True,
num_return_sequences=10
)
print ("\nOriginal Question ::")
print (sentence)
print ("\n")
print ("Paraphrased Questions :: ")
final_outputs =[]
for beam_output in beam_outputs:
sent = tokenizer.decode(beam_output, skip_special_tokens=True,clean_up_tokenization_spaces=True)
if sent.lower() != sentence.lower() and sent not in final_outputs:
final_outputs.append(sent)
for i, final_output in enumerate(final_outputs):
print("{}: {}".format(i, final_output))
边栏推荐
- Leetcode234 question - simple method to judge palindrome linked list
- webRTC中的coturn服务安装
- C language programming (Third Edition)
- Addition of large numbers
- The first week of C language learning - the history of C language
- Product axure9 English version, using repeater repeater to realize drop-down multi selection box
- The solution to the memory exhaustion problem when PHP circulates a large amount of data
- 重新配置cubemx后,生成的代码用IAR打开不成功
- KMEANS 实现
- Servlet basic knowledge points
猜你喜欢

2.2 JMeter基本元件

Cron expression use

Characters generated by JMeter function assistant in jmeter5.3 and later versions cannot be copied when they are grayed out

CCF-201312-1

COMS Technology

Is low code the future of development? On low code platform

The image displayed online by TP5 is garbled

Mazak handwheel maintenance Mazak little giant CNC machine tool handle operator maintenance av-eahs-382-1

DRF learning notes (V): viewset

JSP Foundation
随机推荐
firefox旧版本
Implementation of filler creator material editing tool
重新配置cubemx后,生成的代码用IAR打开不成功
Axure 安装图标字体元件库
Time series - use tsfresh for classification tasks
Coturn service installation in webrtc
Introduction to JWT
The difference between select/poll/epoll
C语言逆序输出字符串
知网、万方数据库免费下载论文------比连接学校内网速度快数倍不止(有的学校万方数据库不支持下载)
Common Oracle statements
DRF learning notes (III): model class serializer modelserializer
webRTC中的coturn服务安装
The first week of C language learning - the history of C language
const小结
Brief description of tenant and multi tenant concepts in cloud management platform
The method of inserting degree in word
C语言程序设计(第三版)
Use of arrow function
DRF learning notes (II): Data deserialization