human-centered-summarization
commited on
Commit
·
02b1c37
1
Parent(s):
9e47233
Update README.md
Browse files
README.md
CHANGED
@@ -27,8 +27,7 @@ pip install transformers
|
|
27 |
```
|
28 |
|
29 |
#### How to use
|
30 |
-
We provide a simple snippet of how to use this model for the task of financial summarization in Pytorch.
|
31 |
-
Tensorflow, you can also run the following code only with minor changes.
|
32 |
|
33 |
```Python
|
34 |
from transformers import PegasusTokenizer, PegasusForConditionalGeneration, TFPegasusForConditionalGeneration
|
@@ -60,6 +59,35 @@ print(tokenizer.decode(output[0], skip_special_tokens=True))
|
|
60 |
# 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
|
61 |
|
62 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
|
65 |
## Evaluation Results
|
|
|
27 |
```
|
28 |
|
29 |
#### How to use
|
30 |
+
We provide a simple snippet of how to use this model for the task of financial summarization in Pytorch.
|
|
|
31 |
|
32 |
```Python
|
33 |
from transformers import PegasusTokenizer, PegasusForConditionalGeneration, TFPegasusForConditionalGeneration
|
|
|
59 |
# 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
|
60 |
|
61 |
```
|
62 |
+
and also in Tensorflow
|
63 |
+
|
64 |
+
```Python
|
65 |
+
from transformers import PegasusTokenizer, TFPegasusForConditionalGeneration
|
66 |
+
|
67 |
+
# Let's load the model and the tokenizer
|
68 |
+
model_name = "human-centered-summarization/financial-summarization-pegasus"
|
69 |
+
tokenizer = PegasusTokenizer.from_pretrained(model_name)
|
70 |
+
model = TFPegasusForConditionalGeneration.from_pretrained(model_name)
|
71 |
+
|
72 |
+
# Some text to summarize here
|
73 |
+
text_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."
|
74 |
+
|
75 |
+
# Tokenize our text
|
76 |
+
input_ids = tokenizer(text_to_summarize, return_tensors="tf").input_ids
|
77 |
+
|
78 |
+
# Generate the output (Here, we use beam search but you can also use any other strategy you like)
|
79 |
+
output = model.generate(
|
80 |
+
input_ids,
|
81 |
+
max_length=32,
|
82 |
+
num_beams=5,
|
83 |
+
early_stopping=True
|
84 |
+
)
|
85 |
+
|
86 |
+
# Finally, we can print the generated summary
|
87 |
+
print(tokenizer.decode(output[0], skip_special_tokens=True))
|
88 |
+
# 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
|
89 |
+
|
90 |
+
|
91 |
|
92 |
|
93 |
## Evaluation Results
|