当前位置:网站首页>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))
边栏推荐
- The new JMeter function assistant is not under the options menu - in the toolbar
- Cubemx联合IAR工程移植
- Boolean value
- HowNet and Wanfang database download papers for free ----- several times faster than connecting to the school intranet (some schools Wanfang database does not support downloading)
- Your password does not satisfy the current policy requirements (modify MySQL password policy setting simple password)
- Solve the problem that Flink cannot be closed normally after startup
- matlab legend用法
- 字节跳动服务网格基于 Hertz 框架的落地实践
- Leetcode 226 翻转二叉树(递归)
- DRF use: get request to get data (small example)
猜你喜欢

SolidWorks simulation curve attribute setting

*List reversal

2.2 basic elements of JMeter

2.2 JMeter基本元件

MapReduce instance (I): wordcount

Crmeb Pro v1.4 makes the user experience more brilliant!

Mysql5.7 master-slave hot standby settings on CentOS

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

Find active SQL connections in SQL Server

Replication of complex linked list
随机推荐
Easy to understand, distinguish between ++i and I++
CCF-201312-1
DRF learning notes (preparation)
Addition of large numbers
4位数的随机数据
ADAMS中转动整个模型
Analysis of PHP keyword replacement classes (avoid repeated replacement, keep and restore the original links)
第31回---第52回
Sudden! 28 Chinese entities including Hikvision / Dahua / Shangtang / Kuangshi / ITU / iFLYTEK have been blacklisted by the United States
Common Oracle statements
Firefox old version
Script file ‘D:\programs\anaconda3\Scripts\pip-script.py‘ is not present.
MySQL high version report SQL_ mode=only_ full_ group_ By exception
编码技巧——全局异常捕获&统一的返回体&业务异常
HowNet and Wanfang database download papers for free ----- several times faster than connecting to the school intranet (some schools Wanfang database does not support downloading)
firefox旧版本
Common problems of mobile terminal H5
插入word中的图片保持高dpi方法
MapReduce instance (II): Average
Solve the problem that ${pagecontext.request.contextpath} is invalid