holylovenia
commited on
Commit
•
ec15dcf
1
Parent(s):
b5b1745
Upload nusaparagraph_rhetoric.py with huggingface_hub
Browse files- nusaparagraph_rhetoric.py +19 -19
nusaparagraph_rhetoric.py
CHANGED
@@ -2,14 +2,14 @@ from pathlib import Path
|
|
2 |
from typing import Dict, List, Tuple
|
3 |
import datasets
|
4 |
import pandas as pd
|
5 |
-
from
|
6 |
-
from
|
7 |
-
from
|
8 |
DEFAULT_SOURCE_VIEW_NAME, Tasks)
|
9 |
_LOCAL = False
|
10 |
_DATASETNAME = "nusaparagraph_rhetoric"
|
11 |
_SOURCE_VIEW_NAME = DEFAULT_SOURCE_VIEW_NAME
|
12 |
-
_UNIFIED_VIEW_NAME =
|
13 |
_LANGUAGES = [
|
14 |
"btk", "bew", "bug", "jav", "mad", "mak", "min", "mui", "rej", "sun"
|
15 |
] # We follow ISO639-3 language code (https://iso639-3.sil.org/code_tables/639/data)
|
@@ -31,7 +31,7 @@ _HOMEPAGE = "https://github.com/IndoNLP/nusa-writes"
|
|
31 |
_LICENSE = "Creative Commons Attribution Share-Alike 4.0 International"
|
32 |
_SUPPORTED_TASKS = [Tasks.RHETORIC_MODE_CLASSIFICATION]
|
33 |
_SOURCE_VERSION = "1.0.0"
|
34 |
-
|
35 |
_URLS = {
|
36 |
"train":
|
37 |
"https://raw.githubusercontent.com/IndoNLP/nusa-writes/main/data/nusa_alinea-paragraph-{lang}-train.csv",
|
@@ -40,12 +40,12 @@ _URLS = {
|
|
40 |
"test":
|
41 |
"https://raw.githubusercontent.com/IndoNLP/nusa-writes/main/data/nusa_alinea-paragraph-{lang}-test.csv",
|
42 |
}
|
43 |
-
def
|
44 |
-
"""Construct
|
45 |
-
if schema != "source" and schema != "
|
46 |
raise ValueError(f"Invalid schema: {schema}")
|
47 |
if lang == "":
|
48 |
-
return
|
49 |
name="nusaparagraph_rhetoric_{schema}".format(schema=schema),
|
50 |
version=datasets.Version(version),
|
51 |
description=
|
@@ -55,7 +55,7 @@ def nusantara_config_constructor(lang, schema, version):
|
|
55 |
subset_id="nusaparagraph_rhetoric",
|
56 |
)
|
57 |
else:
|
58 |
-
return
|
59 |
name="nusaparagraph_rhetoric_{lang}_{schema}".format(lang=lang,
|
60 |
schema=schema),
|
61 |
version=datasets.Version(version),
|
@@ -80,15 +80,15 @@ LANGUAGES_MAP = {
|
|
80 |
class NusaParagraphRhetoric(datasets.GeneratorBasedBuilder):
|
81 |
"""NusaParagraph-Rhetoric is a 50labels (narrative, persuasive, argumentative, descriptive, and expository) rhetoric mode classification dataset for 10 Indonesian local languages."""
|
82 |
BUILDER_CONFIGS = ([
|
83 |
-
|
84 |
for lang in LANGUAGES_MAP
|
85 |
] + [
|
86 |
-
|
87 |
-
|
88 |
for lang in LANGUAGES_MAP
|
89 |
] + [
|
90 |
-
|
91 |
-
|
92 |
])
|
93 |
DEFAULT_CONFIG_NAME = "nusaparagraph_rhetoric_ind_source"
|
94 |
def _info(self) -> datasets.DatasetInfo:
|
@@ -98,7 +98,7 @@ class NusaParagraphRhetoric(datasets.GeneratorBasedBuilder):
|
|
98 |
"text": datasets.Value("string"),
|
99 |
"label": datasets.Value("string"),
|
100 |
})
|
101 |
-
elif self.config.schema == "
|
102 |
features = schemas.text_features([
|
103 |
"narrative", "persuasive", "argumentative", "descriptive", "expository"
|
104 |
])
|
@@ -113,7 +113,7 @@ class NusaParagraphRhetoric(datasets.GeneratorBasedBuilder):
|
|
113 |
self, dl_manager: datasets.DownloadManager
|
114 |
) -> List[datasets.SplitGenerator]:
|
115 |
"""Returns SplitGenerators."""
|
116 |
-
if self.config.name == "nusaparagraph_rhetoric_source" or self.config.name == "
|
117 |
# Load all 12 languages
|
118 |
train_csv_path = dl_manager.download_and_extract([
|
119 |
_URLS["train"].format(lang=lang)
|
@@ -153,9 +153,9 @@ class NusaParagraphRhetoric(datasets.GeneratorBasedBuilder):
|
|
153 |
),
|
154 |
]
|
155 |
def _generate_examples(self, filepath: Path) -> Tuple[int, Dict]:
|
156 |
-
if self.config.schema != "source" and self.config.schema != "
|
157 |
raise ValueError(f"Invalid config: {self.config.name}")
|
158 |
-
if self.config.name == "nusaparagraph_rhetoric_source" or self.config.name == "
|
159 |
ldf = []
|
160 |
for fp in filepath:
|
161 |
ldf.append(pd.read_csv(fp))
|
|
|
2 |
from typing import Dict, List, Tuple
|
3 |
import datasets
|
4 |
import pandas as pd
|
5 |
+
from seacrowd.utils import schemas
|
6 |
+
from seacrowd.utils.configs import SEACrowdConfig
|
7 |
+
from seacrowd.utils.constants import (DEFAULT_SEACROWD_VIEW_NAME,
|
8 |
DEFAULT_SOURCE_VIEW_NAME, Tasks)
|
9 |
_LOCAL = False
|
10 |
_DATASETNAME = "nusaparagraph_rhetoric"
|
11 |
_SOURCE_VIEW_NAME = DEFAULT_SOURCE_VIEW_NAME
|
12 |
+
_UNIFIED_VIEW_NAME = DEFAULT_SEACROWD_VIEW_NAME
|
13 |
_LANGUAGES = [
|
14 |
"btk", "bew", "bug", "jav", "mad", "mak", "min", "mui", "rej", "sun"
|
15 |
] # We follow ISO639-3 language code (https://iso639-3.sil.org/code_tables/639/data)
|
|
|
31 |
_LICENSE = "Creative Commons Attribution Share-Alike 4.0 International"
|
32 |
_SUPPORTED_TASKS = [Tasks.RHETORIC_MODE_CLASSIFICATION]
|
33 |
_SOURCE_VERSION = "1.0.0"
|
34 |
+
_SEACROWD_VERSION = "2024.06.20"
|
35 |
_URLS = {
|
36 |
"train":
|
37 |
"https://raw.githubusercontent.com/IndoNLP/nusa-writes/main/data/nusa_alinea-paragraph-{lang}-train.csv",
|
|
|
40 |
"test":
|
41 |
"https://raw.githubusercontent.com/IndoNLP/nusa-writes/main/data/nusa_alinea-paragraph-{lang}-test.csv",
|
42 |
}
|
43 |
+
def seacrowd_config_constructor(lang, schema, version):
|
44 |
+
"""Construct SEACrowdConfig with nusaparagraph_rhetoric_{lang}_{schema} as the name format"""
|
45 |
+
if schema != "source" and schema != "seacrowd_text":
|
46 |
raise ValueError(f"Invalid schema: {schema}")
|
47 |
if lang == "":
|
48 |
+
return SEACrowdConfig(
|
49 |
name="nusaparagraph_rhetoric_{schema}".format(schema=schema),
|
50 |
version=datasets.Version(version),
|
51 |
description=
|
|
|
55 |
subset_id="nusaparagraph_rhetoric",
|
56 |
)
|
57 |
else:
|
58 |
+
return SEACrowdConfig(
|
59 |
name="nusaparagraph_rhetoric_{lang}_{schema}".format(lang=lang,
|
60 |
schema=schema),
|
61 |
version=datasets.Version(version),
|
|
|
80 |
class NusaParagraphRhetoric(datasets.GeneratorBasedBuilder):
|
81 |
"""NusaParagraph-Rhetoric is a 50labels (narrative, persuasive, argumentative, descriptive, and expository) rhetoric mode classification dataset for 10 Indonesian local languages."""
|
82 |
BUILDER_CONFIGS = ([
|
83 |
+
seacrowd_config_constructor(lang, "source", _SOURCE_VERSION)
|
84 |
for lang in LANGUAGES_MAP
|
85 |
] + [
|
86 |
+
seacrowd_config_constructor(lang, "seacrowd_text",
|
87 |
+
_SEACROWD_VERSION)
|
88 |
for lang in LANGUAGES_MAP
|
89 |
] + [
|
90 |
+
seacrowd_config_constructor("", "source", _SOURCE_VERSION),
|
91 |
+
seacrowd_config_constructor("", "seacrowd_text", _SEACROWD_VERSION)
|
92 |
])
|
93 |
DEFAULT_CONFIG_NAME = "nusaparagraph_rhetoric_ind_source"
|
94 |
def _info(self) -> datasets.DatasetInfo:
|
|
|
98 |
"text": datasets.Value("string"),
|
99 |
"label": datasets.Value("string"),
|
100 |
})
|
101 |
+
elif self.config.schema == "seacrowd_text":
|
102 |
features = schemas.text_features([
|
103 |
"narrative", "persuasive", "argumentative", "descriptive", "expository"
|
104 |
])
|
|
|
113 |
self, dl_manager: datasets.DownloadManager
|
114 |
) -> List[datasets.SplitGenerator]:
|
115 |
"""Returns SplitGenerators."""
|
116 |
+
if self.config.name == "nusaparagraph_rhetoric_source" or self.config.name == "nusaparagraph_rhetoric_seacrowd_text":
|
117 |
# Load all 12 languages
|
118 |
train_csv_path = dl_manager.download_and_extract([
|
119 |
_URLS["train"].format(lang=lang)
|
|
|
153 |
),
|
154 |
]
|
155 |
def _generate_examples(self, filepath: Path) -> Tuple[int, Dict]:
|
156 |
+
if self.config.schema != "source" and self.config.schema != "seacrowd_text":
|
157 |
raise ValueError(f"Invalid config: {self.config.name}")
|
158 |
+
if self.config.name == "nusaparagraph_rhetoric_source" or self.config.name == "nusaparagraph_rhetoric_seacrowd_text":
|
159 |
ldf = []
|
160 |
for fp in filepath:
|
161 |
ldf.append(pd.read_csv(fp))
|