Views
No views yet
1import torch
2from transformers import T5ForConditionalGeneration,T5Tokenizer
3
4device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
5
6model = T5ForConditionalGeneration.from_pretrained("Michau/t5-base-en-generate-headline")
7tokenizer = T5Tokenizer.from_pretrained("Michau/t5-base-en-generate-headline")
8model = model.to(device)
9
10article = '''
11Very early yesterday morning, the United States President Donald Trump reported he and his wife First Lady Melania Trump tested positive for COVID-19. Officials said the Trumps' 14-year-old son Barron tested negative as did First Family and Senior Advisors Jared Kushner and Ivanka Trump.
12Trump took to social media, posting at 12:54 am local time (0454 UTC) on Twitter, "Tonight, [Melania] and I tested positive for COVID-19. We will begin our quarantine and recovery process immediately. We will get through this TOGETHER!" Yesterday afternoon Marine One landed on the White House's South Lawn flying Trump to Walter Reed National Military Medical Center (WRNMMC) in Bethesda, Maryland.
13Reports said both were showing "mild symptoms". Senior administration officials were tested as people were informed of the positive test. Senior advisor Hope Hicks had tested positive on Thursday.
14Presidential physician Sean Conley issued a statement saying Trump has been given zinc, vitamin D, Pepcid and a daily Aspirin. Conley also gave a single dose of the experimental polyclonal antibodies drug from Regeneron Pharmaceuticals.
15According to official statements, Trump, now operating from the WRNMMC, is to continue performing his duties as president during a 14-day quarantine. In the event of Trump becoming incapacitated, Vice President Mike Pence could take over the duties of president via the 25th Amendment of the US Constitution. The Pence family all tested negative as of yesterday and there were no changes regarding Pence's campaign events.
16'''
17
18text = "headline: " + article
19
20max_len = 256
21
22encoding = tokenizer.encode_plus(text, return_tensors = "pt")
23input_ids = encoding["input_ids"].to(device)
24attention_masks = encoding["attention_mask"].to(device)
25
26beam_outputs = model.generate(
27 input_ids = input_ids,
28 attention_mask = attention_masks,
29 max_length = 64,
30 num_beams = 3,
31 early_stopping = True,
32)
33
34result = tokenizer.decode(beam_outputs[0])
35print(result)Trump and First Lady Melania Test Positive for COVID-19