agbejar parquet-converter commited on
Commit
ee6ead5
·
0 Parent(s):

Duplicate from takala/financial_phrasebank

Browse files

Co-authored-by: Parquet-converter (BOT) <parquet-converter@users.noreply.huggingface.co>

.gitattributes ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bin.* filter=lfs diff=lfs merge=lfs -text
5
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.model filter=lfs diff=lfs merge=lfs -text
12
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
13
+ *.onnx filter=lfs diff=lfs merge=lfs -text
14
+ *.ot filter=lfs diff=lfs merge=lfs -text
15
+ *.parquet filter=lfs diff=lfs merge=lfs -text
16
+ *.pb filter=lfs diff=lfs merge=lfs -text
17
+ *.pt filter=lfs diff=lfs merge=lfs -text
18
+ *.pth filter=lfs diff=lfs merge=lfs -text
19
+ *.rar filter=lfs diff=lfs merge=lfs -text
20
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
21
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
22
+ *.tflite filter=lfs diff=lfs merge=lfs -text
23
+ *.tgz filter=lfs diff=lfs merge=lfs -text
24
+ *.xz filter=lfs diff=lfs merge=lfs -text
25
+ *.zip filter=lfs diff=lfs merge=lfs -text
26
+ *.zstandard filter=lfs diff=lfs merge=lfs -text
27
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,301 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ annotations_creators:
3
+ - expert-generated
4
+ language_creators:
5
+ - found
6
+ language:
7
+ - en
8
+ license:
9
+ - cc-by-nc-sa-3.0
10
+ multilinguality:
11
+ - monolingual
12
+ size_categories:
13
+ - 1K<n<10K
14
+ source_datasets:
15
+ - original
16
+ task_categories:
17
+ - text-classification
18
+ task_ids:
19
+ - multi-class-classification
20
+ - sentiment-classification
21
+ pretty_name: FinancialPhrasebank
22
+ dataset_info:
23
+ - config_name: sentences_allagree
24
+ features:
25
+ - name: sentence
26
+ dtype: string
27
+ - name: label
28
+ dtype:
29
+ class_label:
30
+ names:
31
+ '0': negative
32
+ '1': neutral
33
+ '2': positive
34
+ splits:
35
+ - name: train
36
+ num_bytes: 303371
37
+ num_examples: 2264
38
+ download_size: 681890
39
+ dataset_size: 303371
40
+ - config_name: sentences_75agree
41
+ features:
42
+ - name: sentence
43
+ dtype: string
44
+ - name: label
45
+ dtype:
46
+ class_label:
47
+ names:
48
+ '0': negative
49
+ '1': neutral
50
+ '2': positive
51
+ splits:
52
+ - name: train
53
+ num_bytes: 472703
54
+ num_examples: 3453
55
+ download_size: 681890
56
+ dataset_size: 472703
57
+ - config_name: sentences_66agree
58
+ features:
59
+ - name: sentence
60
+ dtype: string
61
+ - name: label
62
+ dtype:
63
+ class_label:
64
+ names:
65
+ '0': negative
66
+ '1': neutral
67
+ '2': positive
68
+ splits:
69
+ - name: train
70
+ num_bytes: 587152
71
+ num_examples: 4217
72
+ download_size: 681890
73
+ dataset_size: 587152
74
+ - config_name: sentences_50agree
75
+ features:
76
+ - name: sentence
77
+ dtype: string
78
+ - name: label
79
+ dtype:
80
+ class_label:
81
+ names:
82
+ '0': negative
83
+ '1': neutral
84
+ '2': positive
85
+ splits:
86
+ - name: train
87
+ num_bytes: 679240
88
+ num_examples: 4846
89
+ download_size: 681890
90
+ dataset_size: 679240
91
+ tags:
92
+ - finance
93
+ ---
94
+
95
+ # Dataset Card for financial_phrasebank
96
+
97
+ ## Table of Contents
98
+ - [Dataset Description](#dataset-description)
99
+ - [Dataset Summary](#dataset-summary)
100
+ - [Supported Tasks and Leaderboards](#supported-tasks-and-leaderboards)
101
+ - [Languages](#languages)
102
+ - [Dataset Structure](#dataset-structure)
103
+ - [Data Instances](#data-instances)
104
+ - [Data Fields](#data-fields)
105
+ - [Data Splits](#data-splits)
106
+ - [Dataset Creation](#dataset-creation)
107
+ - [Curation Rationale](#curation-rationale)
108
+ - [Source Data](#source-data)
109
+ - [Annotations](#annotations)
110
+ - [Personal and Sensitive Information](#personal-and-sensitive-information)
111
+ - [Considerations for Using the Data](#considerations-for-using-the-data)
112
+ - [Social Impact of Dataset](#social-impact-of-dataset)
113
+ - [Discussion of Biases](#discussion-of-biases)
114
+ - [Other Known Limitations](#other-known-limitations)
115
+ - [Additional Information](#additional-information)
116
+ - [Dataset Curators](#dataset-curators)
117
+ - [Licensing Information](#licensing-information)
118
+ - [Citation Information](#citation-information)
119
+ - [Contributions](#contributions)
120
+
121
+ ## Dataset Description
122
+
123
+ - **Homepage:** [Kaggle](https://www.kaggle.com/ankurzing/sentiment-analysis-for-financial-news) [ResearchGate](https://www.researchgate.net/publication/251231364_FinancialPhraseBank-v10)
124
+ - **Repository:**
125
+ - **Paper:** [Arxiv](https://arxiv.org/abs/1307.5336)
126
+ - **Leaderboard:** [Kaggle](https://www.kaggle.com/ankurzing/sentiment-analysis-for-financial-news/code) [PapersWithCode](https://paperswithcode.com/sota/sentiment-analysis-on-financial-phrasebank) =
127
+ - **Point of Contact:** [Pekka Malo](mailto:pekka.malo@aalto.fi) [Ankur Sinha](mailto:ankur.sinha@aalto.fi)
128
+
129
+ ### Dataset Summary
130
+
131
+ Polar sentiment dataset of sentences from financial news. The dataset consists of 4840 sentences from English language financial news categorised by sentiment. The dataset is divided by agreement rate of 5-8 annotators.
132
+
133
+ ### Supported Tasks and Leaderboards
134
+
135
+ Sentiment Classification
136
+
137
+ ### Languages
138
+
139
+ English
140
+
141
+ ## Dataset Structure
142
+
143
+ ### Data Instances
144
+
145
+ ```
146
+ { "sentence": "Pharmaceuticals group Orion Corp reported a fall in its third-quarter earnings that were hit by larger expenditures on R&D and marketing .",
147
+ "label": "negative"
148
+ }
149
+ ```
150
+
151
+ ### Data Fields
152
+ Each example contains:
153
+ - sentence: a tokenized line from the dataset
154
+ - label: a label corresponding to the class as a string: 'positive', 'negative' or 'neutral'
155
+
156
+ ### Data Splits
157
+ There's no train/validation/test split.
158
+
159
+ However the dataset is available in four possible configurations depending on the percentage of agreement of annotators:
160
+
161
+ - `sentences_50agree`; Number of instances with >=50% annotator agreement: 4846
162
+ - `sentences_66agree`: Number of instances with >=66% annotator agreement: 4217
163
+ - `sentences_75agree`: Number of instances with >=75% annotator agreement: 3453
164
+ - `sentences_allagree`: Number of instances with 100% annotator agreement: 2264
165
+
166
+ ### Usage
167
+
168
+ ```python
169
+ from datasets import load_dataset
170
+
171
+ # Load the highest-agreement configuration
172
+ ds = load_dataset("takala/financial_phrasebank", "sentences_allagree")
173
+
174
+ print(ds)
175
+ print(ds["train"][0])
176
+ ```
177
+
178
+ Other configurations (e.g. `sentences_75agree`, `sentences_66agree`) can be loaded by changing the second argument.
179
+
180
+ ## Quick baseline (Transformers)
181
+
182
+ ```python
183
+ from datasets import load_dataset
184
+ from transformers import pipeline
185
+
186
+ ds = load_dataset("takala/financial_phrasebank", "sentences_allagree")["train"]
187
+ clf = pipeline("text-classification", model="distilbert-base-uncased-finetuned-sst-2-english")
188
+
189
+ print(ds[0]["sentence"])
190
+ print(clf(ds[0]["sentence"]))
191
+ ```
192
+
193
+ ## Dataset Creation
194
+
195
+ ### Curation Rationale
196
+
197
+ The key arguments for the low utilization of statistical techniques in
198
+ financial sentiment analysis have been the difficulty of implementation for
199
+ practical applications and the lack of high quality training data for building
200
+ such models. Especially in the case of finance and economic texts, annotated
201
+ collections are a scarce resource and many are reserved for proprietary use
202
+ only. To resolve the missing training data problem, we present a collection of
203
+ ∼ 5000 sentences to establish human-annotated standards for benchmarking
204
+ alternative modeling techniques.
205
+
206
+ The objective of the phrase level annotation task was to classify each example
207
+ sentence into a positive, negative or neutral category by considering only the
208
+ information explicitly available in the given sentence. Since the study is
209
+ focused only on financial and economic domains, the annotators were asked to
210
+ consider the sentences from the view point of an investor only; i.e. whether
211
+ the news may have positive, negative or neutral influence on the stock price.
212
+ As a result, sentences which have a sentiment that is not relevant from an
213
+ economic or financial perspective are considered neutral.
214
+
215
+ ### Source Data
216
+
217
+ #### Initial Data Collection and Normalization
218
+
219
+ The corpus used in this paper is made out of English news on all listed
220
+ companies in OMX Helsinki. The news has been downloaded from the LexisNexis
221
+ database using an automated web scraper. Out of this news database, a random
222
+ subset of 10,000 articles was selected to obtain good coverage across small and
223
+ large companies, companies in different industries, as well as different news
224
+ sources. Following the approach taken by Maks and Vossen (2010), we excluded
225
+ all sentences which did not contain any of the lexicon entities. This reduced
226
+ the overall sample to 53,400 sentences, where each has at least one or more
227
+ recognized lexicon entity. The sentences were then classified according to the
228
+ types of entity sequences detected. Finally, a random sample of ∼5000 sentences
229
+ was chosen to represent the overall news database.
230
+
231
+ #### Who are the source language producers?
232
+
233
+ The source data was written by various financial journalists.
234
+
235
+ ### Annotations
236
+
237
+ #### Annotation process
238
+
239
+ This release of the financial phrase bank covers a collection of 4840
240
+ sentences. The selected collection of phrases was annotated by 16 people with
241
+ adequate background knowledge on financial markets.
242
+
243
+ Given the large number of overlapping annotations (5 to 8 annotations per
244
+ sentence), there are several ways to define a majority vote based gold
245
+ standard. To provide an objective comparison, we have formed 4 alternative
246
+ reference datasets based on the strength of majority agreement:
247
+
248
+ #### Who are the annotators?
249
+
250
+ Three of the annotators were researchers and the remaining 13 annotators were
251
+ master's students at Aalto University School of Business with majors primarily
252
+ in finance, accounting, and economics.
253
+
254
+ ### Personal and Sensitive Information
255
+
256
+ [More Information Needed]
257
+
258
+ ## Considerations for Using the Data
259
+
260
+ ### Social Impact of Dataset
261
+
262
+ [More Information Needed]
263
+
264
+ ### Discussion of Biases
265
+
266
+ All annotators were from the same institution and so interannotator agreement
267
+ should be understood with this taken into account.
268
+
269
+ ### Other Known Limitations
270
+
271
+ [More Information Needed]
272
+
273
+ ## Additional Information
274
+
275
+ ### Dataset Curators
276
+
277
+ [More Information Needed]
278
+
279
+ ### Licensing Information
280
+
281
+ This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/.
282
+
283
+ If you are interested in commercial use of the data, please contact the following authors for an appropriate license:
284
+ - [Pekka Malo](mailto:pekka.malo@aalto.fi)
285
+ - [Ankur Sinha](mailto:ankur.sinha@aalto.fi)
286
+
287
+ ### Citation Information
288
+
289
+ ```
290
+ @article{Malo2014GoodDO,
291
+ title={Good debt or bad debt: Detecting semantic orientations in economic texts},
292
+ author={P. Malo and A. Sinha and P. Korhonen and J. Wallenius and P. Takala},
293
+ journal={Journal of the Association for Information Science and Technology},
294
+ year={2014},
295
+ volume={65}
296
+ }
297
+ ```
298
+
299
+ ### Contributions
300
+
301
+ Thanks to [@frankier](https://github.com/frankier) for adding this dataset.
data/FinancialPhraseBank-v1.0.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0e1a06c4900fdae46091d031068601e3773ba067c7cecb5b0da1dcba5ce989a6
3
+ size 681890
financial_phrasebank.py ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ """Financial Phrase Bank v1.0: Polar sentiment dataset of sentences from
17
+ financial news. The dataset consists of 4840 sentences from English language
18
+ financial news categorised by sentiment. The dataset is divided by agreement
19
+ rate of 5-8 annotators."""
20
+
21
+
22
+ import os
23
+
24
+ import datasets
25
+
26
+
27
+ _CITATION = """\
28
+ @article{Malo2014GoodDO,
29
+ title={Good debt or bad debt: Detecting semantic orientations in economic texts},
30
+ author={P. Malo and A. Sinha and P. Korhonen and J. Wallenius and P. Takala},
31
+ journal={Journal of the Association for Information Science and Technology},
32
+ year={2014},
33
+ volume={65}
34
+ }
35
+ """
36
+
37
+ _DESCRIPTION = """\
38
+ The key arguments for the low utilization of statistical techniques in
39
+ financial sentiment analysis have been the difficulty of implementation for
40
+ practical applications and the lack of high quality training data for building
41
+ such models. Especially in the case of finance and economic texts, annotated
42
+ collections are a scarce resource and many are reserved for proprietary use
43
+ only. To resolve the missing training data problem, we present a collection of
44
+ ∼ 5000 sentences to establish human-annotated standards for benchmarking
45
+ alternative modeling techniques.
46
+
47
+ The objective of the phrase level annotation task was to classify each example
48
+ sentence into a positive, negative or neutral category by considering only the
49
+ information explicitly available in the given sentence. Since the study is
50
+ focused only on financial and economic domains, the annotators were asked to
51
+ consider the sentences from the view point of an investor only; i.e. whether
52
+ the news may have positive, negative or neutral influence on the stock price.
53
+ As a result, sentences which have a sentiment that is not relevant from an
54
+ economic or financial perspective are considered neutral.
55
+
56
+ This release of the financial phrase bank covers a collection of 4840
57
+ sentences. The selected collection of phrases was annotated by 16 people with
58
+ adequate background knowledge on financial markets. Three of the annotators
59
+ were researchers and the remaining 13 annotators were master’s students at
60
+ Aalto University School of Business with majors primarily in finance,
61
+ accounting, and economics.
62
+
63
+ Given the large number of overlapping annotations (5 to 8 annotations per
64
+ sentence), there are several ways to define a majority vote based gold
65
+ standard. To provide an objective comparison, we have formed 4 alternative
66
+ reference datasets based on the strength of majority agreement: all annotators
67
+ agree, >=75% of annotators agree, >=66% of annotators agree and >=50% of
68
+ annotators agree.
69
+ """
70
+
71
+ _HOMEPAGE = "https://www.kaggle.com/ankurzing/sentiment-analysis-for-financial-news"
72
+
73
+ _LICENSE = "Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License"
74
+
75
+ _REPO = "https://huggingface.co/datasets/financial_phrasebank/resolve/main/data"
76
+ _URL = f"{_REPO}/FinancialPhraseBank-v1.0.zip"
77
+
78
+
79
+ _VERSION = datasets.Version("1.0.0")
80
+
81
+
82
+ class FinancialPhraseBankConfig(datasets.BuilderConfig):
83
+ """BuilderConfig for FinancialPhraseBank."""
84
+
85
+ def __init__(
86
+ self,
87
+ split,
88
+ **kwargs,
89
+ ):
90
+ """BuilderConfig for Discovery.
91
+ Args:
92
+ filename_bit: `string`, the changing part of the filename.
93
+ """
94
+
95
+ super(FinancialPhraseBankConfig, self).__init__(name=f"sentences_{split}agree", version=_VERSION, **kwargs)
96
+
97
+ self.path = os.path.join("FinancialPhraseBank-v1.0", f"Sentences_{split.title()}Agree.txt")
98
+
99
+
100
+ class FinancialPhrasebank(datasets.GeneratorBasedBuilder):
101
+
102
+ BUILDER_CONFIGS = [
103
+ FinancialPhraseBankConfig(
104
+ split="all",
105
+ description="Sentences where all annotators agreed",
106
+ ),
107
+ FinancialPhraseBankConfig(split="75", description="Sentences where at least 75% of annotators agreed"),
108
+ FinancialPhraseBankConfig(split="66", description="Sentences where at least 66% of annotators agreed"),
109
+ FinancialPhraseBankConfig(split="50", description="Sentences where at least 50% of annotators agreed"),
110
+ ]
111
+
112
+ def _info(self):
113
+ return datasets.DatasetInfo(
114
+ description=_DESCRIPTION,
115
+ features=datasets.Features(
116
+ {
117
+ "sentence": datasets.Value("string"),
118
+ "label": datasets.features.ClassLabel(
119
+ names=[
120
+ "negative",
121
+ "neutral",
122
+ "positive",
123
+ ]
124
+ ),
125
+ }
126
+ ),
127
+ supervised_keys=None,
128
+ homepage=_HOMEPAGE,
129
+ license=_LICENSE,
130
+ citation=_CITATION,
131
+ )
132
+
133
+ def _split_generators(self, dl_manager):
134
+ """Returns SplitGenerators."""
135
+ data_dir = dl_manager.download_and_extract(_URL)
136
+ return [
137
+ datasets.SplitGenerator(
138
+ name=datasets.Split.TRAIN,
139
+ # These kwargs will be passed to _generate_examples
140
+ gen_kwargs={"filepath": os.path.join(data_dir, self.config.path)},
141
+ ),
142
+ ]
143
+
144
+ def _generate_examples(self, filepath):
145
+ """Yields examples."""
146
+ with open(filepath, encoding="iso-8859-1") as f:
147
+ for id_, line in enumerate(f):
148
+ sentence, label = line.rsplit("@", 1)
149
+ yield id_, {"sentence": sentence, "label": label}