alexcadillon commited on
Commit
b3347c4
·
1 Parent(s): a453cb3

Upload 9 files

Browse files
ABSA16_Laptops_Train_English_SB2.xml ADDED
The diff for this file is too large to render. See raw diff
 
ABSA16_Laptops_Train_SB1_v2.xml ADDED
The diff for this file is too large to render. See raw diff
 
ABSA16_Restaurants_Train_English_SB2.xml ADDED
The diff for this file is too large to render. See raw diff
 
ABSA16_Restaurants_Train_SB1_v2.xml ADDED
The diff for this file is too large to render. See raw diff
 
EN_LAPT_SB1_TEST_.xml.gold ADDED
The diff for this file is too large to render. See raw diff
 
EN_LAPT_SB2_TEST.xml.gold ADDED
The diff for this file is too large to render. See raw diff
 
EN_REST_SB1_TEST.xml.gold ADDED
The diff for this file is too large to render. See raw diff
 
EN_REST_SB2_TEST.xml.gold ADDED
The diff for this file is too large to render. See raw diff
 
SemEval2016Task5.py ADDED
@@ -0,0 +1,262 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ # TODO: Address all TODOs and remove all explanatory comments
15
+ """TODO: Add a description here."""
16
+
17
+
18
+ import xml.etree.ElementTree as ET
19
+ import os
20
+
21
+ import datasets
22
+ import datasets.features.features
23
+ from datasets import ClassLabel
24
+
25
+
26
+ _CITATION = """\
27
+ @inproceedings{pontiki-etal-2016-semeval,
28
+ title = "{S}em{E}val-2016 Task 5: Aspect Based Sentiment Analysis",
29
+ author = {Pontiki, Maria and Galanis, Dimitris and Papageorgiou, Haris and Androutsopoulos, Ion and Manandhar, Suresh and AL-Smadi, Mohammad and Al-Ayyoub, Mahmoud and Zhao, Yanyan and Qin, Bing and De Clercq, Orphée and Hoste, Véronique and Apidianaki, Marianna and Tannier, Xavier and Loukachevitch, Natalia and Kotelnikov, Evgeniy and Bel, Nuria and Jiménez-Zafra, Salud María and Eryiğit, Gülşen},
30
+ booktitle = "Proceedings of the 10th International Workshop on Semantic Evaluation ({S}em{E}val-2016)",
31
+ month = jun,
32
+ year = "2016",
33
+ address = "San Diego, California",
34
+ publisher = "Association for Computational Linguistics",
35
+ url = "https://aclanthology.org/S16-1002",
36
+ doi = "10.18653/v1/S16-1002",
37
+ pages = "19--30",
38
+ }
39
+ """
40
+
41
+ _DESCRIPTION = """\
42
+ These are the datasets for Aspect Based Sentiment Analysis (ABSA), Task 5 of SemEval-2016.
43
+ """
44
+
45
+ _HOMEPAGE = "https://alt.qcri.org/semeval2016/task5/index.php?id=data-and-tools"
46
+
47
+ # TODO: Add the licence for the dataset here if you can find it
48
+ _LICENSE = ""
49
+
50
+ # TODO: Add link to the official dataset URLs here
51
+ # The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
52
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
53
+ _URLS = {
54
+ "restaurants": {
55
+ "train": {
56
+ "SB1": "ABSA16_Restaurants_Train_SB1_v2.xml",
57
+ "SB2": "ABSA16_Restaurants_Train_English_SB2.xml"
58
+ },
59
+ "test": {
60
+ "SB1": "EN_REST_SB1_TEST.xml.gold",
61
+ "SB2": "EN_REST_SB2_TEST.xml.gold"
62
+ }
63
+ },
64
+ "laptops": {
65
+ "train": {
66
+ "SB1": "ABSA16_Laptops_Train_SB1_v2.xml",
67
+ "SB2": "ABSA16_Laptops_Train_English_SB2.xml"
68
+ },
69
+ "test": {
70
+ "SB1": "EN_LAPT_SB1_TEST.xml.gold",
71
+ "SB2": "EN_LAPT_SB2_TEST.xml.gold"
72
+ }
73
+ },
74
+ }
75
+
76
+
77
+ class SemEval2016Task5(datasets.GeneratorBasedBuilder):
78
+ """These are the datasets for Aspect Based Sentiment Analysis (ABSA), Task 5 of SemEval-2016."""
79
+
80
+ VERSION = datasets.Version("1.1.0")
81
+
82
+ # This is an example of a dataset with multiple configurations.
83
+ # If you don't want/need to define several sub-sets in your dataset,
84
+ # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
85
+
86
+ # If you need to make complex sub-parts in the datasets with configurable options
87
+ # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
88
+ # BUILDER_CONFIG_CLASS = MyBuilderConfig
89
+
90
+ # You will be able to load one or the other configurations in the following list with
91
+ # data = datasets.load_dataset('my_dataset', 'first_domain')
92
+ # data = datasets.load_dataset('my_dataset', 'second_domain')
93
+ BUILDER_CONFIGS = [
94
+ datasets.BuilderConfig(name="restaurants", version=VERSION, description="Restaurant reviews"),
95
+ datasets.BuilderConfig(name="laptops", version=VERSION, description="Laptop reviews"),
96
+ ]
97
+
98
+ # DEFAULT_CONFIG_NAME = "first_domain" # It's not mandatory to have a default configuration. Just use one if it make sense.
99
+
100
+ def _info(self):
101
+ # TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
102
+ categories = {
103
+ "restaurants": {
104
+ "entities": ["RESTAURANT", "FOOD", "DRINKS", "AMBIENCE", "SERVICE", "LOCATION"],
105
+ "attributes": ["GENERAL", "PRICES", "QUALITY", "STYLE_OPTIONS", "MISCELLANEOUS"]
106
+ },
107
+ "laptops": {
108
+ "entities": ["LAPTOP", "DISPLAY", "KEYBOARD", "MOUSE", "MOTHERBOARD", "CPU", "FANS_COOLING", "PORTS",
109
+ "MEMORY", "POWER_SUPPLY", "OPTICAL_DRIVES", "BATTERY", "GRAPHICS", "HARD_DISC",
110
+ "MULTIMEDIA_DEVICES", "HARDWARE", "SOFTWARE", "OS", "WARRANTY", "SHIPPING", "SUPPORT",
111
+ "COMPANY"],
112
+ "attributes": ["GENERAL", "PRICE", "QUALITY", "OPERATION_PERFORMANCE", "USABILITY", "DESIGN_FEATURES",
113
+ "PORTABILITY", "CONNECTIVITY", "MISCELLANEOUS"]
114
+ },
115
+ "hotels": {
116
+ "entities": ["HOTEL", "ROOMS", "FACILITIES", "ROOMS_AMENITIES", "SERVICE", "LOCATION", "FOOD_DRINKS"],
117
+ "attributes": ["GENERAL", "PRICES", "COMFORT", "CLEANLINESS", "QUALITY", "DESIGN_FEATURES",
118
+ "STYLE_OPTIONS", "MISCELLANEOUS"]
119
+ },
120
+ }
121
+ polarities = ["positive", "negative", "neutral"]
122
+ if self.config.name == "restaurants": # This is the name of the configuration selected in BUILDER_CONFIGS above
123
+ features = datasets.Features(
124
+ {
125
+ "reviewId": datasets.Value(dtype="string"),
126
+ "sentences": [
127
+ {
128
+ "sentenceId": datasets.Value("string"),
129
+ "text": datasets.Value("string"),
130
+ "opinions": [
131
+ {
132
+ "target": datasets.Value("string"),
133
+ "category": {
134
+ "entity": datasets.Value("string"),
135
+ "attribute": datasets.Value("string")
136
+ },
137
+ "polarity": datasets.Value("string"),
138
+ "from": datasets.Value("string"),
139
+ "to": datasets.Value("string"),
140
+ }
141
+ ]
142
+ }
143
+ ],
144
+ "opinions": [
145
+ {
146
+ "category": {
147
+ "entity": datasets.Value("string"),
148
+ "attribute": datasets.Value("string")
149
+ },
150
+ "polarity": datasets.Value("string"),
151
+ }
152
+ ]
153
+ }
154
+ )
155
+ elif self.config.name == "laptops":
156
+ features = datasets.Features(
157
+ {
158
+ "reviewId": datasets.Value(dtype="string"),
159
+ "sentences": [
160
+ {
161
+ "sentenceId": datasets.Value("string"),
162
+ "text": datasets.Value("string"),
163
+ "opinions": [
164
+ {
165
+ "category": {
166
+ "entity": datasets.Value("string"),
167
+ "attribute": datasets.Value("string")
168
+ },
169
+ "polarity": datasets.Value("string"),
170
+ }
171
+ ]
172
+ }
173
+ ],
174
+ "opinions": [
175
+ {
176
+ "category": {
177
+ "entity": datasets.Value("string"),
178
+ "attribute": datasets.Value("string")
179
+ },
180
+ "polarity": datasets.Value("string"),
181
+ }
182
+ ]
183
+ }
184
+ )
185
+ return datasets.DatasetInfo(
186
+ # This is the description that will appear on the datasets page.
187
+ description=_DESCRIPTION,
188
+ # This defines the different columns of the dataset and their types
189
+ features=features, # Here we define them above because they are different between the two configurations
190
+ # If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
191
+ # specify them. They'll be used if as_supervised=True in builder.as_dataset.
192
+ # supervised_keys=("sentence", "label"),
193
+ # Homepage of the dataset for documentation
194
+ homepage=_HOMEPAGE,
195
+ # License for the dataset if available
196
+ license=_LICENSE,
197
+ # Citation for the dataset
198
+ citation=_CITATION,
199
+ )
200
+
201
+ def _split_generators(self, dl_manager):
202
+ # TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
203
+ # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
204
+
205
+ # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
206
+ # It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
207
+ # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
208
+ urls = _URLS[self.config.name]
209
+ data_dir = dl_manager.download_and_extract(urls)
210
+ return [
211
+ datasets.SplitGenerator(
212
+ name=datasets.Split.TRAIN,
213
+ # These kwargs will be passed to _generate_examples
214
+ gen_kwargs={
215
+ "filepath": data_dir['train'],
216
+ "split": "train",
217
+ },
218
+ ),
219
+ datasets.SplitGenerator(
220
+ name=datasets.Split.TEST,
221
+ # These kwargs will be passed to _generate_examples
222
+ gen_kwargs={
223
+ "filepath": data_dir['test'],
224
+ "split": "test"
225
+ },
226
+ ),
227
+ ]
228
+
229
+ # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
230
+ def _generate_examples(self, filepath, split):
231
+ # TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
232
+ # The `id_` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
233
+ tree_SB1 = ET.parse(filepath["SB1"])
234
+ tree_SB2 = ET.parse(filepath["SB2"])
235
+ root_SB1 = tree_SB1.getroot()
236
+ root_SB2 = tree_SB2.getroot()
237
+ for id_, (review_SB1, review_SB2) in enumerate(zip(root_SB1.iter("Review"), root_SB2.iter("Review"))):
238
+ reviewId = review_SB1.attrib.get("rid")
239
+ sentences = []
240
+ for sentence in review_SB1.iter("sentence"):
241
+ sentence_dict = {}
242
+ sentence_dict["sentenceId"] = sentence.get("id")
243
+ sentence_dict["text"] = sentence.find("text").text
244
+ sentence_opinions = []
245
+ for sentence_opinion in sentence.iter("Opinion"):
246
+ sentence_opinion_dict = sentence_opinion.attrib
247
+ sentence_opinion_dict["category"] = dict(zip(["entity", "attribute"], sentence_opinion_dict["category"].split("#")))
248
+ sentence_opinions.append(sentence_opinion_dict)
249
+ sentence_dict["opinions"] = sentence_opinions
250
+ sentences.append(sentence_dict)
251
+ # Find the review with the same reviewId in "tree_SB2" and parse review-level opinions
252
+ review_opinions = []
253
+ for review_opinion in review_SB2.iter("Opinion"):
254
+ review_opinion_dict = review_opinion.attrib
255
+ review_opinion_dict["category"] = dict(zip(["entity", "attribute"], review_opinion_dict["category"].split("#")))
256
+ review_opinions.append(review_opinion_dict)
257
+
258
+ yield id_, {
259
+ "reviewId": reviewId,
260
+ "sentences": sentences,
261
+ "opinions": review_opinions,
262
+ }