0

Getting the error "TypeError: 'NoneType' object is not callable", even after running "pip install sentencepiece".

TypeError                                 Traceback (most recent call last)
<ipython-input-10-388b02906732> in <module>
      3 model_name = 'tuner007/pegasus_paraphrase'
      4 torch_device = 'cuda' if torch.cuda.is_available() else 'cpu'
----> 5 tokenizer = PegasusTokenizer.from_pretrained(model_name)
      6 model = PegasusForConditionalGeneration.from_pretrained(model_name).to(torch_device)
      7 

TypeError: 'NoneType' object is not callable
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,num_beams):
  batch = tokenizer([input_text],truncation=True,padding='longest',max_length=60, return_tensors="pt").to(torch_device)
  translated = model.generate(**batch,max_length=60,num_beams=num_beams, num_return_sequences=num_return_sequences, temperature=1.5)
  tgt_text = tokenizer.batch_decode(translated, skip_special_tokens=True)
  return tgt_text

Issue seems to be in the bold line.

  • Just for the record, since the code after the problematic line isn't called, you can remove it from a [mcve]. That said, `PegasusTokenizer` looks like a class name. You usually don't interact with classes though but with _instances_ of classes. Check whatever tutorial you're working from. – Ulrich Eckhardt Dec 14 '22 at 07:37

0 Answers0