holylovenia
commited on
Commit
·
05b1129
1
Parent(s):
cad3ee5
Upload titml_idn.py with huggingface_hub
Browse files- titml_idn.py +138 -0
titml_idn.py
ADDED
@@ -0,0 +1,138 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pathlib import Path
|
2 |
+
from typing import List
|
3 |
+
|
4 |
+
import datasets
|
5 |
+
import json
|
6 |
+
import os
|
7 |
+
|
8 |
+
from nusacrowd.utils import schemas
|
9 |
+
from nusacrowd.utils.configs import NusantaraConfig
|
10 |
+
from nusacrowd.utils.constants import Tasks, DEFAULT_SOURCE_VIEW_NAME, DEFAULT_NUSANTARA_VIEW_NAME
|
11 |
+
|
12 |
+
_DATASETNAME = "titml_idn"
|
13 |
+
_SOURCE_VIEW_NAME = DEFAULT_SOURCE_VIEW_NAME
|
14 |
+
_UNIFIED_VIEW_NAME = DEFAULT_NUSANTARA_VIEW_NAME
|
15 |
+
|
16 |
+
_LANGUAGES = ["ind"] # We follow ISO639-3 language code (https://iso639-3.sil.org/code_tables/639/data)
|
17 |
+
_LOCAL = False
|
18 |
+
_CITATION = """\
|
19 |
+
@inproceedings{lestari2006titmlidn,
|
20 |
+
title={A large vocabulary continuous speech recognition system for Indonesian language},
|
21 |
+
author={Lestari, Dessi Puji and Iwano, Koji and Furui, Sadaoki},
|
22 |
+
booktitle={15th Indonesian Scientific Conference in Japan Proceedings},
|
23 |
+
pages={17--22},
|
24 |
+
year={2006}
|
25 |
+
}
|
26 |
+
"""
|
27 |
+
|
28 |
+
_DESCRIPTION = """\
|
29 |
+
TITML-IDN (Tokyo Institute of Technology Multilingual - Indonesian) is collected to build a pioneering Indonesian Large Vocabulary Continuous Speech Recognition (LVCSR) System. In order to build an LVCSR system, high accurate acoustic models and large-scale language models are essential. Since Indonesian speech corpus was not available yet, we tried to collect speech data from 20 Indonesian native speakers (11 males and 9 females) to construct a speech corpus for training the acoustic model based on Hidden Markov Models (HMMs). A text corpus which was collected by ILPS, Informatics Institute, University of Amsterdam, was used to build a 40K-vocabulary dictionary and a n-gram language model.
|
30 |
+
"""
|
31 |
+
|
32 |
+
_HOMEPAGE = "http://research.nii.ac.jp/src/en/TITML-IDN.html"
|
33 |
+
|
34 |
+
_LICENSE = "For research purposes only. If you use this corpus, you have to cite (Lestari et al, 2006)."
|
35 |
+
|
36 |
+
_URLs = {"titml-idn": "https://huggingface.co/datasets/holylovenia/TITML-IDN/resolve/main/IndoLVCSR.zip"}
|
37 |
+
|
38 |
+
_SUPPORTED_TASKS = [Tasks.SPEECH_RECOGNITION]
|
39 |
+
|
40 |
+
_SOURCE_VERSION = "1.0.0"
|
41 |
+
_NUSANTARA_VERSION = "1.0.0"
|
42 |
+
|
43 |
+
|
44 |
+
class TitmlIdn(datasets.GeneratorBasedBuilder):
|
45 |
+
"""TITML-IDN is a speech recognition dataset containing Indonesian speech collected with transcriptions from newpaper and magazine articles."""
|
46 |
+
|
47 |
+
BUILDER_CONFIGS = [
|
48 |
+
NusantaraConfig(
|
49 |
+
name="titml_idn_source",
|
50 |
+
version=datasets.Version(_SOURCE_VERSION),
|
51 |
+
description="TITML-IDN source schema",
|
52 |
+
schema="source",
|
53 |
+
subset_id="titml_idn",
|
54 |
+
),
|
55 |
+
NusantaraConfig(
|
56 |
+
name="titml_idn_nusantara_sptext",
|
57 |
+
version=datasets.Version(_NUSANTARA_VERSION),
|
58 |
+
description="TITML-IDN Nusantara schema",
|
59 |
+
schema="nusantara_sptext",
|
60 |
+
subset_id="titml_idn",
|
61 |
+
),
|
62 |
+
]
|
63 |
+
|
64 |
+
DEFAULT_CONFIG_NAME = "titml_idn_source"
|
65 |
+
|
66 |
+
def _info(self):
|
67 |
+
if self.config.schema == "source":
|
68 |
+
features = datasets.Features(
|
69 |
+
{
|
70 |
+
"id": datasets.Value("string"),
|
71 |
+
"speaker_id": datasets.Value("string"),
|
72 |
+
"path": datasets.Value("string"),
|
73 |
+
"audio": datasets.Audio(sampling_rate=16_000),
|
74 |
+
"text": datasets.Value("string"),
|
75 |
+
}
|
76 |
+
)
|
77 |
+
elif self.config.schema == "nusantara_sptext":
|
78 |
+
features = schemas.speech_text_features
|
79 |
+
|
80 |
+
return datasets.DatasetInfo(
|
81 |
+
description=_DESCRIPTION,
|
82 |
+
features=features,
|
83 |
+
homepage=_HOMEPAGE,
|
84 |
+
license=_LICENSE,
|
85 |
+
citation=_CITATION,
|
86 |
+
task_templates=[datasets.AutomaticSpeechRecognition(audio_column="audio", transcription_column="text")],
|
87 |
+
)
|
88 |
+
|
89 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
90 |
+
base_path = dl_manager.download_and_extract(_URLs["titml-idn"])
|
91 |
+
|
92 |
+
return [
|
93 |
+
datasets.SplitGenerator(
|
94 |
+
name=datasets.Split.TRAIN,
|
95 |
+
gen_kwargs={"filepath": base_path},
|
96 |
+
),
|
97 |
+
]
|
98 |
+
|
99 |
+
def _generate_examples(self, filepath: Path, n_speakers=20):
|
100 |
+
|
101 |
+
if self.config.schema == "source" or self.config.schema == "nusantara_sptext":
|
102 |
+
|
103 |
+
for speaker_id in range(1, n_speakers + 1):
|
104 |
+
speaker_id = str(speaker_id).zfill(2)
|
105 |
+
dir_path = os.path.join(filepath, speaker_id)
|
106 |
+
transcription_path = os.path.join(dir_path, "script~")
|
107 |
+
|
108 |
+
with open(transcription_path, "r+") as f:
|
109 |
+
for line in f:
|
110 |
+
audio_id = line[2:8]
|
111 |
+
text = line[9:].strip()
|
112 |
+
wav_path = os.path.join(dir_path, "{}.wav".format(audio_id))
|
113 |
+
|
114 |
+
if os.path.exists(wav_path):
|
115 |
+
if self.config.schema == "source":
|
116 |
+
ex = {
|
117 |
+
"id": audio_id,
|
118 |
+
"speaker_id": speaker_id,
|
119 |
+
"path": wav_path,
|
120 |
+
"audio": wav_path,
|
121 |
+
"text": text,
|
122 |
+
}
|
123 |
+
yield audio_id, ex
|
124 |
+
elif self.config.schema == "nusantara_sptext":
|
125 |
+
ex = {
|
126 |
+
"id": audio_id,
|
127 |
+
"speaker_id": speaker_id,
|
128 |
+
"path": wav_path,
|
129 |
+
"audio": wav_path,
|
130 |
+
"text": text,
|
131 |
+
"metadata": {
|
132 |
+
"speaker_age": None,
|
133 |
+
"speaker_gender": None,
|
134 |
+
}
|
135 |
+
}
|
136 |
+
yield audio_id, ex
|
137 |
+
else:
|
138 |
+
raise ValueError(f"Invalid config: {self.config.name}")
|