holylovenia
commited on
Commit
•
9fcd6d7
1
Parent(s):
6d6da67
Upload smsa.py with huggingface_hub
Browse files
smsa.py
ADDED
@@ -0,0 +1,137 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pathlib import Path
|
2 |
+
from typing import List
|
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, DEFAULT_SOURCE_VIEW_NAME, DEFAULT_NUSANTARA_VIEW_NAME
|
10 |
+
|
11 |
+
_DATASETNAME = "smsa"
|
12 |
+
_SOURCE_VIEW_NAME = DEFAULT_SOURCE_VIEW_NAME
|
13 |
+
_UNIFIED_VIEW_NAME = DEFAULT_NUSANTARA_VIEW_NAME
|
14 |
+
|
15 |
+
_LANGUAGES = ["ind"] # We follow ISO639-3 language code (https://iso639-3.sil.org/code_tables/639/data)
|
16 |
+
_LOCAL = False
|
17 |
+
|
18 |
+
_CITATION = """\
|
19 |
+
@INPROCEEDINGS{8904199,
|
20 |
+
author={Purwarianti, Ayu and Crisdayanti, Ida Ayu Putu Ari},
|
21 |
+
booktitle={2019 International Conference of Advanced Informatics: Concepts, Theory and Applications (ICAICTA)},
|
22 |
+
title={Improving Bi-LSTM Performance for Indonesian Sentiment Analysis Using Paragraph Vector},
|
23 |
+
year={2019},
|
24 |
+
pages={1-5},
|
25 |
+
doi={10.1109/ICAICTA.2019.8904199}
|
26 |
+
}
|
27 |
+
|
28 |
+
@inproceedings{wilie2020indonlu,
|
29 |
+
title={IndoNLU: Benchmark and Resources for Evaluating Indonesian Natural Language Understanding},
|
30 |
+
author={Wilie, Bryan and Vincentio, Karissa and Winata, Genta Indra and Cahyawijaya, Samuel and Li, Xiaohong and Lim, Zhi Yuan and Soleman, Sidik and Mahendra, Rahmad and Fung, Pascale and Bahar, Syafri and others},
|
31 |
+
booktitle={Proceedings of the 1st Conference of the Asia-Pacific Chapter of the Association for Computational Linguistics and the 10th International Joint Conference on Natural Language Processing},
|
32 |
+
pages={843--857},
|
33 |
+
year={2020}
|
34 |
+
}
|
35 |
+
"""
|
36 |
+
|
37 |
+
_DESCRIPTION = """\
|
38 |
+
SmSA is a sentence-level sentiment analysis dataset (Purwarianti and Crisdayanti, 2019) is a collection of comments and reviews
|
39 |
+
in Indonesian obtained from multiple online platforms. The text was crawled and then annotated by several Indonesian linguists
|
40 |
+
to construct this dataset. There are three possible sentiments on the SmSA dataset: positive, negative, and neutral
|
41 |
+
"""
|
42 |
+
|
43 |
+
_HOMEPAGE = "https://github.com/IndoNLP/indonlu"
|
44 |
+
|
45 |
+
_LICENSE = "Creative Commons Attribution Share-Alike 4.0 International"
|
46 |
+
|
47 |
+
_URLs = {
|
48 |
+
"train": "https://github.com/IndoNLP/indonlu/raw/master/dataset/smsa_doc-sentiment-prosa/train_preprocess.tsv",
|
49 |
+
"validation": "https://github.com/IndoNLP/indonlu/raw/master/dataset/smsa_doc-sentiment-prosa/valid_preprocess.tsv",
|
50 |
+
"test": "https://github.com/IndoNLP/indonlu/raw/master/dataset/smsa_doc-sentiment-prosa/test_preprocess.tsv",
|
51 |
+
}
|
52 |
+
|
53 |
+
_SUPPORTED_TASKS = [Tasks.SENTIMENT_ANALYSIS]
|
54 |
+
|
55 |
+
_SOURCE_VERSION = "1.0.0"
|
56 |
+
_NUSANTARA_VERSION = "1.0.0"
|
57 |
+
|
58 |
+
|
59 |
+
class SMSA(datasets.GeneratorBasedBuilder):
|
60 |
+
"""SMSA is a sentiment analysis dataset consisting of 3 labels (positive, neutral, and negative) which comes from comments and reviews collected from multiple online platforms."""
|
61 |
+
|
62 |
+
BUILDER_CONFIGS = [
|
63 |
+
NusantaraConfig(
|
64 |
+
name="smsa_source",
|
65 |
+
version=datasets.Version(_SOURCE_VERSION),
|
66 |
+
description="SMSA source schema",
|
67 |
+
schema="source",
|
68 |
+
subset_id="smsa",
|
69 |
+
),
|
70 |
+
NusantaraConfig(
|
71 |
+
name="smsa_nusantara_text",
|
72 |
+
version=datasets.Version(_NUSANTARA_VERSION),
|
73 |
+
description="SMSA Nusantara schema",
|
74 |
+
schema="nusantara_text",
|
75 |
+
subset_id="smsa",
|
76 |
+
),
|
77 |
+
]
|
78 |
+
|
79 |
+
DEFAULT_CONFIG_NAME = "smsa_source"
|
80 |
+
|
81 |
+
def _info(self):
|
82 |
+
if self.config.schema == "source":
|
83 |
+
features = datasets.Features({"index": datasets.Value("string"), "sentence": datasets.Value("string"), "label": datasets.Value("string")})
|
84 |
+
elif self.config.schema == "nusantara_text":
|
85 |
+
features = schemas.text_features(["negative", "neutral", "positive"])
|
86 |
+
|
87 |
+
return datasets.DatasetInfo(
|
88 |
+
description=_DESCRIPTION,
|
89 |
+
features=features,
|
90 |
+
homepage=_HOMEPAGE,
|
91 |
+
license=_LICENSE,
|
92 |
+
citation=_CITATION,
|
93 |
+
)
|
94 |
+
|
95 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
96 |
+
train_tsv_path = Path(dl_manager.download_and_extract(_URLs["train"]))
|
97 |
+
validation_tsv_path = Path(dl_manager.download_and_extract(_URLs["validation"]))
|
98 |
+
test_tsv_path = Path(dl_manager.download_and_extract(_URLs["test"]))
|
99 |
+
data_files = {
|
100 |
+
"train": train_tsv_path,
|
101 |
+
"validation": validation_tsv_path,
|
102 |
+
"test": test_tsv_path,
|
103 |
+
}
|
104 |
+
|
105 |
+
return [
|
106 |
+
datasets.SplitGenerator(
|
107 |
+
name=datasets.Split.TRAIN,
|
108 |
+
gen_kwargs={"filepath": data_files["train"]},
|
109 |
+
),
|
110 |
+
datasets.SplitGenerator(
|
111 |
+
name=datasets.Split.VALIDATION,
|
112 |
+
gen_kwargs={"filepath": data_files["validation"]},
|
113 |
+
),
|
114 |
+
datasets.SplitGenerator(
|
115 |
+
name=datasets.Split.TEST,
|
116 |
+
gen_kwargs={"filepath": data_files["test"]},
|
117 |
+
),
|
118 |
+
]
|
119 |
+
|
120 |
+
def _generate_examples(self, filepath: Path):
|
121 |
+
df = pd.read_csv(filepath, sep="\t", header=None).reset_index()
|
122 |
+
df.columns = ["id", "sentence", "label"]
|
123 |
+
|
124 |
+
if self.config.schema == "source":
|
125 |
+
for row in df.itertuples():
|
126 |
+
ex = {"index": str(row.id), "sentence": row.sentence, "label": row.label}
|
127 |
+
yield row.id, ex
|
128 |
+
elif self.config.schema == "nusantara_text":
|
129 |
+
for row in df.itertuples():
|
130 |
+
ex = {
|
131 |
+
"id": str(row.id),
|
132 |
+
"text": row.sentence,
|
133 |
+
"label": row.label
|
134 |
+
}
|
135 |
+
yield row.id, ex
|
136 |
+
else:
|
137 |
+
raise ValueError(f"Invalid config: {self.config.name}")
|