omidvaramin commited on
Commit
6a65c56
·
1 Parent(s): e1cacc1

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +119 -0
README.md ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ # For reference on model card metadata, see the spec: https://github.com/huggingface/hub-docs/blob/main/modelcard.md?plain=1
3
+ # Doc / guide: https://huggingface.co/docs/hub/model-cards
4
+ {}
5
+ ---
6
+
7
+ # Model Card for Ht5-small
8
+
9
+ <!-- Provide a quick summary of what the model is/does. -->
10
+
11
+ This model is a fine-tuned version of [t5-small](https://huggingface.co/t5-small) on Newsroom dataset to generate news headlines. To ask model to generate headliens
12
+ "Headline: " should be appended to the beginning of the article.
13
+
14
+ ## Intended uses & limitations
15
+ You can use this model for headline generation task on English news articles.
16
+
17
+ ### Usage
18
+ ```python
19
+
20
+ article = """Two of the OPEC oil cartel’s 11 members, Nigeria and Venezuela, said today \
21
+ that they would voluntarily cut production in response to declining crude oil prices, which \
22
+ have fallen 20 percent from their peak two months ago.
23
+ The move, which would take less than 200,000 barrels of oil a day off the market, follows days \
24
+ of mixed signals from some OPEC officials, who have voiced increasing concern about the rapid \
25
+ drop in prices. Nigeria’s oil minister, Edmund Daukoru, who is president of OPEC this year, \
26
+ recently said the price of oil was very low.
27
+ Nigeria and Venezuela, which have generally been price hawks within the group, said their decision \
28
+ to cut production grew out of an informal deal reached at OPEC’s last meeting, earlier this month, \
29
+ to pare output if prices fell steeply. Some OPEC representatives have grown anxious at the slide in \
30
+ the oil futures markets, where prices for benchmark contracts have fallen from a midsummer high of \
31
+ $77.03 a barrel.
32
+ But traders shrugged off the announcement of the production cuts today. On the New York Mercantile \
33
+ Exchange, the most widely watched contract price light, low-sulfur crude for delivery next month \
34
+ traded this afternoon at $62.30 a barrel, down 0.7 percent.
35
+ Mr. Daukoru has been in contact with other OPEC ministers to discuss prices, which on Monday briefly \
36
+ slipped below $60 a barrel for the first time in six months. But the Organization of the Petroleum \
37
+ Exporting Countries, as the cartel is formally known, denied any shift in policy.
38
+ We are not currently concerned, a delegate from one of OPECs Gulf members said. The prices are \
39
+ currently manageable and fair. We are not overly alarmed by the prices. It is not a cause for alarm. \
40
+ It's the market working.
41
+ It is not unusual for oil prices to fall after Labor Day and the conclusion of the summer travel season. \
42
+ Demand tends to slow in the third quarter, and refiners reduce their output for seasonal maintenance; \
43
+ consumption picks up again with the first winter cold in the Western Hemisphere, and prices sometimes do as well.
44
+ We are not going to push extra oil in the market or force it down our customers throats, we just respond to demand, \
45
+ the delegate from the Gulf said.
46
+ Still, contradictory statements from senior OPEC representatives have sown doubt about the oil cartel's strategy. \
47
+ Whether OPEC countries actually reduce their output or not, the mixed messages have at least succeeded in one way: \
48
+ oil traders have been persuaded that OPEC is willing to step in to defend prices, and have traded on that belief, \
49
+ slowing the recent price decline.
50
+ While apparently fanciful, reports of an imminent output cut reflect two hard facts: stocks are building faster than \
51
+ expected, and several producers have an incredibly low pain threshold when it comes to price drops, Antoine Halff, an \
52
+ energy analyst with Fimat, wrote in a note to clients today. “However, more price declines will likely be needed before \
53
+ OPEC producers decide on any coordinated move.
54
+ Venezuela, which pumps about 2.5 million barrels a day, said it would cut its daily output by 50,000 barrels, or about 2 \
55
+ percent, starting Oct. 1. Nigeria said it would trim its exports by 5 percent on the same date, a reduction of about \
56
+ 120,000 barrels a day from its current output of about 3.8 million barrels a day.
57
+ They are trying to influence the psychology of the market, said Larry Goldstein, a veteran oil analyst and the president \
58
+ of the Petroleum Industry Research Foundation in New York. Although they are reacting to the reduction in demand, they \
59
+ are trying to convince the market that they are actually anticipating it, by making cuts ahead of the market. But they \
60
+ are simply reacting to it, which is how markets should operate."""
61
+
62
+ import transformers
63
+ import os
64
+ import torch
65
+ os.environ["CUDA_VISIBLE_DEVICES"]="5"
66
+ from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
67
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
68
+ print(device)
69
+
70
+ #appending the task identifier to the beginning of input
71
+ article = "Headline: " + article
72
+
73
+ model = AutoModelForSeq2SeqLM.from_pretrained("omidvaramin/HBART").to(device)
74
+ tokenizer = AutoTokenizer.from_pretrained("omidvaramin/HBART")
75
+ #encodign article using tokenizer
76
+ encoding = tokenizer(article
77
+ , max_length=1024
78
+ , truncation=True
79
+ ,return_tensors="pt"
80
+ ,padding='longest')
81
+
82
+ input_ids = encoding['input_ids']
83
+ attention_masks = encoding['attention_mask']
84
+
85
+ #transfering the data into GPU
86
+ input_ids = input_ids.to(device)
87
+ attention_masks = attention_masks.to(device)
88
+
89
+
90
+ #generate headlines using kbeam technique
91
+ beam_outputs = model.generate(
92
+ input_ids = input_ids,
93
+ attention_mask = attention_masks
94
+ ,do_sample = False
95
+ ,num_beams = 4
96
+ ,max_length = 20
97
+ ,min_length = 1
98
+ ,num_return_sequences = 1
99
+ )
100
+
101
+ result = tokenizer.batch_decode(beam_outputs,
102
+ skip_special_tokens=True)
103
+ print(result[0])
104
+ >>> [{'OPEC Members Say They Will Cut Oil Production'}]
105
+ ```
106
+
107
+ ### BibTeX entry and citation info
108
+
109
+ ```bibtex
110
+ @ARTICLE{10154027,
111
+ author={Omidvar, Amin and An, Aijun},
112
+ journal={IEEE Access},
113
+ title={Learning to Generate Popular Headlines},
114
+ year={2023},
115
+ volume={11},
116
+ number={},
117
+ pages={60904-60914},
118
+ doi={10.1109/ACCESS.2023.3286853}}
119
+