Upload melayu_sarawak.py with huggingface_hub
Browse files- melayu_sarawak.py +146 -0
melayu_sarawak.py
ADDED
@@ -0,0 +1,146 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
from pathlib import Path
|
3 |
+
from typing import Dict, List, Tuple
|
4 |
+
|
5 |
+
import datasets
|
6 |
+
|
7 |
+
from seacrowd.utils import schemas
|
8 |
+
from seacrowd.utils.configs import SEACrowdConfig
|
9 |
+
from seacrowd.utils.constants import TASK_TO_SCHEMA, Licenses, Tasks
|
10 |
+
|
11 |
+
_DATASETNAME = "melayu_sarawak"
|
12 |
+
|
13 |
+
|
14 |
+
_DESCRIPTION = """\
|
15 |
+
Korpus Variasi Bahasa Melayu: Sarawak is a language corpus sourced from various folklores in Melayu Sarawak dialect.
|
16 |
+
"""
|
17 |
+
|
18 |
+
|
19 |
+
_HOMEPAGE = "https://github.com/matbahasa/Melayu_Sarawak"
|
20 |
+
|
21 |
+
_CITATION = """\
|
22 |
+
@misc{melayusarawak,
|
23 |
+
author = {Hiroki Nomoto},
|
24 |
+
title = {Melayu_Sabah},
|
25 |
+
year = {2020},
|
26 |
+
publisher = {GitHub},
|
27 |
+
journal = {GitHub repository},
|
28 |
+
howpublished = {\\url{https://github.com/matbahasa/Melayu_Sarawak}},
|
29 |
+
commit = {a175f691f9db94d7b4f971e7a93b7cc001c0ed47}
|
30 |
+
}
|
31 |
+
"""
|
32 |
+
|
33 |
+
_LANGUAGES = ["zlm"]
|
34 |
+
|
35 |
+
_LICENSE = Licenses.CC_BY_4_0.value
|
36 |
+
|
37 |
+
_LOCAL = False
|
38 |
+
|
39 |
+
_URLS = {
|
40 |
+
"sarawak201801": "https://raw.githubusercontent.com/matbahasa/Melayu_Sarawak/master/Sarawak201801.txt",
|
41 |
+
"sarawak201802": "https://raw.githubusercontent.com/matbahasa/Melayu_Sarawak/master/Sarawak201802.txt",
|
42 |
+
"sarawak201803": "https://raw.githubusercontent.com/matbahasa/Melayu_Sarawak/master/Sarawak201803.txt",
|
43 |
+
"sarawak201804": "https://raw.githubusercontent.com/matbahasa/Melayu_Sarawak/master/Sarawak201804.txt",
|
44 |
+
"sarawak201805": "https://raw.githubusercontent.com/matbahasa/Melayu_Sarawak/master/Sarawak201805.txt",
|
45 |
+
"sarawak201806": "https://raw.githubusercontent.com/matbahasa/Melayu_Sarawak/master/Sarawak201806.txt",
|
46 |
+
"sarawak201807": "https://raw.githubusercontent.com/matbahasa/Melayu_Sarawak/master/Sarawak201807.txt",
|
47 |
+
"sarawak201808": "https://raw.githubusercontent.com/matbahasa/Melayu_Sarawak/master/Sarawak201808.txt",
|
48 |
+
"sarawak201809": "https://raw.githubusercontent.com/matbahasa/Melayu_Sarawak/master/Sarawak201809.txt",
|
49 |
+
"sarawak201810": "https://raw.githubusercontent.com/matbahasa/Melayu_Sarawak/master/Sarawak201810.txt",
|
50 |
+
"sarawak201811": "https://raw.githubusercontent.com/matbahasa/Melayu_Sarawak/master/Sarawak201811.txt",
|
51 |
+
"sarawak201812": "https://raw.githubusercontent.com/matbahasa/Melayu_Sarawak/master/Sarawak201812.txt",
|
52 |
+
"sarawak201813": "https://raw.githubusercontent.com/matbahasa/Melayu_Sarawak/master/Sarawak201813.txt",
|
53 |
+
"sarawak201814": "https://raw.githubusercontent.com/matbahasa/Melayu_Sarawak/master/Sarawak201814.txt",
|
54 |
+
"sarawak201815": "https://raw.githubusercontent.com/matbahasa/Melayu_Sarawak/master/Sarawak201815.txt",
|
55 |
+
"sarawak201817": "https://raw.githubusercontent.com/matbahasa/Melayu_Sarawak/master/Sarawak201817.txt",
|
56 |
+
"sarawak201818": "https://raw.githubusercontent.com/matbahasa/Melayu_Sarawak/master/Sarawak201818.txt",
|
57 |
+
"sarawak201819": "https://raw.githubusercontent.com/matbahasa/Melayu_Sarawak/master/Sarawak201819.txt",
|
58 |
+
"sarawak201820": "https://raw.githubusercontent.com/matbahasa/Melayu_Sarawak/master/Sarawak201820.txt",
|
59 |
+
"sarawak201821": "https://raw.githubusercontent.com/matbahasa/Melayu_Sarawak/master/Sarawak201821.txt",
|
60 |
+
"sarawak201822": "https://raw.githubusercontent.com/matbahasa/Melayu_Sarawak/master/Sarawak201822.txt",
|
61 |
+
"sarawak201823": "https://raw.githubusercontent.com/matbahasa/Melayu_Sarawak/master/Sarawak201823.txt",
|
62 |
+
"sarawak201824": "https://raw.githubusercontent.com/matbahasa/Melayu_Sarawak/master/Sarawak201824.txt",
|
63 |
+
"sarawak201825": "https://raw.githubusercontent.com/matbahasa/Melayu_Sarawak/master/Sarawak201825.txt",
|
64 |
+
"sarawak201826": "https://raw.githubusercontent.com/matbahasa/Melayu_Sarawak/master/Sarawak201826.txt",
|
65 |
+
"sarawak201827": "https://raw.githubusercontent.com/matbahasa/Melayu_Sarawak/master/Sarawak201827.txt",
|
66 |
+
"sarawak201828": "https://raw.githubusercontent.com/matbahasa/Melayu_Sarawak/master/Sarawak201828.txt",
|
67 |
+
"sarawak201829": "https://raw.githubusercontent.com/matbahasa/Melayu_Sarawak/master/Sarawak201829.txt",
|
68 |
+
}
|
69 |
+
|
70 |
+
_SUPPORTED_TASKS = [Tasks.SELF_SUPERVISED_PRETRAINING]
|
71 |
+
|
72 |
+
_SOURCE_VERSION = "1.0.0"
|
73 |
+
|
74 |
+
_SEACROWD_VERSION = "2024.06.20"
|
75 |
+
|
76 |
+
|
77 |
+
class MelayuSarawakDataset(datasets.GeneratorBasedBuilder):
|
78 |
+
"""Korpus Variasi Bahasa Melayu:
|
79 |
+
Sarawak is a language corpus sourced from various folklores in Melayu Sarawak dialect."""
|
80 |
+
|
81 |
+
SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
|
82 |
+
SEACROWD_VERSION = datasets.Version(_SEACROWD_VERSION)
|
83 |
+
|
84 |
+
SEACROWD_SCHEMA_NAME = TASK_TO_SCHEMA[_SUPPORTED_TASKS[0]].lower()
|
85 |
+
|
86 |
+
BUILDER_CONFIGS = [
|
87 |
+
SEACrowdConfig(
|
88 |
+
name=f"{_DATASETNAME}_source",
|
89 |
+
version=SOURCE_VERSION,
|
90 |
+
description=f"{_DATASETNAME} source schema",
|
91 |
+
schema="source",
|
92 |
+
subset_id=f"{_DATASETNAME}",
|
93 |
+
),
|
94 |
+
SEACrowdConfig(
|
95 |
+
name=f"{_DATASETNAME}_seacrowd_{SEACROWD_SCHEMA_NAME}",
|
96 |
+
version=SEACROWD_VERSION,
|
97 |
+
description=f"{_DATASETNAME} SEACrowd schema",
|
98 |
+
schema=f"seacrowd_{SEACROWD_SCHEMA_NAME}",
|
99 |
+
subset_id=f"{_DATASETNAME}",
|
100 |
+
),
|
101 |
+
]
|
102 |
+
|
103 |
+
DEFAULT_CONFIG_NAME = f"{_DATASETNAME}_source"
|
104 |
+
|
105 |
+
def _info(self) -> datasets.DatasetInfo:
|
106 |
+
if self.config.schema == "source":
|
107 |
+
features = datasets.Features(
|
108 |
+
{
|
109 |
+
"id": datasets.Value("string"),
|
110 |
+
"text": datasets.Value("string"),
|
111 |
+
}
|
112 |
+
)
|
113 |
+
elif self.config.schema == "seacrowd_ssp":
|
114 |
+
features = schemas.self_supervised_pretraining.features
|
115 |
+
|
116 |
+
return datasets.DatasetInfo(
|
117 |
+
description=_DESCRIPTION,
|
118 |
+
features=features,
|
119 |
+
homepage=_HOMEPAGE,
|
120 |
+
license=_LICENSE,
|
121 |
+
citation=_CITATION,
|
122 |
+
)
|
123 |
+
|
124 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
125 |
+
"""Returns SplitGenerators."""
|
126 |
+
|
127 |
+
urls = [_URLS[key] for key in _URLS.keys()]
|
128 |
+
data_path = dl_manager.download_and_extract(urls)
|
129 |
+
|
130 |
+
return [
|
131 |
+
datasets.SplitGenerator(
|
132 |
+
name=datasets.Split.TRAIN,
|
133 |
+
gen_kwargs={"filepath": data_path[0], "split": "train", "other_path": data_path[1:]},
|
134 |
+
)
|
135 |
+
]
|
136 |
+
|
137 |
+
def _generate_examples(self, filepath: Path, split: str, other_path: List) -> Tuple[int, Dict]:
|
138 |
+
"""Yields examples as (key, example) tuples."""
|
139 |
+
filepaths = [filepath] + other_path
|
140 |
+
data = []
|
141 |
+
for filepath in filepaths:
|
142 |
+
with open(filepath, "r") as f:
|
143 |
+
data.append([line.rstrip() for line in f.readlines()])
|
144 |
+
|
145 |
+
for id, text in enumerate(data):
|
146 |
+
yield id, {"id": id, "text": text}
|