Views
No views yet
1from transformers import T5Config, T5ForConditionalGeneration, T5Tokenizer
2
3model_name = "allenai/t5-small-squad2-next-word-generator-squad"
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
14
15run_model("Which")
16run_model("Which two")
17run_model("Which two counties")
18run_model("Which two counties are")
19run_model("Which two counties are the")
20run_model("Which two counties are the biggest")
21run_model("Which two counties are the biggest economic")
22run_model("Which two counties are the biggest economic powers")
23['one']
['statements']
['are']
['in']
['most']
['in']
['zones']
['of']