holylovenia commited on
Commit
5b42e20
1 Parent(s): 5ba0b83

Upload casa.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. casa.py +154 -0
casa.py ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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{8629181,
13
+ author={Ilmania, Arfinda and Abdurrahman and Cahyawijaya, Samuel and Purwarianti, Ayu},
14
+ booktitle={2018 International Conference on Asian Language Processing (IALP)},
15
+ title={Aspect Detection and Sentiment Classification Using Deep Neural Network for Indonesian Aspect-Based Sentiment Analysis},
16
+ year={2018},
17
+ volume={},
18
+ number={},
19
+ pages={62-67},
20
+ doi={10.1109/IALP.2018.8629181
21
+ }
22
+ """
23
+
24
+ _LANGUAGES = ["ind"] # We follow ISO639-3 language code (https://iso639-3.sil.org/code_tables/639/data)
25
+ _LOCAL = False
26
+
27
+ _DATASETNAME = "casa"
28
+
29
+ _DESCRIPTION = """
30
+ CASA: An aspect-based sentiment analysis dataset consisting of around a thousand car reviews collected from multiple Indonesian online automobile platforms (Ilmania et al., 2018).
31
+ The dataset covers six aspects of car quality.
32
+ We define the task to be a multi-label classification task,
33
+ where each label represents a sentiment for a single aspect with three possible values: positive, negative, and neutral.
34
+ """
35
+
36
+ _HOMEPAGE = "https://github.com/IndoNLP/indonlu"
37
+
38
+ _LICENSE = "CC-BY-SA 4.0"
39
+
40
+ _URLS = {
41
+ "train": "https://raw.githubusercontent.com/IndoNLP/indonlu/master/dataset/casa_absa-prosa/train_preprocess.csv",
42
+ "validation": "https://raw.githubusercontent.com/IndoNLP/indonlu/master/dataset/casa_absa-prosa/valid_preprocess.csv",
43
+ "test": "https://raw.githubusercontent.com/IndoNLP/indonlu/master/dataset/casa_absa-prosa/test_preprocess.csv",
44
+ }
45
+
46
+ _SUPPORTED_TASKS = [Tasks.ASPECT_BASED_SENTIMENT_ANALYSIS]
47
+
48
+ _SOURCE_VERSION = "1.0.0"
49
+
50
+ _NUSANTARA_VERSION = "1.0.0"
51
+
52
+
53
+ class CASA(datasets.GeneratorBasedBuilder):
54
+ """CASA is an aspect based sentiment analysis dataset"""
55
+
56
+ SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
57
+ NUSANTARA_VERSION = datasets.Version(_NUSANTARA_VERSION)
58
+
59
+ BUILDER_CONFIGS = [
60
+ NusantaraConfig(
61
+ name="casa_source",
62
+ version=SOURCE_VERSION,
63
+ description="CASA source schema",
64
+ schema="source",
65
+ subset_id="casa",
66
+ ),
67
+ NusantaraConfig(
68
+ name="casa_nusantara_text_multi",
69
+ version=NUSANTARA_VERSION,
70
+ description="CASA Nusantara schema",
71
+ schema="nusantara_text_multi",
72
+ subset_id="casa",
73
+ ),
74
+ ]
75
+
76
+ DEFAULT_CONFIG_NAME = "casa_source"
77
+
78
+ def _info(self) -> datasets.DatasetInfo:
79
+ if self.config.schema == "source":
80
+ features = datasets.Features(
81
+ {
82
+ "index": datasets.Value("int64"),
83
+ "sentence": datasets.Value("string"),
84
+ "fuel": datasets.Value("string"),
85
+ "machine": datasets.Value("string"),
86
+ "others": datasets.Value("string"),
87
+ "part": datasets.Value("string"),
88
+ "price": datasets.Value("string"),
89
+ "service": datasets.Value("string"),
90
+ }
91
+ )
92
+
93
+ elif self.config.schema == "nusantara_text_multi":
94
+ features = schemas.text_multi_features(["positive", "neutral", "negative"])
95
+
96
+ return datasets.DatasetInfo(
97
+ description=_DESCRIPTION,
98
+ features=features,
99
+ homepage=_HOMEPAGE,
100
+ license=_LICENSE,
101
+ citation=_CITATION,
102
+ )
103
+
104
+ def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
105
+ train_csv_path = Path(dl_manager.download_and_extract(_URLS["train"]))
106
+ validation_csv_path = Path(dl_manager.download_and_extract(_URLS["validation"]))
107
+ test_csv_path = Path(dl_manager.download_and_extract(_URLS["test"]))
108
+
109
+ data_dir = {
110
+ "train": train_csv_path,
111
+ "validation": validation_csv_path,
112
+ "test": test_csv_path,
113
+ }
114
+
115
+ return [
116
+ datasets.SplitGenerator(
117
+ name=datasets.Split.TRAIN,
118
+ gen_kwargs={
119
+ "filepath": data_dir["train"],
120
+ "split": "train",
121
+ },
122
+ ),
123
+ datasets.SplitGenerator(
124
+ name=datasets.Split.TEST,
125
+ gen_kwargs={
126
+ "filepath": data_dir["test"],
127
+ "split": "test",
128
+ },
129
+ ),
130
+ datasets.SplitGenerator(
131
+ name=datasets.Split.VALIDATION,
132
+ gen_kwargs={
133
+ "filepath": data_dir["validation"],
134
+ "split": "dev",
135
+ },
136
+ ),
137
+ ]
138
+
139
+ def _generate_examples(self, filepath: Path, split: str) -> Tuple[int, Dict]:
140
+ """Yields examples as (key, example) tuples."""
141
+ df = pd.read_csv(filepath, sep=",", header="infer").reset_index()
142
+ if self.config.schema == "source":
143
+ for row in df.itertuples():
144
+ entry = {"index": row.index, "sentence": row.sentence, "fuel": row.fuel, "machine": row.machine, "others": row.others, "part": row.part, "price": row.price, "service": row.service}
145
+ yield row.index, entry
146
+
147
+ elif self.config.schema == "nusantara_text_multi":
148
+ for row in df.itertuples():
149
+ entry = {
150
+ "id": str(row.index),
151
+ "text": row.sentence,
152
+ "labels": [label for label in row[3:]],
153
+ }
154
+ yield row.index, entry