当前位置:网站首页>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))
边栏推荐
猜你喜欢

Axure 安装图标字体元件库

Cron expression use

matlab legend用法

Servlet基础知识点

JMeter5.3 及以后的版本jmeter函数助手生成的字符在置灰无法复制

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

字节跳动服务网格基于 Hertz 框架的落地实践

C channel simply implements the publishing and subscription of message queue

Pychart import existing project

Product axure9 English version, using repeater repeater to realize drop-down multi selection box
随机推荐
TP5 query empty two cases
Excel extract duplicates
training on multiple GPUs pytorch
JMeter5.3 及以后的版本jmeter函数助手生成的字符在置灰无法复制
Use of arrow function
COMS Technology
Product axure9 English version, using repeater repeater to realize drop-down multi selection box
2021-03-09
2021-03-09
Axure install Icon Font Catalog
TSMC's 6-nanometer manufacturing process will enter trial production in the first quarter of next year
第21回---第30回
第31回---第52回
CCF-201312-1
The difference and use between get request and post request
知网、万方数据库免费下载论文------比连接学校内网速度快数倍不止(有的学校万方数据库不支持下载)
IO流简介
C语言逆序输出字符串
201403-1
pdf 提取文字