http-server / inference.py
Ron Au
Initial Commit
abf9047
raw
history blame
368 Bytes
from transformers import T5Tokenizer, T5ForConditionalGeneration
tokenizer = T5Tokenizer.from_pretrained("t5-small")
model = T5ForConditionalGeneration.from_pretrained("t5-small")
def t5_infer(input):
input_ids = tokenizer(input, return_tensors="pt").input_ids
outputs = model.generate(input_ids)
return tokenizer.decode(outputs[0], skip_special_tokens=True)