Datasets:
Tasks:
Text Classification
Modalities:
Text
Sub-tasks:
sentiment-classification
Size:
10K - 100K
ArXiv:
License:
add loader
Browse files- NusaX-senti.py +116 -0
NusaX-senti.py
ADDED
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pathlib import Path
|
2 |
+
from typing import Dict, List, Tuple
|
3 |
+
|
4 |
+
import datasets
|
5 |
+
import pandas as pd
|
6 |
+
|
7 |
+
_LOCAL = False
|
8 |
+
|
9 |
+
_LANGUAGES = ["ind", "ace", "ban", "bjn", "bbc", "bug", "jav", "mad", "min", "nij", "sun", "eng"] # We follow ISO639-3 language code (https://iso639-3.sil.org/code_tables/639/data)
|
10 |
+
|
11 |
+
_CITATION = """\
|
12 |
+
@misc{winata2022nusax,
|
13 |
+
title={NusaX: Multilingual Parallel Sentiment Dataset for 10 Indonesian Local Languages},
|
14 |
+
author={Winata, Genta Indra and Aji, Alham Fikri and Cahyawijaya,
|
15 |
+
Samuel and Mahendra, Rahmad and Koto, Fajri and Romadhony,
|
16 |
+
Ade and Kurniawan, Kemal and Moeljadi, David and Prasojo,
|
17 |
+
Radityo Eko and Fung, Pascale and Baldwin, Timothy and Lau,
|
18 |
+
Jey Han and Sennrich, Rico and Ruder, Sebastian},
|
19 |
+
year={2022},
|
20 |
+
eprint={2205.15960},
|
21 |
+
archivePrefix={arXiv},
|
22 |
+
primaryClass={cs.CL}
|
23 |
+
}
|
24 |
+
"""
|
25 |
+
|
26 |
+
_DESCRIPTION = """\
|
27 |
+
NusaX is a high-quality multilingual parallel corpus that covers 12 languages, Indonesian, English, and 10 Indonesian local languages, namely Acehnese, Balinese, Banjarese, Buginese, Madurese, Minangkabau, Javanese, Ngaju, Sundanese, and Toba Batak.
|
28 |
+
NusaX-Senti is a 3-labels (positive, neutral, negative) sentiment analysis dataset for 10 Indonesian local languages + Indonesian and English.
|
29 |
+
"""
|
30 |
+
|
31 |
+
_HOMEPAGE = "https://github.com/IndoNLP/nusax/tree/main/datasets/sentiment"
|
32 |
+
|
33 |
+
_LICENSE = "Creative Commons Attribution Share-Alike 4.0 International"
|
34 |
+
|
35 |
+
_SOURCE_VERSION = "1.0.0"
|
36 |
+
|
37 |
+
_URLS = {
|
38 |
+
"train": "https://raw.githubusercontent.com/IndoNLP/nusax/main/datasets/sentiment/{lang}/train.csv",
|
39 |
+
"validation": "https://raw.githubusercontent.com/IndoNLP/nusax/main/datasets/sentiment/{lang}/valid.csv",
|
40 |
+
"test": "https://raw.githubusercontent.com/IndoNLP/nusax/main/datasets/sentiment/{lang}/test.csv",
|
41 |
+
}
|
42 |
+
|
43 |
+
LANGUAGES_MAP = {
|
44 |
+
"ace": "acehnese",
|
45 |
+
"ban": "balinese",
|
46 |
+
"bjn": "banjarese",
|
47 |
+
"bug": "buginese",
|
48 |
+
"eng": "english",
|
49 |
+
"ind": "indonesian",
|
50 |
+
"jav": "javanese",
|
51 |
+
"mad": "madurese",
|
52 |
+
"min": "minangkabau",
|
53 |
+
"nij": "ngaju",
|
54 |
+
"sun": "sundanese",
|
55 |
+
"bbc": "toba_batak",
|
56 |
+
}
|
57 |
+
|
58 |
+
|
59 |
+
class NusaXSenti(datasets.GeneratorBasedBuilder):
|
60 |
+
"""NusaX-Senti is a 3-labels (positive, neutral, negative) sentiment analysis dataset for 10 Indonesian local languages + Indonesian and English."""
|
61 |
+
|
62 |
+
BUILDER_CONFIGS = [
|
63 |
+
datasets.BuilderConfig(
|
64 |
+
name = lang,
|
65 |
+
version = _SOURCE_VERSION,
|
66 |
+
description = f"NusaX-Senti: Sentiment analysis dataset for {lang}")
|
67 |
+
for lang in LANGUAGES_MAP]
|
68 |
+
|
69 |
+
DEFAULT_CONFIG_NAME = "ind"
|
70 |
+
|
71 |
+
def _info(self) -> datasets.DatasetInfo:
|
72 |
+
features = datasets.Features(
|
73 |
+
{
|
74 |
+
"id": datasets.Value("string"),
|
75 |
+
"text": datasets.Value("string"),
|
76 |
+
"lang": datasets.Value("string"),
|
77 |
+
"label": datasets.Value("string"),
|
78 |
+
}
|
79 |
+
)
|
80 |
+
|
81 |
+
return datasets.DatasetInfo(
|
82 |
+
description=_DESCRIPTION,
|
83 |
+
features=features,
|
84 |
+
homepage=_HOMEPAGE,
|
85 |
+
license=_LICENSE,
|
86 |
+
citation=_CITATION,
|
87 |
+
)
|
88 |
+
|
89 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
90 |
+
"""Returns SplitGenerators."""
|
91 |
+
lang = self.config.name
|
92 |
+
train_csv_path = Path(dl_manager.download_and_extract(_URLS["train"].format(lang=LANGUAGES_MAP[lang])))
|
93 |
+
validation_csv_path = Path(dl_manager.download_and_extract(_URLS["validation"].format(lang=LANGUAGES_MAP[lang])))
|
94 |
+
test_csv_path = Path(dl_manager.download_and_extract(_URLS["test"].format(lang=LANGUAGES_MAP[lang])))
|
95 |
+
|
96 |
+
return [
|
97 |
+
datasets.SplitGenerator(
|
98 |
+
name=datasets.Split.TRAIN,
|
99 |
+
gen_kwargs={"filepath": train_csv_path},
|
100 |
+
),
|
101 |
+
datasets.SplitGenerator(
|
102 |
+
name=datasets.Split.VALIDATION,
|
103 |
+
gen_kwargs={"filepath": validation_csv_path},
|
104 |
+
),
|
105 |
+
datasets.SplitGenerator(
|
106 |
+
name=datasets.Split.TEST,
|
107 |
+
gen_kwargs={"filepath": test_csv_path},
|
108 |
+
),
|
109 |
+
]
|
110 |
+
|
111 |
+
def _generate_examples(self, filepath: Path) -> Tuple[int, Dict]:
|
112 |
+
df = pd.read_csv(filepath).reset_index()
|
113 |
+
|
114 |
+
for row in df.itertuples():
|
115 |
+
ex = {"id": str(row.id), "text": row.text, "label": row.label, "lang": self.config.name}
|
116 |
+
yield row.id, ex
|