Views
No views yet
1# Load the Model
2model = AutoModelForSeq2SeqLM.from_pretrained("JordiAb/BART_news_summarizer")
3tokenizer = AutoTokenizer.from_pretrained("JordiAb/BART_news_summarizer")
4
5# News article text
6article_text = """
7Los Angeles Lakers will have more time than anticipated. The four-time NBA Most Valuable Player (MVP) extended his contract for two years and $85 million, keeping him in California until 2023. In 2018, The King had already signed for 153 mdd and, in his second campaign in the quintet, led the championship in the Orlando bubble. With 35 years of life – he turns 36 on December 30 – and 17 campaigns of experience, LeBron is still considered one of the best (or the best) NBA players. You can read: "Mercedes found Lewis Hamilton\'s substitute" James just took the Lakers to his first NBA title since 2010 and was named MVP of the Finals; he led the League in assists per game (10.2) for the first time in his career, while adding 25.3 points and 7.8 rebounds per performance, during the last campaign. James has adapted to life in Hollywood, as he will be part of the sequel to Space Jam, to be released next year.
8"""
9
10# tokenize text
11inputs = tokenizer(article_text, return_tensors='pt')
12# generate summary
13with torch.no_grad():
14 summary_ids = model.generate(
15 inputs['input_ids'],
16 num_beams=4,
17 max_length=250,
18 early_stopping=True
19 )
20# decode summary
21summary = tokenizer.decode(
22 summary_ids[0],
23 skip_special_tokens=True
24)