holylovenia
commited on
Upload melayu_standard_lisan.py with huggingface_hub
Browse files- melayu_standard_lisan.py +162 -0
melayu_standard_lisan.py
ADDED
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2022 The HuggingFace Datasets Authors and the current dataset script contributor.
|
3 |
+
#
|
4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5 |
+
# you may not use this file except in compliance with the License.
|
6 |
+
# You may obtain a copy of the License at
|
7 |
+
#
|
8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9 |
+
#
|
10 |
+
# Unless required by applicable law or agreed to in writing, software
|
11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 |
+
# See the License for the specific language governing permissions and
|
14 |
+
# limitations under the License.
|
15 |
+
import os
|
16 |
+
from pathlib import Path
|
17 |
+
from typing import Dict, List, Tuple
|
18 |
+
|
19 |
+
import datasets
|
20 |
+
|
21 |
+
from seacrowd.utils import schemas
|
22 |
+
from seacrowd.utils.configs import SEACrowdConfig
|
23 |
+
from seacrowd.utils.constants import TASK_TO_SCHEMA, Licenses, Tasks
|
24 |
+
|
25 |
+
_CITATION = """\
|
26 |
+
@misc{nomoto2018melayustandardlisan,
|
27 |
+
author = {Hiroki Nomoto},
|
28 |
+
title = {Korpus Variasi Bahasa Melayu: Standard Lisan},
|
29 |
+
year = {2018},
|
30 |
+
url = {https://github.com/matbahasa/Melayu_Standard_Lisan}
|
31 |
+
}
|
32 |
+
"""
|
33 |
+
|
34 |
+
_DATASETNAME = "melayu_standard_lisan"
|
35 |
+
|
36 |
+
|
37 |
+
_DESCRIPTION = """\
|
38 |
+
Korpus Variasi Bahasa Melayu: Standard Lisan is a language corpus sourced from monologues of various melayu folklores.
|
39 |
+
"""
|
40 |
+
|
41 |
+
|
42 |
+
_HOMEPAGE = "https://github.com/matbahasa/Melayu_Standard_Lisan"
|
43 |
+
|
44 |
+
|
45 |
+
_LANGUAGES = ["zlm"]
|
46 |
+
|
47 |
+
_LICENSE = Licenses.CC_BY_4_0.value
|
48 |
+
|
49 |
+
_LOCAL = False
|
50 |
+
|
51 |
+
_URLS = {
|
52 |
+
"kl201701": "https://raw.githubusercontent.com/matbahasa/Melayu_Standard_Lisan/master/KL201701.txt",
|
53 |
+
"kl201702": "https://raw.githubusercontent.com/matbahasa/Melayu_Standard_Lisan/master/KL201702.txt",
|
54 |
+
"kl201703": "https://raw.githubusercontent.com/matbahasa/Melayu_Standard_Lisan/master/KL201703.txt",
|
55 |
+
"kl201704": "https://raw.githubusercontent.com/matbahasa/Melayu_Standard_Lisan/master/KL201704.txt",
|
56 |
+
"kl201705": "https://raw.githubusercontent.com/matbahasa/Melayu_Standard_Lisan/master/KL201705.txt",
|
57 |
+
"kl201706": "https://raw.githubusercontent.com/matbahasa/Melayu_Standard_Lisan/master/KL201706.txt",
|
58 |
+
"kl201707": "https://raw.githubusercontent.com/matbahasa/Melayu_Standard_Lisan/master/KL201707.txt",
|
59 |
+
"kl201708": "https://raw.githubusercontent.com/matbahasa/Melayu_Standard_Lisan/master/KL201708.txt",
|
60 |
+
"kl201709": "https://raw.githubusercontent.com/matbahasa/Melayu_Standard_Lisan/master/KL201709.txt",
|
61 |
+
"kl201710": "https://raw.githubusercontent.com/matbahasa/Melayu_Standard_Lisan/master/KL201710.txt",
|
62 |
+
"kl201711": "https://raw.githubusercontent.com/matbahasa/Melayu_Standard_Lisan/master/KL201711.txt",
|
63 |
+
"kl201712": "https://raw.githubusercontent.com/matbahasa/Melayu_Standard_Lisan/master/KL201712.txt",
|
64 |
+
"kl201713": "https://raw.githubusercontent.com/matbahasa/Melayu_Standard_Lisan/master/KL201713.txt",
|
65 |
+
"kl201714": "https://raw.githubusercontent.com/matbahasa/Melayu_Standard_Lisan/master/KL201714.txt",
|
66 |
+
"kl201715": "https://raw.githubusercontent.com/matbahasa/Melayu_Standard_Lisan/master/KL201715.txt",
|
67 |
+
"kl201716": "https://raw.githubusercontent.com/matbahasa/Melayu_Standard_Lisan/master/KL201716.txt",
|
68 |
+
"kl201717": "https://raw.githubusercontent.com/matbahasa/Melayu_Standard_Lisan/master/KL201717.txt",
|
69 |
+
"kl201718": "https://raw.githubusercontent.com/matbahasa/Melayu_Standard_Lisan/master/KL201718.txt",
|
70 |
+
"kl201719": "https://raw.githubusercontent.com/matbahasa/Melayu_Standard_Lisan/master/KL201719.txt",
|
71 |
+
"kl201720": "https://raw.githubusercontent.com/matbahasa/Melayu_Standard_Lisan/master/KL201720.txt",
|
72 |
+
"kl201721": "https://raw.githubusercontent.com/matbahasa/Melayu_Standard_Lisan/master/KL201721.txt",
|
73 |
+
"kl201722": "https://raw.githubusercontent.com/matbahasa/Melayu_Standard_Lisan/master/KL201722.txt",
|
74 |
+
"kl201723": "https://raw.githubusercontent.com/matbahasa/Melayu_Standard_Lisan/master/KL201723.txt",
|
75 |
+
"kl201724": "https://raw.githubusercontent.com/matbahasa/Melayu_Standard_Lisan/master/KL201724.txt",
|
76 |
+
"kl201725": "https://raw.githubusercontent.com/matbahasa/Melayu_Standard_Lisan/master/KL201725.txt",
|
77 |
+
"kl201726": "https://raw.githubusercontent.com/matbahasa/Melayu_Standard_Lisan/master/KL201726.txt",
|
78 |
+
"kl201727": "https://raw.githubusercontent.com/matbahasa/Melayu_Standard_Lisan/master/KL201727.txt",
|
79 |
+
"kl201728": "https://raw.githubusercontent.com/matbahasa/Melayu_Standard_Lisan/master/KL201728.txt",
|
80 |
+
"kl201729": "https://raw.githubusercontent.com/matbahasa/Melayu_Standard_Lisan/master/KL201729.txt",
|
81 |
+
"kl201730": "https://raw.githubusercontent.com/matbahasa/Melayu_Standard_Lisan/master/KL201730.txt",
|
82 |
+
"kl201731": "https://raw.githubusercontent.com/matbahasa/Melayu_Standard_Lisan/master/KL201731.txt",
|
83 |
+
"kl201732": "https://raw.githubusercontent.com/matbahasa/Melayu_Standard_Lisan/master/KL201732.txt",
|
84 |
+
"kl201733": "https://raw.githubusercontent.com/matbahasa/Melayu_Standard_Lisan/master/KL201733.txt",
|
85 |
+
}
|
86 |
+
|
87 |
+
_SUPPORTED_TASKS = [Tasks.SELF_SUPERVISED_PRETRAINING]
|
88 |
+
|
89 |
+
_SOURCE_VERSION = "1.0.0"
|
90 |
+
|
91 |
+
_SEACROWD_VERSION = "2024.06.20"
|
92 |
+
|
93 |
+
|
94 |
+
class MelayuStandardLisan(datasets.GeneratorBasedBuilder):
|
95 |
+
"""Korpus Variasi Bahasa Melayu:
|
96 |
+
Standard Lisan is a language corpus sourced from monologues of various melayu folklores."""
|
97 |
+
|
98 |
+
SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
|
99 |
+
SEACROWD_VERSION = datasets.Version(_SEACROWD_VERSION)
|
100 |
+
|
101 |
+
SEACROWD_SCHEMA_NAME = TASK_TO_SCHEMA[_SUPPORTED_TASKS[0]].lower()
|
102 |
+
|
103 |
+
BUILDER_CONFIGS = [
|
104 |
+
SEACrowdConfig(
|
105 |
+
name=f"{_DATASETNAME}_source",
|
106 |
+
version=SOURCE_VERSION,
|
107 |
+
description=f"{_DATASETNAME} source schema",
|
108 |
+
schema="source",
|
109 |
+
subset_id=f"{_DATASETNAME}",
|
110 |
+
),
|
111 |
+
SEACrowdConfig(
|
112 |
+
name=f"{_DATASETNAME}_seacrowd_{SEACROWD_SCHEMA_NAME}",
|
113 |
+
version=SEACROWD_VERSION,
|
114 |
+
description=f"{_DATASETNAME} SEACrowd schema",
|
115 |
+
schema=f"seacrowd_{SEACROWD_SCHEMA_NAME}",
|
116 |
+
subset_id=f"{_DATASETNAME}",
|
117 |
+
),
|
118 |
+
]
|
119 |
+
|
120 |
+
DEFAULT_CONFIG_NAME = f"{_DATASETNAME}_source"
|
121 |
+
|
122 |
+
def _info(self) -> datasets.DatasetInfo:
|
123 |
+
if self.config.schema == "source":
|
124 |
+
features = datasets.Features(
|
125 |
+
{
|
126 |
+
"id": datasets.Value("string"),
|
127 |
+
"text": datasets.Value("string"),
|
128 |
+
}
|
129 |
+
)
|
130 |
+
elif self.config.schema == f"seacrowd_{self.SEACROWD_SCHEMA_NAME}":
|
131 |
+
features = schemas.self_supervised_pretraining.features
|
132 |
+
|
133 |
+
return datasets.DatasetInfo(
|
134 |
+
description=_DESCRIPTION,
|
135 |
+
features=features,
|
136 |
+
homepage=_HOMEPAGE,
|
137 |
+
license=_LICENSE
|
138 |
+
)
|
139 |
+
|
140 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
141 |
+
"""Returns SplitGenerators."""
|
142 |
+
|
143 |
+
urls = [_URLS[key] for key in _URLS.keys()]
|
144 |
+
data_path = dl_manager.download_and_extract(urls)
|
145 |
+
|
146 |
+
return [
|
147 |
+
datasets.SplitGenerator(
|
148 |
+
name=datasets.Split.TRAIN,
|
149 |
+
gen_kwargs={"filepath": data_path[0], "split": "train", "other_path": data_path[1:]},
|
150 |
+
)
|
151 |
+
]
|
152 |
+
|
153 |
+
def _generate_examples(self, filepath: Path, split: str, other_path: List) -> Tuple[int, Dict]:
|
154 |
+
"""Yields examples as (key, example) tuples."""
|
155 |
+
filepaths = [filepath] + other_path
|
156 |
+
data = []
|
157 |
+
for filepath in filepaths:
|
158 |
+
with open(filepath, "r") as f:
|
159 |
+
data.append(" ".join([line.rstrip() for line in f.readlines()]))
|
160 |
+
|
161 |
+
for id, text in enumerate(data):
|
162 |
+
yield id, {"id": id, "text": text}
|