holylovenia
commited on
Commit
•
cffd665
1
Parent(s):
9e96dc7
Upload uit_vsfc.py with huggingface_hub
Browse files- uit_vsfc.py +203 -0
uit_vsfc.py
ADDED
@@ -0,0 +1,203 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
from pathlib import Path
|
17 |
+
from typing import Dict, List, Tuple
|
18 |
+
|
19 |
+
import datasets
|
20 |
+
|
21 |
+
from seacrowd.utils import schemas
|
22 |
+
from seacrowd.utils.configs import SEACrowdConfig
|
23 |
+
from seacrowd.utils.constants import Licenses, Tasks
|
24 |
+
|
25 |
+
_CITATION = """\
|
26 |
+
@inproceedings{van2018uit,
|
27 |
+
title={UIT-VSFC: Vietnamese students’ feedback corpus for sentiment analysis},
|
28 |
+
author={Van Nguyen, Kiet and Nguyen, Vu Duc and Nguyen, Phu XV and Truong, Tham TH and Nguyen, Ngan Luu-Thuy},
|
29 |
+
booktitle={2018 10th international conference on knowledge and systems engineering (KSE)},
|
30 |
+
pages={19--24},
|
31 |
+
year={2018},
|
32 |
+
organization={IEEE}
|
33 |
+
}
|
34 |
+
"""
|
35 |
+
|
36 |
+
|
37 |
+
_DATASETNAME = "uit_vsfc"
|
38 |
+
|
39 |
+
_DESCRIPTION = """\
|
40 |
+
This corpus consists of student feedback obtained from end-of-semester surveys at a Vietnamese university.
|
41 |
+
Feedback is classified into four possible topics: lecturer, curriculum, facility or others.
|
42 |
+
Feedback is also labeled as one of three sentiment polarities: positive, negative or neutral.
|
43 |
+
"""
|
44 |
+
|
45 |
+
_HOMEPAGE = "https://drive.google.com/drive/folders/1HooABJyrddVGzll7fgkJ6VzkG_XuWfRu"
|
46 |
+
|
47 |
+
_LANGUAGES = ["vie"]
|
48 |
+
|
49 |
+
_LICENSE = Licenses.UNKNOWN.value
|
50 |
+
|
51 |
+
_LOCAL = False
|
52 |
+
|
53 |
+
|
54 |
+
_URLS = {
|
55 |
+
"train": {
|
56 |
+
"sentences": "https://drive.google.com/uc?id=1nzak5OkrheRV1ltOGCXkT671bmjODLhP&export=download",
|
57 |
+
"sentiments": "https://drive.google.com/uc?id=1ye-gOZIBqXdKOoi_YxvpT6FeRNmViPPv&export=download",
|
58 |
+
"topics": "https://drive.google.com/uc?id=14MuDtwMnNOcr4z_8KdpxprjbwaQ7lJ_C&export=download",
|
59 |
+
},
|
60 |
+
"validation": {
|
61 |
+
"sentences": "https://drive.google.com/uc?id=1sMJSR3oRfPc3fe1gK-V3W5F24tov_517&export=download",
|
62 |
+
"sentiments": "https://drive.google.com/uc?id=1GiY1AOp41dLXIIkgES4422AuDwmbUseL&export=download",
|
63 |
+
"topics": "https://drive.google.com/uc?id=1DwLgDEaFWQe8mOd7EpF-xqMEbDLfdT-W&export=download",
|
64 |
+
},
|
65 |
+
"test": {
|
66 |
+
"sentences": "https://drive.google.com/uc?id=1aNMOeZZbNwSRkjyCWAGtNCMa3YrshR-n&export=download",
|
67 |
+
"sentiments": "https://drive.google.com/uc?id=1vkQS5gI0is4ACU58-AbWusnemw7KZNfO&export=download",
|
68 |
+
"topics": "https://drive.google.com/uc?id=1_ArMpDguVsbUGl-xSMkTF_p5KpZrmpSB&export=download",
|
69 |
+
},
|
70 |
+
}
|
71 |
+
|
72 |
+
_SUPPORTED_TASKS = [Tasks.SENTIMENT_ANALYSIS, Tasks.TOPIC_MODELING]
|
73 |
+
|
74 |
+
_SOURCE_VERSION = "1.0.0"
|
75 |
+
|
76 |
+
_SEACROWD_VERSION = "2024.06.20"
|
77 |
+
|
78 |
+
|
79 |
+
class UITVSFCDataset(datasets.GeneratorBasedBuilder):
|
80 |
+
"""This corpus consists of student feedback obtained from end-of-semester surveys at a Vietnamese university.
|
81 |
+
Feedback is classified into four possible topics: lecturer, curriculum, facility or others.
|
82 |
+
Feedback is also labeled as one of three sentiment polarities: positive, negative or neutral."""
|
83 |
+
|
84 |
+
SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
|
85 |
+
SEACROWD_VERSION = datasets.Version(_SEACROWD_VERSION)
|
86 |
+
|
87 |
+
SENTIMENT_LABEL_CLASSES = ["positive", "negative", "neutral"]
|
88 |
+
TOPIC_LABEL_CLASSES = ["lecturer", "training_program", "others", "facility"]
|
89 |
+
|
90 |
+
SEACROWD_SCHEMA_NAME = "text"
|
91 |
+
|
92 |
+
BUILDER_CONFIGS = [
|
93 |
+
SEACrowdConfig(
|
94 |
+
name=f"{_DATASETNAME}_sentiment_source",
|
95 |
+
version=SOURCE_VERSION,
|
96 |
+
description=f"{_DATASETNAME} source schema",
|
97 |
+
schema="source",
|
98 |
+
subset_id=_DATASETNAME,
|
99 |
+
),
|
100 |
+
SEACrowdConfig(
|
101 |
+
name=f"{_DATASETNAME}_topic_source",
|
102 |
+
version=SOURCE_VERSION,
|
103 |
+
description=f"{_DATASETNAME} source schema",
|
104 |
+
schema="source",
|
105 |
+
subset_id=_DATASETNAME,
|
106 |
+
),
|
107 |
+
SEACrowdConfig(
|
108 |
+
name=f"{_DATASETNAME}_sentiment_seacrowd_{SEACROWD_SCHEMA_NAME}",
|
109 |
+
version=SEACROWD_VERSION,
|
110 |
+
description=f"{_DATASETNAME} SEACrowd schema",
|
111 |
+
schema=f"seacrowd_{SEACROWD_SCHEMA_NAME}",
|
112 |
+
subset_id=_DATASETNAME,
|
113 |
+
),
|
114 |
+
SEACrowdConfig(
|
115 |
+
name=f"{_DATASETNAME}_topic_seacrowd_{SEACROWD_SCHEMA_NAME}",
|
116 |
+
version=SEACROWD_VERSION,
|
117 |
+
description=f"{_DATASETNAME} SEACrowd schema",
|
118 |
+
schema=f"seacrowd_{SEACROWD_SCHEMA_NAME}",
|
119 |
+
subset_id=_DATASETNAME,
|
120 |
+
),
|
121 |
+
]
|
122 |
+
|
123 |
+
DEFAULT_CONFIG_NAME = f"{_DATASETNAME}_source"
|
124 |
+
|
125 |
+
def _info(self) -> datasets.DatasetInfo:
|
126 |
+
if self.config.schema == "source":
|
127 |
+
features = datasets.Features(
|
128 |
+
{
|
129 |
+
"sentence": datasets.Value("string"),
|
130 |
+
"sentiment": datasets.ClassLabel(names=self.SENTIMENT_LABEL_CLASSES),
|
131 |
+
"topic": datasets.ClassLabel(names=self.TOPIC_LABEL_CLASSES),
|
132 |
+
}
|
133 |
+
)
|
134 |
+
elif self.config.name == f"{_DATASETNAME}_sentiment_seacrowd_{self.SEACROWD_SCHEMA_NAME}":
|
135 |
+
features = schemas.text_features(self.SENTIMENT_LABEL_CLASSES)
|
136 |
+
elif self.config.name == f"{_DATASETNAME}_topic_seacrowd_{self.SEACROWD_SCHEMA_NAME}":
|
137 |
+
features = schemas.text_features(self.TOPIC_LABEL_CLASSES)
|
138 |
+
|
139 |
+
return datasets.DatasetInfo(
|
140 |
+
description=_DESCRIPTION,
|
141 |
+
features=features,
|
142 |
+
homepage=_HOMEPAGE,
|
143 |
+
license=_LICENSE,
|
144 |
+
citation=_CITATION,
|
145 |
+
)
|
146 |
+
|
147 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
148 |
+
data_dir = dl_manager.download(_URLS)
|
149 |
+
|
150 |
+
return [
|
151 |
+
datasets.SplitGenerator(
|
152 |
+
name=datasets.Split.TRAIN,
|
153 |
+
gen_kwargs={
|
154 |
+
"sentences_path": data_dir["train"]["sentences"],
|
155 |
+
"sentiments_path": data_dir["train"]["sentiments"],
|
156 |
+
"topics_path": data_dir["train"]["topics"],
|
157 |
+
"split": "train",
|
158 |
+
},
|
159 |
+
),
|
160 |
+
datasets.SplitGenerator(
|
161 |
+
name=datasets.Split.TEST,
|
162 |
+
gen_kwargs={
|
163 |
+
"sentences_path": data_dir["test"]["sentences"],
|
164 |
+
"sentiments_path": data_dir["test"]["sentiments"],
|
165 |
+
"topics_path": data_dir["test"]["topics"],
|
166 |
+
"split": "test",
|
167 |
+
},
|
168 |
+
),
|
169 |
+
datasets.SplitGenerator(
|
170 |
+
name=datasets.Split.VALIDATION,
|
171 |
+
gen_kwargs={
|
172 |
+
"sentences_path": data_dir["validation"]["sentences"],
|
173 |
+
"sentiments_path": data_dir["validation"]["sentiments"],
|
174 |
+
"topics_path": data_dir["validation"]["topics"],
|
175 |
+
"split": "dev",
|
176 |
+
},
|
177 |
+
),
|
178 |
+
]
|
179 |
+
|
180 |
+
def _generate_examples(self, sentences_path: Path, sentiments_path: Path, topics_path: Path, split: str) -> Tuple[int, Dict]:
|
181 |
+
"""Yields examples as (key, example) tuples."""
|
182 |
+
|
183 |
+
if self.config.schema == "source":
|
184 |
+
with open(sentences_path, encoding="utf-8") as sentences, open(sentiments_path, encoding="utf-8") as sentiments, open(topics_path, encoding="utf-8") as topics:
|
185 |
+
for key, (sentence, sentiment, topic) in enumerate(zip(sentences, sentiments, topics)):
|
186 |
+
yield key, {
|
187 |
+
"sentence": sentence.strip(),
|
188 |
+
"sentiment": int(sentiment.strip()),
|
189 |
+
"topic": int(topic.strip()),
|
190 |
+
}
|
191 |
+
|
192 |
+
elif self.config.name == f"{_DATASETNAME}_sentiment_seacrowd_{self.SEACROWD_SCHEMA_NAME}":
|
193 |
+
with open(sentences_path, encoding="utf-8") as sentences, open(sentiments_path, encoding="utf-8") as sentiments:
|
194 |
+
for key, (sentence, sentiment) in enumerate(zip(sentences, sentiments)):
|
195 |
+
yield key, {"id": str(key), "text": sentence.strip(), "label": int(sentiment.strip())}
|
196 |
+
elif self.config.name == f"{_DATASETNAME}_topic_seacrowd_{self.SEACROWD_SCHEMA_NAME}":
|
197 |
+
with open(sentences_path, encoding="utf-8") as sentences, open(topics_path, encoding="utf-8") as topics:
|
198 |
+
for key, (sentence, topic) in enumerate(zip(sentences, topics)):
|
199 |
+
yield key, {
|
200 |
+
"id": str(key),
|
201 |
+
"text": sentence.strip(),
|
202 |
+
"label": int(topic.strip()),
|
203 |
+
}
|