Click here to Skip to main content
15,900,378 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Whenever I try to run the following script:
Python
from transformers import *

model = PegasusForConditionalGeneration.from_pretrained("tuner007/pegasus_paraphrase")
tokenizer = PegasusTokenizerFast.from_pretrained("tuner007/pegasus_paraphrase")
def get_paraphrased_sentences(model, tokenizer, sentence, num_return_sequences=5, num_beams=5):
    inputs = tokenizer([sentence], truncation=True, padding="longest", return_tensors="pt")
    outputs = model.generate(**inputs, num_beams=num_beams, num_return_sequences=num_return_sequences,)
    return tokenizer.batch_decode(outputs, skip_special_tokens=True)

sentence = "Learning is the progress of acquiring new understanding, knowledge, behaviors, skills, values, attitudes, and preferences."
get_paraphrased_sentences(model, tokenizer, sentence, num_beams=10, num_return_sequences=10)

It returns me with the following error:
2022-01-31 01:36:51.328822: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_100.dll
Traceback (most recent call last):
  File "text_paraphraser.py", line 4, in <module>
    model = PegasusForConditionalGeneration.from_pretrained("tuner007/pegasus_paraphrase")
NameError: name 'PegasusForConditionalGeneration' is not defined

I am running this in a virtual environment inside of Anaconda if that helps, I don't have the right version of Python on my real desktop to download sentencepiece

What I have tried:

I followed the tutorial on thepythoncode.com, double-checking multiple times.
Posted
Updated 30-Jan-22 18:27pm

1 solution

Take a fresh git and try the following in your code
mname = "tuner007/pegasus_paraphrase"
model = PegasusForConditionalGeneration.from_pretrained(mname)
For more information you can check the code:
Pegasus[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900