Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
551 B
2
Indexable
Never
!pip install transformers
from transformers import BlenderbotTokenizer, BlenderbotForConditionalGeneration

%%time
mname = "facebook/blenderbot-400M-distill"
model = BlenderbotForConditionalGeneration.from_pretrained(mname)
tokenizer = BlenderbotTokenizer.from_pretrained(mname)

def infer(question, tozenizer, model):
  inputs = inputs = tokenizer([question], return_tensors="pt")
  answer = model.generate(**inputs)
  return tokenizer.batch_decode(answer)[0]

%%time
print(infer('My friends are cool but they eat too many carbs.', tokenizer, model))