Datasets:

Languages:
Vietnamese
ArXiv:
License:
holylovenia commited on
Commit
b3b9b01
1 Parent(s): 3e396ae

Upload uit_visfd.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. uit_visfd.py +227 -0
uit_visfd.py ADDED
@@ -0,0 +1,227 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2022 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
+ """
17
+ UIT-ViSFD is the Vietnamese Smartphone Feedback Dataset.
18
+ It is an aspect-based sentiment analysis dataset.
19
+ It consists of 11,122 human-annotated comments for mobile e-commerce.
20
+ """
21
+ import os
22
+ from pathlib import Path
23
+ from typing import Dict, List, Tuple
24
+
25
+ import datasets
26
+ import pandas as pd
27
+
28
+ from seacrowd.utils import schemas
29
+ from seacrowd.utils.configs import SEACrowdConfig
30
+ from seacrowd.utils.constants import Licenses, Tasks
31
+
32
+ _CITATION = """\
33
+ @InProceedings{10.1007/978-3-030-82147-0_53,
34
+ author="Luc Phan, Luong
35
+ and Huynh Pham, Phuc
36
+ and Thi-Thanh Nguyen, Kim
37
+ and Khai Huynh, Sieu
38
+ and Thi Nguyen, Tham
39
+ and Thanh Nguyen, Luan
40
+ and Van Huynh, Tin
41
+ and Van Nguyen, Kiet",
42
+ editor="Qiu, Han
43
+ and Zhang, Cheng
44
+ and Fei, Zongming
45
+ and Qiu, Meikang
46
+ and Kung, Sun-Yuan",
47
+ title="SA2SL: From Aspect-Based Sentiment Analysis to Social Listening System for Business Intelligence",
48
+ booktitle="Knowledge Science, Engineering and Management ",
49
+ year="2021",
50
+ publisher="Springer International Publishing",
51
+ address="Cham",
52
+ pages="647--658",
53
+ isbn="978-3-030-82147-0"
54
+ }
55
+ """
56
+
57
+ _DATASETNAME = "uit_visfd"
58
+
59
+ _DESCRIPTION = """
60
+ UIT-ViSFD is the Vietnamese Smartphone Feedback Dataset.
61
+ It is an aspect-based sentiment analysis dataset.
62
+ It consists of 11,122 human-annotated comments for mobile e-commerce.
63
+ """
64
+
65
+ _HOMEPAGE = "https://github.com/LuongPhan/UIT-ViSFD"
66
+
67
+ _LANGUAGES = ["vie"]
68
+
69
+ _LICENSE = Licenses.UNKNOWN.value
70
+
71
+ _LOCAL = False
72
+
73
+ _URLS = {_DATASETNAME: "https://github.com/LuongPhan/UIT-ViSFD/raw/main/UIT-ViSFD.zip"}
74
+
75
+ _SUPPORTED_TASKS = [Tasks.ASPECT_BASED_SENTIMENT_ANALYSIS]
76
+
77
+ _SOURCE_VERSION = "1.0.0"
78
+
79
+ _SEACROWD_VERSION = "2024.06.20"
80
+
81
+
82
+ class UITViSFDDataset(datasets.GeneratorBasedBuilder):
83
+ """
84
+ Crawled textual feedback from customers about smartphones on a large e-commerce website in Vietnam.
85
+ The label of the dataset is ten aspects and three polarities.
86
+ Please read the guidelines in the paper for more information.
87
+ We randomly divide the dataset into three sets:
88
+ - Train: 7,786.
89
+ - Dev: 1,112.
90
+ - Test: 2,224.
91
+ """
92
+
93
+ SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
94
+ SEACROWD_VERSION = datasets.Version(_SEACROWD_VERSION)
95
+
96
+ BUILDER_CONFIGS = [
97
+ SEACrowdConfig(
98
+ name=f"{_DATASETNAME}_source",
99
+ version=SOURCE_VERSION,
100
+ description=f"{_DATASETNAME} source schema",
101
+ schema="source",
102
+ subset_id=f"{_DATASETNAME}",
103
+ ),
104
+ SEACrowdConfig(
105
+ name=f"{_DATASETNAME}_seacrowd_text_multi",
106
+ version=SEACROWD_VERSION,
107
+ description=f"{_DATASETNAME} SEACrowd schema",
108
+ schema="seacrowd_text_multi",
109
+ subset_id=f"{_DATASETNAME}",
110
+ ),
111
+ ]
112
+
113
+ DEFAULT_CONFIG_NAME = f"{_DATASETNAME}_source"
114
+
115
+ _LABELS = [
116
+ "BATTERY#Positive",
117
+ "BATTERY#Neutral",
118
+ "BATTERY#Negative",
119
+ "GENERAL#Positive",
120
+ "GENERAL#Neutral",
121
+ "GENERAL#Negative",
122
+ "CAMERA#Positive",
123
+ "CAMERA#Neutral",
124
+ "CAMERA#Negative",
125
+ "FEATURES#Positive",
126
+ "FEATURES#Neutral",
127
+ "FEATURES#Negative",
128
+ "PRICE#Positive",
129
+ "PRICE#Neutral",
130
+ "PRICE#Negative",
131
+ "SER&ACC#Positive",
132
+ "SER&ACC#Neutral",
133
+ "SER&ACC#Negative",
134
+ "PERFORMANCE#Positive",
135
+ "PERFORMANCE#Neutral",
136
+ "PERFORMANCE#Negative",
137
+ "SCREEN#Positive",
138
+ "SCREEN#Neutral",
139
+ "SCREEN#Negative",
140
+ "DESIGN#Positive",
141
+ "DESIGN#Neutral",
142
+ "DESIGN#Negative",
143
+ "STORAGE#Positive",
144
+ "STORAGE#Neutral",
145
+ "STORAGE#Negative",
146
+ "OTHERS",
147
+ ]
148
+
149
+ def _info(self) -> datasets.DatasetInfo:
150
+
151
+ if self.config.schema == "source":
152
+
153
+ features = datasets.Features(
154
+ {"index": datasets.Value("int64"), "comment": datasets.Value("string"), "n_star": datasets.Value("int64"), "date_time": datasets.Value("string"), "label": datasets.Sequence(feature=datasets.ClassLabel(names=self._LABELS))}
155
+ )
156
+
157
+ elif self.config.schema == "seacrowd_text_multi":
158
+ features = schemas.text_multi_features(self._LABELS)
159
+
160
+ return datasets.DatasetInfo(
161
+ description=_DESCRIPTION,
162
+ features=features,
163
+ homepage=_HOMEPAGE,
164
+ license=_LICENSE,
165
+ citation=_CITATION,
166
+ )
167
+
168
+ def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
169
+ """Returns SplitGenerators."""
170
+
171
+ data_dir = dl_manager.download_and_extract(_URLS[_DATASETNAME])
172
+
173
+ return [
174
+ datasets.SplitGenerator(
175
+ name=datasets.Split.TRAIN,
176
+ gen_kwargs={
177
+ "filepath": os.path.join(data_dir, "Train.csv"),
178
+ "split": "train",
179
+ },
180
+ ),
181
+ datasets.SplitGenerator(
182
+ name=datasets.Split.TEST,
183
+ gen_kwargs={
184
+ "filepath": os.path.join(data_dir, "Test.csv"),
185
+ "split": "test",
186
+ },
187
+ ),
188
+ datasets.SplitGenerator(
189
+ name=datasets.Split.VALIDATION,
190
+ gen_kwargs={
191
+ "filepath": os.path.join(data_dir, "Dev.csv"),
192
+ "split": "dev",
193
+ },
194
+ ),
195
+ ]
196
+
197
+ def _generate_examples(self, filepath: Path, split: str) -> Tuple[int, Dict]:
198
+ """Yields examples as (key, example) tuples."""
199
+
200
+ df = pd.read_csv(filepath, index_col=None)
201
+
202
+ def transform_label(label_string):
203
+ label_string = label_string.strip("{}")
204
+ label_pairs = label_string.split(";")
205
+ label_array = []
206
+ for pair in label_pairs:
207
+ pair = pair.strip("{}")
208
+ if pair:
209
+ label_array.append(pair)
210
+ return label_array
211
+
212
+ df["label"] = df["label"].apply(transform_label)
213
+
214
+ for index, row in df.iterrows():
215
+
216
+ if self.config.schema == "source":
217
+ example = row.to_dict()
218
+
219
+ elif self.config.schema == "seacrowd_text_multi":
220
+
221
+ example = {
222
+ "id": str(row["index"]),
223
+ "text": str(row["comment"]),
224
+ "labels": row["label"],
225
+ }
226
+
227
+ yield index, example