Views
No views yet
1from transformers import T5ForConditionalGeneration
2from transformers import T5TokenizerFast as T5Tokenizer
3model = "svjack/summary-dialogue-eng"
4device = "cpu"
5tokenizer = T5Tokenizer.from_pretrained(model)
6model = T5ForConditionalGeneration.from_pretrained(model).to(device).eval()
7
8prompt = "The Wisconsin Territorial Centennial half dollar was designed by David Parsons and Benjamin Hawkins and minted by the United States Bureau of the Mint in 1936. The obverse (pictured) depicts a pick axe and lead ore, referring to the lead mining in early Wisconsin"
9prompt = "{}\nCandidates:Tom Jack".format(prompt)
10
11encode = tokenizer(prompt, return_tensors='pt').to(device)
12answer = model.generate(encode.input_ids,
13 max_length = 128,
14 num_beams=2,
15 top_p = 0.95,
16 top_k = 50,
17 repetition_penalty = 2.5,
18 length_penalty=1.0,
19 early_stopping=True,
20 )[0]
21decoded = tokenizer.decode(answer, skip_special_tokens=True)
22decoded.replace("Tom:", "\n").replace("Jack:", "\n").split("\n")1['',
2 ' Have you seen the Wisconsin Territorial Centennial half dollar? ',
3 ' Yeah, it was designed by David Parsons and Benjamin Hawkins. ',
4 ' What is it? ',
5 " It's a half dollar with a pick axe and lead ore. ",
6 " That's great!"]