holylovenia
commited on
Commit
•
e4849a3
1
Parent(s):
726feea
Upload nusax_senti.py with huggingface_hub
Browse files- nusax_senti.py +17 -17
nusax_senti.py
CHANGED
@@ -4,16 +4,16 @@ from typing import Dict, List, Tuple
|
|
4 |
import datasets
|
5 |
import pandas as pd
|
6 |
|
7 |
-
from
|
8 |
-
from
|
9 |
-
from
|
10 |
DEFAULT_SOURCE_VIEW_NAME, Tasks)
|
11 |
|
12 |
_LOCAL = False
|
13 |
|
14 |
_DATASETNAME = "nusax_senti"
|
15 |
_SOURCE_VIEW_NAME = DEFAULT_SOURCE_VIEW_NAME
|
16 |
-
_UNIFIED_VIEW_NAME =
|
17 |
|
18 |
_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)
|
19 |
|
@@ -46,7 +46,7 @@ _SUPPORTED_TASKS = [Tasks.SENTIMENT_ANALYSIS]
|
|
46 |
|
47 |
_SOURCE_VERSION = "1.0.0"
|
48 |
|
49 |
-
|
50 |
|
51 |
_URLS = {
|
52 |
"train": "https://raw.githubusercontent.com/IndoNLP/nusax/main/datasets/sentiment/{lang}/train.csv",
|
@@ -55,13 +55,13 @@ _URLS = {
|
|
55 |
}
|
56 |
|
57 |
|
58 |
-
def
|
59 |
-
"""Construct
|
60 |
-
if schema != "source" and schema != "
|
61 |
raise ValueError(f"Invalid schema: {schema}")
|
62 |
|
63 |
if lang == "":
|
64 |
-
return
|
65 |
name="nusax_senti_{schema}".format(schema=schema),
|
66 |
version=datasets.Version(version),
|
67 |
description="nusax_senti with {schema} schema for all 12 languages".format(schema=schema),
|
@@ -69,7 +69,7 @@ def nusantara_config_constructor(lang, schema, version):
|
|
69 |
subset_id="nusax_senti",
|
70 |
)
|
71 |
else:
|
72 |
-
return
|
73 |
name="nusax_senti_{lang}_{schema}".format(lang=lang, schema=schema),
|
74 |
version=datasets.Version(version),
|
75 |
description="nusax_senti with {schema} schema for {lang} language".format(lang=lang, schema=schema),
|
@@ -98,9 +98,9 @@ class NusaXSenti(datasets.GeneratorBasedBuilder):
|
|
98 |
"""NusaX-Senti is a 3-labels (positive, neutral, negative) sentiment analysis dataset for 10 Indonesian local languages + Indonesian and English."""
|
99 |
|
100 |
BUILDER_CONFIGS = (
|
101 |
-
[
|
102 |
-
+ [
|
103 |
-
+ [
|
104 |
)
|
105 |
|
106 |
DEFAULT_CONFIG_NAME = "nusax_senti_ind_source"
|
@@ -114,7 +114,7 @@ class NusaXSenti(datasets.GeneratorBasedBuilder):
|
|
114 |
"label": datasets.Value("string"),
|
115 |
}
|
116 |
)
|
117 |
-
elif self.config.schema == "
|
118 |
features = schemas.text_features(["negative", "neutral", "positive"])
|
119 |
|
120 |
return datasets.DatasetInfo(
|
@@ -127,7 +127,7 @@ class NusaXSenti(datasets.GeneratorBasedBuilder):
|
|
127 |
|
128 |
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
129 |
"""Returns SplitGenerators."""
|
130 |
-
if self.config.name == "nusax_senti_source" or self.config.name == "
|
131 |
# Load all 12 languages
|
132 |
train_csv_path = dl_manager.download_and_extract([_URLS["train"].format(lang=LANGUAGES_MAP[lang]) for lang in LANGUAGES_MAP])
|
133 |
validation_csv_path = dl_manager.download_and_extract([_URLS["validation"].format(lang=LANGUAGES_MAP[lang]) for lang in LANGUAGES_MAP])
|
@@ -154,10 +154,10 @@ class NusaXSenti(datasets.GeneratorBasedBuilder):
|
|
154 |
]
|
155 |
|
156 |
def _generate_examples(self, filepath: Path) -> Tuple[int, Dict]:
|
157 |
-
if self.config.schema != "source" and self.config.schema != "
|
158 |
raise ValueError(f"Invalid config: {self.config.name}")
|
159 |
|
160 |
-
if self.config.name == "nusax_senti_source" or self.config.name == "
|
161 |
ldf = []
|
162 |
for fp in filepath:
|
163 |
ldf.append(pd.read_csv(fp))
|
|
|
4 |
import datasets
|
5 |
import pandas as pd
|
6 |
|
7 |
+
from seacrowd.utils import schemas
|
8 |
+
from seacrowd.utils.configs import SEACrowdConfig
|
9 |
+
from seacrowd.utils.constants import (DEFAULT_SEACROWD_VIEW_NAME,
|
10 |
DEFAULT_SOURCE_VIEW_NAME, Tasks)
|
11 |
|
12 |
_LOCAL = False
|
13 |
|
14 |
_DATASETNAME = "nusax_senti"
|
15 |
_SOURCE_VIEW_NAME = DEFAULT_SOURCE_VIEW_NAME
|
16 |
+
_UNIFIED_VIEW_NAME = DEFAULT_SEACROWD_VIEW_NAME
|
17 |
|
18 |
_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)
|
19 |
|
|
|
46 |
|
47 |
_SOURCE_VERSION = "1.0.0"
|
48 |
|
49 |
+
_SEACROWD_VERSION = "2024.06.20"
|
50 |
|
51 |
_URLS = {
|
52 |
"train": "https://raw.githubusercontent.com/IndoNLP/nusax/main/datasets/sentiment/{lang}/train.csv",
|
|
|
55 |
}
|
56 |
|
57 |
|
58 |
+
def seacrowd_config_constructor(lang, schema, version):
|
59 |
+
"""Construct SEACrowdConfig with nusax_senti_{lang}_{schema} as the name format"""
|
60 |
+
if schema != "source" and schema != "seacrowd_text":
|
61 |
raise ValueError(f"Invalid schema: {schema}")
|
62 |
|
63 |
if lang == "":
|
64 |
+
return SEACrowdConfig(
|
65 |
name="nusax_senti_{schema}".format(schema=schema),
|
66 |
version=datasets.Version(version),
|
67 |
description="nusax_senti with {schema} schema for all 12 languages".format(schema=schema),
|
|
|
69 |
subset_id="nusax_senti",
|
70 |
)
|
71 |
else:
|
72 |
+
return SEACrowdConfig(
|
73 |
name="nusax_senti_{lang}_{schema}".format(lang=lang, schema=schema),
|
74 |
version=datasets.Version(version),
|
75 |
description="nusax_senti with {schema} schema for {lang} language".format(lang=lang, schema=schema),
|
|
|
98 |
"""NusaX-Senti is a 3-labels (positive, neutral, negative) sentiment analysis dataset for 10 Indonesian local languages + Indonesian and English."""
|
99 |
|
100 |
BUILDER_CONFIGS = (
|
101 |
+
[seacrowd_config_constructor(lang, "source", _SOURCE_VERSION) for lang in LANGUAGES_MAP]
|
102 |
+
+ [seacrowd_config_constructor(lang, "seacrowd_text", _SEACROWD_VERSION) for lang in LANGUAGES_MAP]
|
103 |
+
+ [seacrowd_config_constructor("", "source", _SOURCE_VERSION), seacrowd_config_constructor("", "seacrowd_text", _SEACROWD_VERSION)]
|
104 |
)
|
105 |
|
106 |
DEFAULT_CONFIG_NAME = "nusax_senti_ind_source"
|
|
|
114 |
"label": datasets.Value("string"),
|
115 |
}
|
116 |
)
|
117 |
+
elif self.config.schema == "seacrowd_text":
|
118 |
features = schemas.text_features(["negative", "neutral", "positive"])
|
119 |
|
120 |
return datasets.DatasetInfo(
|
|
|
127 |
|
128 |
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
129 |
"""Returns SplitGenerators."""
|
130 |
+
if self.config.name == "nusax_senti_source" or self.config.name == "nusax_senti_seacrowd_text":
|
131 |
# Load all 12 languages
|
132 |
train_csv_path = dl_manager.download_and_extract([_URLS["train"].format(lang=LANGUAGES_MAP[lang]) for lang in LANGUAGES_MAP])
|
133 |
validation_csv_path = dl_manager.download_and_extract([_URLS["validation"].format(lang=LANGUAGES_MAP[lang]) for lang in LANGUAGES_MAP])
|
|
|
154 |
]
|
155 |
|
156 |
def _generate_examples(self, filepath: Path) -> Tuple[int, Dict]:
|
157 |
+
if self.config.schema != "source" and self.config.schema != "seacrowd_text":
|
158 |
raise ValueError(f"Invalid config: {self.config.name}")
|
159 |
|
160 |
+
if self.config.name == "nusax_senti_source" or self.config.name == "nusax_senti_seacrowd_text":
|
161 |
ldf = []
|
162 |
for fp in filepath:
|
163 |
ldf.append(pd.read_csv(fp))
|