import torch
from transformers import PegasusForConditionalGeneration, PegasusTokenizer
model_name = 'tuner007/pegasus_paraphrase'
torch_device = 'cuda' if torch.cuda.is_available() else 'cpu'
tokenizer = PegasusTokenizer.from_pretrained(model_name)
model = PegasusForConditionalGeneration.from_pretrained(model_name).to(torch_device)
def get_response(input_text,num_return_sequences):
# batch = tokenizer.prepare_seq2seq_batch([input_text],truncation=True,padding='longest',max_length=60, return_tensors="pt").to(torch_device)
with tokenizer.as_target_tokenizer():
tokenized_text = tokenizer(input_text, truncation=True, padding='longest', max_length=60, return_tensors="pt")
batch = tokenized_text.to(torch_device)
translated = model.generate(**batch,max_length=60,num_beams=10, num_return_sequences=num_return_sequences, temperature=1.5)
tgt_text = tokenizer.batch_decode(translated, skip_special_tokens=True)
return tgt_text
text = "In this video, I will be showing you how to build a stock price web application in Python using the Streamlit and yfinance library."
get_response(text, 5)
錯誤:
FutureWarning:
prepare_seq2seq_batch已棄用,并將在 HuggingFace Transformers 的第 5 版中洗掉。使用常規__call__方法準備您的輸入,并使用as_target_tokenizer背景關系管理器下的標記器來準備您的目標。
請幫助修復此錯誤
uj5u.com熱心網友回復:
根據這個問題,更換
batch = tokenizer.prepare_seq2seq_batch([input_text],truncation=True,padding='longest',max_length=60, return_tensors="pt").to(torch_device)
和
with tokenizer.as_target_tokenizer():
tokenized_text = tokenizer(input_text, truncation=True,padding='longest',max_length=60, return_tensors="pt")
batch = tokenized_text.to(torch_device)
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/337859.html
標籤:蟒蛇-3.x
