Upload lex_indo.py with huggingface_hub
Browse files- lex_indo.py +126 -0
lex_indo.py
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pathlib import Path
|
| 2 |
+
from typing import List
|
| 3 |
+
|
| 4 |
+
import datasets
|
| 5 |
+
|
| 6 |
+
from seacrowd.utils import schemas
|
| 7 |
+
from seacrowd.utils.configs import SEACrowdConfig
|
| 8 |
+
from seacrowd.utils.constants import Licenses, Tasks
|
| 9 |
+
|
| 10 |
+
_CITATION = """\
|
| 11 |
+
@misc{magichubLEXIndoIndonesian,
|
| 12 |
+
author = {},
|
| 13 |
+
title = {LEX-INDO: AN INDONESIAN LEXICON},
|
| 14 |
+
year = {},
|
| 15 |
+
howpublished = {Online},
|
| 16 |
+
url = {https://magichub.com/datasets/indonesian-lexicon/},
|
| 17 |
+
note = {Accessed 19-03-2024},
|
| 18 |
+
}
|
| 19 |
+
"""
|
| 20 |
+
|
| 21 |
+
_DATASETNAME = "lex_indo"
|
| 22 |
+
|
| 23 |
+
_DESCRIPTION = """This open-source lexicon consists of 2,000 common Indonesian words, with phoneme series attached.
|
| 24 |
+
It is intended to be used as the lexicon for an automatic speech recognition system or a text-to-speech system.
|
| 25 |
+
The dictionary presents words as well as their pronunciation transcribed with an ARPABET(phone set of CMU)-like phone set. Syllables are separated with dots.
|
| 26 |
+
"""
|
| 27 |
+
|
| 28 |
+
_HOMEPAGE = "https://magichub.com/datasets/indonesian-lexicon/"
|
| 29 |
+
_LICENSE = Licenses.CC_BY_NC_ND_4_0.value
|
| 30 |
+
_LOCAL = True
|
| 31 |
+
|
| 32 |
+
_URLS = {}
|
| 33 |
+
|
| 34 |
+
_SUPPORTED_TASKS = [Tasks.MULTILEXNORM]
|
| 35 |
+
|
| 36 |
+
_LANGUAGES = ["ind"]
|
| 37 |
+
|
| 38 |
+
_SOURCE_VERSION = "1.0.0"
|
| 39 |
+
_SEACROWD_VERSION = "2024.06.20"
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
class LexIndo(datasets.GeneratorBasedBuilder):
|
| 43 |
+
"""This open-source lexicon consists of 2,000 common Indonesian words, with phoneme series attached"""
|
| 44 |
+
|
| 45 |
+
SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
|
| 46 |
+
SEACROWD_VERSION = datasets.Version(_SEACROWD_VERSION)
|
| 47 |
+
SEACROWD_SCHEMA_NAME = "t2t"
|
| 48 |
+
|
| 49 |
+
BUILDER_CONFIGS = [
|
| 50 |
+
SEACrowdConfig(
|
| 51 |
+
name=f"{_DATASETNAME}_source",
|
| 52 |
+
version=SOURCE_VERSION,
|
| 53 |
+
description=f"{_DATASETNAME} lexicon with source schema",
|
| 54 |
+
schema="source",
|
| 55 |
+
subset_id=_DATASETNAME,
|
| 56 |
+
)
|
| 57 |
+
] + [
|
| 58 |
+
SEACrowdConfig(
|
| 59 |
+
name=f"{_DATASETNAME}_seacrowd_{SEACROWD_SCHEMA_NAME}",
|
| 60 |
+
version=SEACROWD_VERSION,
|
| 61 |
+
description=f"{_DATASETNAME} lexicon with SEACrowd schema",
|
| 62 |
+
schema=f"seacrowd_{SEACROWD_SCHEMA_NAME}",
|
| 63 |
+
subset_id=_DATASETNAME,
|
| 64 |
+
)
|
| 65 |
+
]
|
| 66 |
+
|
| 67 |
+
DEFAULT_CONFIG_NAME = f"{_DATASETNAME}_source"
|
| 68 |
+
|
| 69 |
+
def _info(self) -> datasets.DatasetInfo:
|
| 70 |
+
schema = self.config.schema
|
| 71 |
+
if schema == "source":
|
| 72 |
+
features = datasets.Features({"id": datasets.Value("string"), "word": datasets.Value("string"), "phoneme": datasets.Value("string")})
|
| 73 |
+
else:
|
| 74 |
+
features = schemas.text2text_features
|
| 75 |
+
|
| 76 |
+
return datasets.DatasetInfo(
|
| 77 |
+
description=_DESCRIPTION,
|
| 78 |
+
features=features,
|
| 79 |
+
homepage=_HOMEPAGE,
|
| 80 |
+
license=_LICENSE,
|
| 81 |
+
citation=_CITATION,
|
| 82 |
+
)
|
| 83 |
+
|
| 84 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
| 85 |
+
"""Returns SplitGenerators."""
|
| 86 |
+
if self.config.data_dir is None:
|
| 87 |
+
raise ValueError("This is a local dataset. Please pass the data_dir kwarg to load_dataset.")
|
| 88 |
+
else:
|
| 89 |
+
data_dir = self.config.data_dir
|
| 90 |
+
|
| 91 |
+
return [
|
| 92 |
+
datasets.SplitGenerator(
|
| 93 |
+
name=datasets.Split.TRAIN,
|
| 94 |
+
gen_kwargs={
|
| 95 |
+
"filepath": data_dir,
|
| 96 |
+
},
|
| 97 |
+
)
|
| 98 |
+
]
|
| 99 |
+
|
| 100 |
+
def _generate_examples(self, filepath: Path):
|
| 101 |
+
"""Yields examples as (key, example) tuples."""
|
| 102 |
+
|
| 103 |
+
try:
|
| 104 |
+
with open(f"{filepath}/Indonesian_dic.txt", "r") as f:
|
| 105 |
+
data = f.readlines()
|
| 106 |
+
except FileNotFoundError:
|
| 107 |
+
print("File not found. Please check the file path. Make sure Indonesian_dic.txt is in dest directory")
|
| 108 |
+
except IOError:
|
| 109 |
+
print("An error occurred while trying to read the file.")
|
| 110 |
+
|
| 111 |
+
for idx, text in enumerate(data):
|
| 112 |
+
word_i = text.split()[0]
|
| 113 |
+
phoneme_i = " ".join(text.split()[1:])
|
| 114 |
+
if self.config.schema == "source":
|
| 115 |
+
example = {"id": str(idx), "word": word_i, "phoneme": phoneme_i}
|
| 116 |
+
elif self.config.schema == f"seacrowd_{self.SEACROWD_SCHEMA_NAME}":
|
| 117 |
+
example = {
|
| 118 |
+
"id": str(idx),
|
| 119 |
+
"text_1": word_i,
|
| 120 |
+
"text_2": phoneme_i,
|
| 121 |
+
"text_1_name": _LANGUAGES[-1],
|
| 122 |
+
"text_2_name": "phoneme",
|
| 123 |
+
}
|
| 124 |
+
else:
|
| 125 |
+
raise ValueError(f"Invalid config: {self.config.name}")
|
| 126 |
+
yield idx, example
|