Views
No views yet
1from transformers import PegasusTokenizer, PegasusForConditionalGeneration, TFPegasusForConditionalGeneration
2
3# Let's load the model and the tokenizer
4model_name = "human-centered-summarization/financial-summarization-pegasus"
5tokenizer = PegasusTokenizer.from_pretrained(model_name)
6model = PegasusForConditionalGeneration.from_pretrained(model_name) # If you want to use the Tensorflow model
7 # just replace with TFPegasusForConditionalGeneration
8
9
10# Some text to summarize here
11text_to_summarize = "National Commercial Bank (NCB), Saudi Arabia’s largest lender by assets, agreed to buy rival Samba Financial Group for $15 billion in the biggest banking takeover this year.NCB will pay 28.45 riyals ($7.58) for each Samba share, according to a statement on Sunday, valuing it at about 55.7 billion riyals. NCB will offer 0.739 new shares for each Samba share, at the lower end of the 0.736-0.787 ratio the banks set when they signed an initial framework agreement in June.The offer is a 3.5% premium to Samba’s Oct. 8 closing price of 27.50 riyals and about 24% higher than the level the shares traded at before the talks were made public. Bloomberg News first reported the merger discussions.The new bank will have total assets of more than $220 billion, creating the Gulf region’s third-largest lender. The entity’s $46 billion market capitalization nearly matches that of Qatar National Bank QPSC, which is still the Middle East’s biggest lender with about $268 billion of assets."
12
13# Tokenize our text
14# If you want to run the code in Tensorflow, please remember to return the particular tensors as simply as using return_tensors = 'tf'
15input_ids = tokenizer(text_to_summarize, return_tensors="pt").input_ids
16
17# Generate the output (Here, we use beam search but you can also use any other strategy you like)
18output = model.generate(
19 input_ids,
20 max_length=32,
21 num_beams=5,
22 early_stopping=True
23)
24
25# Finally, we can print the generated summary
26print(tokenizer.decode(output[0], skip_special_tokens=True))
27# Generated Output: Saudi bank to pay a 3.5% premium to Samba share price. Gulf region’s third-largest lender will have total assets of $220 billion| Fine-tuning | R-1 | R-2 | R-L | R-S |
|---|---|---|---|---|
| Yes | 23.55 | 6.99 | 18.14 | 21.36 |
| No | 13.8 | 2.4 | 10.63 | 12.03 |
T. Passali, A. Gidiotis, E. Chatzikyriakidis and G. Tsoumakas. 2021. Towards Human-Centered Summarization: A Case Study on Financial News. In Proceedings of the First Workshop on Bridging Human-Computer Interaction and Natural Language Processing(pp. 21–27). Association for Computational Linguistics.
@inproceedings{passali-etal-2021-towards,
title = "Towards Human-Centered Summarization: A Case Study on Financial News",
author = "Passali, Tatiana and Gidiotis, Alexios and Chatzikyriakidis, Efstathios and Tsoumakas, Grigorios",
booktitle = "Proceedings of the First Workshop on Bridging Human{--}Computer Interaction and Natural Language Processing",
month = apr,
year = "2021",
address = "Online",
publisher = "Association for Computational Linguistics",
url = "https://www.aclweb.org/anthology/2021.hcinlp-1.4",
pages = "21--27",
}