Views
No views yet
1from transformers import T5Config, T5ForConditionalGeneration, T5Tokenizer
2
3model_name = "allenai/t5-small-next-word-generator-qoogle"
4tokenizer = T5Tokenizer.from_pretrained(model_name)
5model = T5ForConditionalGeneration.from_pretrained(model_name)
6
7def run_model(input_string, **generator_args):
8 input_ids = tokenizer.encode(input_string, return_tensors="pt")
9 res = model.generate(input_ids, **generator_args)
10 output = tokenizer.batch_decode(res, skip_special_tokens=True)
11 print(output)
12 return output
13
14run_model("Who is the winner of 2009 olympics? \n Jack and Jill participated, but James won the games.")```
15which should result in the following: