holylovenia
commited on
Commit
•
cca2724
1
Parent(s):
b609410
Upload hoasa.py with huggingface_hub
Browse files
hoasa.py
ADDED
@@ -0,0 +1,170 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pathlib import Path
|
2 |
+
from typing import Dict, List, Tuple
|
3 |
+
|
4 |
+
import datasets
|
5 |
+
import pandas as pd
|
6 |
+
|
7 |
+
from nusacrowd.utils import schemas
|
8 |
+
from nusacrowd.utils.configs import NusantaraConfig
|
9 |
+
from nusacrowd.utils.constants import Tasks
|
10 |
+
|
11 |
+
_CITATION = """
|
12 |
+
@inproceedings{azhar2019multi,
|
13 |
+
title={Multi-label Aspect Categorization with Convolutional Neural Networks and Extreme Gradient Boosting},
|
14 |
+
author={A. N. Azhar, M. L. Khodra, and A. P. Sutiono}
|
15 |
+
booktitle={Proceedings of the 2019 International Conference on Electrical Engineering and Informatics (ICEEI)},
|
16 |
+
pages={35--40},
|
17 |
+
year={2019}
|
18 |
+
}
|
19 |
+
"""
|
20 |
+
|
21 |
+
|
22 |
+
_LANGUAGES = ["ind"] # We follow ISO639-3 language code (https://iso639-3.sil.org/code_tables/639/data)
|
23 |
+
_LOCAL = False
|
24 |
+
|
25 |
+
_DATASETNAME = "hoasa"
|
26 |
+
|
27 |
+
_DESCRIPTION = """
|
28 |
+
HoASA: An aspect-based sentiment analysis dataset consisting of hotel reviews collected from the hotel aggregator platform, AiryRooms.
|
29 |
+
The dataset covers ten different aspects of hotel quality. Similar to the CASA dataset, each review is labeled with a single sentiment label for each aspect.
|
30 |
+
There are four possible sentiment classes for each sentiment label:
|
31 |
+
positive, negative, neutral, and positive-negative.
|
32 |
+
The positivenegative label is given to a review that contains multiple sentiments of the same aspect but for different objects (e.g., cleanliness of bed and toilet).
|
33 |
+
"""
|
34 |
+
|
35 |
+
_HOMEPAGE = "https://github.com/IndoNLP/indonlu"
|
36 |
+
|
37 |
+
_LICENSE = "CC-BY-SA 4.0"
|
38 |
+
|
39 |
+
_URLS = {
|
40 |
+
"train": "https://raw.githubusercontent.com/IndoNLP/indonlu/master/dataset/hoasa_absa-airy/train_preprocess.csv",
|
41 |
+
"validation": "https://raw.githubusercontent.com/IndoNLP/indonlu/master/dataset/hoasa_absa-airy/valid_preprocess.csv",
|
42 |
+
"test": "https://raw.githubusercontent.com/IndoNLP/indonlu/master/dataset/hoasa_absa-airy/test_preprocess.csv",
|
43 |
+
}
|
44 |
+
|
45 |
+
_SUPPORTED_TASKS = [Tasks.ASPECT_BASED_SENTIMENT_ANALYSIS]
|
46 |
+
|
47 |
+
_SOURCE_VERSION = "1.0.0"
|
48 |
+
|
49 |
+
_NUSANTARA_VERSION = "1.0.0"
|
50 |
+
|
51 |
+
|
52 |
+
class HoASA(datasets.GeneratorBasedBuilder):
|
53 |
+
"""HoASA is an aspect based sentiment analysis dataset"""
|
54 |
+
|
55 |
+
SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
|
56 |
+
NUSANTARA_VERSION = datasets.Version(_NUSANTARA_VERSION)
|
57 |
+
|
58 |
+
BUILDER_CONFIGS = [
|
59 |
+
NusantaraConfig(
|
60 |
+
name="hoasa_source",
|
61 |
+
version=SOURCE_VERSION,
|
62 |
+
description="HoASA source schema",
|
63 |
+
schema="source",
|
64 |
+
subset_id="hoasa",
|
65 |
+
),
|
66 |
+
NusantaraConfig(
|
67 |
+
name="hoasa_nusantara_text_multi",
|
68 |
+
version=NUSANTARA_VERSION,
|
69 |
+
description="HoASA Nusantara schema",
|
70 |
+
schema="nusantara_text_multi",
|
71 |
+
subset_id="hoasa",
|
72 |
+
),
|
73 |
+
]
|
74 |
+
|
75 |
+
DEFAULT_CONFIG_NAME = "hoasa_source"
|
76 |
+
|
77 |
+
def _info(self) -> datasets.DatasetInfo:
|
78 |
+
if self.config.schema == "source":
|
79 |
+
features = datasets.Features(
|
80 |
+
{
|
81 |
+
"index": datasets.Value("int64"),
|
82 |
+
"review": datasets.Value("string"),
|
83 |
+
"ac": datasets.Value("string"),
|
84 |
+
"air_panas": datasets.Value("string"),
|
85 |
+
"bau": datasets.Value("string"),
|
86 |
+
"general": datasets.Value("string"),
|
87 |
+
"kebersihan": datasets.Value("string"),
|
88 |
+
"linen": datasets.Value("string"),
|
89 |
+
"service": datasets.Value("string"),
|
90 |
+
"sunrise_meal": datasets.Value("string"),
|
91 |
+
"tv": datasets.Value("string"),
|
92 |
+
"wifi": datasets.Value("string"),
|
93 |
+
}
|
94 |
+
)
|
95 |
+
|
96 |
+
elif self.config.schema == "nusantara_text_multi":
|
97 |
+
features = schemas.text_multi_features(["pos", "neut", "neg", "neg_pos"])
|
98 |
+
|
99 |
+
return datasets.DatasetInfo(
|
100 |
+
description=_DESCRIPTION,
|
101 |
+
features=features,
|
102 |
+
homepage=_HOMEPAGE,
|
103 |
+
license=_LICENSE,
|
104 |
+
citation=_CITATION,
|
105 |
+
)
|
106 |
+
|
107 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
108 |
+
train_csv_path = Path(dl_manager.download_and_extract(_URLS["train"]))
|
109 |
+
validation_csv_path = Path(dl_manager.download_and_extract(_URLS["validation"]))
|
110 |
+
test_csv_path = Path(dl_manager.download_and_extract(_URLS["test"]))
|
111 |
+
|
112 |
+
data_dir = {
|
113 |
+
"train": train_csv_path,
|
114 |
+
"validation": validation_csv_path,
|
115 |
+
"test": test_csv_path,
|
116 |
+
}
|
117 |
+
|
118 |
+
return [
|
119 |
+
datasets.SplitGenerator(
|
120 |
+
name=datasets.Split.TRAIN,
|
121 |
+
gen_kwargs={
|
122 |
+
"filepath": data_dir["train"],
|
123 |
+
"split": "train",
|
124 |
+
},
|
125 |
+
),
|
126 |
+
datasets.SplitGenerator(
|
127 |
+
name=datasets.Split.TEST,
|
128 |
+
gen_kwargs={
|
129 |
+
"filepath": data_dir["test"],
|
130 |
+
"split": "test",
|
131 |
+
},
|
132 |
+
),
|
133 |
+
datasets.SplitGenerator(
|
134 |
+
name=datasets.Split.VALIDATION,
|
135 |
+
gen_kwargs={
|
136 |
+
"filepath": data_dir["validation"],
|
137 |
+
"split": "dev",
|
138 |
+
},
|
139 |
+
),
|
140 |
+
]
|
141 |
+
|
142 |
+
def _generate_examples(self, filepath: Path, split: str) -> Tuple[int, Dict]:
|
143 |
+
"""Yields examples as (key, example) tuples."""
|
144 |
+
df = pd.read_csv(filepath, sep=",", header="infer").reset_index()
|
145 |
+
if self.config.schema == "source":
|
146 |
+
for row in df.itertuples():
|
147 |
+
entry = {
|
148 |
+
"index": row.index,
|
149 |
+
"review": row.review,
|
150 |
+
"ac": row.ac,
|
151 |
+
"air_panas": row.air_panas,
|
152 |
+
"bau": row.bau,
|
153 |
+
"general": row.general,
|
154 |
+
"kebersihan": row.kebersihan,
|
155 |
+
"linen": row.linen,
|
156 |
+
"service": row.service,
|
157 |
+
"sunrise_meal": row.sunrise_meal,
|
158 |
+
"tv": row.tv,
|
159 |
+
"wifi": row.wifi,
|
160 |
+
}
|
161 |
+
yield row.index, entry
|
162 |
+
|
163 |
+
elif self.config.schema == "nusantara_text_multi":
|
164 |
+
for row in df.itertuples():
|
165 |
+
entry = {
|
166 |
+
"id": str(row.index),
|
167 |
+
"text": row.review,
|
168 |
+
"labels": [label for label in row[3:]],
|
169 |
+
}
|
170 |
+
yield row.index, entry
|