Upload nusatranslation_emot.py with huggingface_hub
Browse files- nusatranslation_emot.py +17 -17
nusatranslation_emot.py
CHANGED
|
@@ -4,15 +4,15 @@ from typing import Dict, List, Tuple
|
|
| 4 |
import datasets
|
| 5 |
import pandas as pd
|
| 6 |
|
| 7 |
-
from
|
| 8 |
-
from
|
| 9 |
-
from
|
| 10 |
|
| 11 |
_LOCAL = False
|
| 12 |
|
| 13 |
_DATASETNAME = "nusatranslation_emot"
|
| 14 |
_SOURCE_VIEW_NAME = DEFAULT_SOURCE_VIEW_NAME
|
| 15 |
-
_UNIFIED_VIEW_NAME =
|
| 16 |
|
| 17 |
_LANGUAGES = ["abs", "btk", "bew", "bug", "jav", "mad", "mak", "min", "mui", "rej", "sun"] # We follow ISO639-3 language code (https://iso639-3.sil.org/code_tables/639/data)
|
| 18 |
|
|
@@ -40,7 +40,7 @@ _SUPPORTED_TASKS = [Tasks.EMOTION_CLASSIFICATION]
|
|
| 40 |
|
| 41 |
_SOURCE_VERSION = "1.0.0"
|
| 42 |
|
| 43 |
-
|
| 44 |
|
| 45 |
_URLS = {
|
| 46 |
"train": "https://raw.githubusercontent.com/IndoNLP/nusa-writes/main/data/nusa_kalimat-emot-{lang}-train.csv",
|
|
@@ -49,13 +49,13 @@ _URLS = {
|
|
| 49 |
}
|
| 50 |
|
| 51 |
|
| 52 |
-
def
|
| 53 |
-
"""Construct
|
| 54 |
-
if schema != "source" and schema != "
|
| 55 |
raise ValueError(f"Invalid schema: {schema}")
|
| 56 |
|
| 57 |
if lang == "":
|
| 58 |
-
return
|
| 59 |
name="nusatranslation_emot_{schema}".format(schema=schema),
|
| 60 |
version=datasets.Version(version),
|
| 61 |
description="nusatranslation_emot with {schema} schema for all 12 languages".format(schema=schema),
|
|
@@ -63,7 +63,7 @@ def nusantara_config_constructor(lang, schema, version):
|
|
| 63 |
subset_id="nusatranslation_emot",
|
| 64 |
)
|
| 65 |
else:
|
| 66 |
-
return
|
| 67 |
name="nusatranslation_emot_{lang}_{schema}".format(lang=lang, schema=schema),
|
| 68 |
version=datasets.Version(version),
|
| 69 |
description="nusatranslation_emot with {schema} schema for {lang} language".format(lang=lang, schema=schema),
|
|
@@ -91,9 +91,9 @@ class NusaTranslationEmot(datasets.GeneratorBasedBuilder):
|
|
| 91 |
"""NusaTranslationEmot is a 5-labels (fear, sadness, happy, anger, love) emotion classification dataset for 11 Indonesian local languages + Indonesian and English."""
|
| 92 |
|
| 93 |
BUILDER_CONFIGS = (
|
| 94 |
-
[
|
| 95 |
-
+ [
|
| 96 |
-
+ [
|
| 97 |
)
|
| 98 |
|
| 99 |
DEFAULT_CONFIG_NAME = "nusatranslation_emot_source"
|
|
@@ -107,7 +107,7 @@ class NusaTranslationEmot(datasets.GeneratorBasedBuilder):
|
|
| 107 |
"label": datasets.Value("string"),
|
| 108 |
}
|
| 109 |
)
|
| 110 |
-
elif self.config.schema == "
|
| 111 |
features = schemas.text_features(["fear", "sadness", "happy", "anger", "love"])
|
| 112 |
|
| 113 |
return datasets.DatasetInfo(
|
|
@@ -120,7 +120,7 @@ class NusaTranslationEmot(datasets.GeneratorBasedBuilder):
|
|
| 120 |
|
| 121 |
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
| 122 |
"""Returns SplitGenerators."""
|
| 123 |
-
if self.config.name == "nusatranslation_emot_source" or self.config.name == "
|
| 124 |
# Load all 12 languages
|
| 125 |
train_csv_path = dl_manager.download_and_extract([_URLS["train"].format(lang=lang) for lang in LANGUAGES_MAP])
|
| 126 |
validation_csv_path = dl_manager.download_and_extract([_URLS["validation"].format(lang=lang) for lang in LANGUAGES_MAP])
|
|
@@ -147,10 +147,10 @@ class NusaTranslationEmot(datasets.GeneratorBasedBuilder):
|
|
| 147 |
]
|
| 148 |
|
| 149 |
def _generate_examples(self, filepath: Path) -> Tuple[int, Dict]:
|
| 150 |
-
if self.config.schema != "source" and self.config.schema != "
|
| 151 |
raise ValueError(f"Invalid config: {self.config.name}")
|
| 152 |
|
| 153 |
-
if self.config.name == "nusatranslation_emot_source" or self.config.name == "
|
| 154 |
ldf = []
|
| 155 |
for fp in filepath:
|
| 156 |
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, DEFAULT_SOURCE_VIEW_NAME, Tasks
|
| 10 |
|
| 11 |
_LOCAL = False
|
| 12 |
|
| 13 |
_DATASETNAME = "nusatranslation_emot"
|
| 14 |
_SOURCE_VIEW_NAME = DEFAULT_SOURCE_VIEW_NAME
|
| 15 |
+
_UNIFIED_VIEW_NAME = DEFAULT_SEACROWD_VIEW_NAME
|
| 16 |
|
| 17 |
_LANGUAGES = ["abs", "btk", "bew", "bug", "jav", "mad", "mak", "min", "mui", "rej", "sun"] # We follow ISO639-3 language code (https://iso639-3.sil.org/code_tables/639/data)
|
| 18 |
|
|
|
|
| 40 |
|
| 41 |
_SOURCE_VERSION = "1.0.0"
|
| 42 |
|
| 43 |
+
_SEACROWD_VERSION = "2024.06.20"
|
| 44 |
|
| 45 |
_URLS = {
|
| 46 |
"train": "https://raw.githubusercontent.com/IndoNLP/nusa-writes/main/data/nusa_kalimat-emot-{lang}-train.csv",
|
|
|
|
| 49 |
}
|
| 50 |
|
| 51 |
|
| 52 |
+
def seacrowd_config_constructor(lang, schema, version):
|
| 53 |
+
"""Construct SEACrowdConfig with nusatranslation_emot_{lang}_{schema} as the name format"""
|
| 54 |
+
if schema != "source" and schema != "seacrowd_text":
|
| 55 |
raise ValueError(f"Invalid schema: {schema}")
|
| 56 |
|
| 57 |
if lang == "":
|
| 58 |
+
return SEACrowdConfig(
|
| 59 |
name="nusatranslation_emot_{schema}".format(schema=schema),
|
| 60 |
version=datasets.Version(version),
|
| 61 |
description="nusatranslation_emot with {schema} schema for all 12 languages".format(schema=schema),
|
|
|
|
| 63 |
subset_id="nusatranslation_emot",
|
| 64 |
)
|
| 65 |
else:
|
| 66 |
+
return SEACrowdConfig(
|
| 67 |
name="nusatranslation_emot_{lang}_{schema}".format(lang=lang, schema=schema),
|
| 68 |
version=datasets.Version(version),
|
| 69 |
description="nusatranslation_emot with {schema} schema for {lang} language".format(lang=lang, schema=schema),
|
|
|
|
| 91 |
"""NusaTranslationEmot is a 5-labels (fear, sadness, happy, anger, love) emotion classification dataset for 11 Indonesian local languages + Indonesian and English."""
|
| 92 |
|
| 93 |
BUILDER_CONFIGS = (
|
| 94 |
+
[seacrowd_config_constructor(lang, "source", _SOURCE_VERSION) for lang in LANGUAGES_MAP]
|
| 95 |
+
+ [seacrowd_config_constructor(lang, "seacrowd_text", _SEACROWD_VERSION) for lang in LANGUAGES_MAP]
|
| 96 |
+
+ [seacrowd_config_constructor("", "source", _SOURCE_VERSION), seacrowd_config_constructor("", "seacrowd_text", _SEACROWD_VERSION)]
|
| 97 |
)
|
| 98 |
|
| 99 |
DEFAULT_CONFIG_NAME = "nusatranslation_emot_source"
|
|
|
|
| 107 |
"label": datasets.Value("string"),
|
| 108 |
}
|
| 109 |
)
|
| 110 |
+
elif self.config.schema == "seacrowd_text":
|
| 111 |
features = schemas.text_features(["fear", "sadness", "happy", "anger", "love"])
|
| 112 |
|
| 113 |
return datasets.DatasetInfo(
|
|
|
|
| 120 |
|
| 121 |
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
| 122 |
"""Returns SplitGenerators."""
|
| 123 |
+
if self.config.name == "nusatranslation_emot_source" or self.config.name == "nusatranslation_emot_seacrowd_text":
|
| 124 |
# Load all 12 languages
|
| 125 |
train_csv_path = dl_manager.download_and_extract([_URLS["train"].format(lang=lang) for lang in LANGUAGES_MAP])
|
| 126 |
validation_csv_path = dl_manager.download_and_extract([_URLS["validation"].format(lang=lang) for lang in LANGUAGES_MAP])
|
|
|
|
| 147 |
]
|
| 148 |
|
| 149 |
def _generate_examples(self, filepath: Path) -> Tuple[int, Dict]:
|
| 150 |
+
if self.config.schema != "source" and self.config.schema != "seacrowd_text":
|
| 151 |
raise ValueError(f"Invalid config: {self.config.name}")
|
| 152 |
|
| 153 |
+
if self.config.name == "nusatranslation_emot_source" or self.config.name == "nusatranslation_emot_seacrowd_text":
|
| 154 |
ldf = []
|
| 155 |
for fp in filepath:
|
| 156 |
ldf.append(pd.read_csv(fp))
|