holylovenia commited on
Commit
754238a
1 Parent(s): d49f723

Upload medisco.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. medisco.py +136 -0
medisco.py ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
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 Tasks
10
+
11
+ _DATASETNAME = "medisco"
12
+
13
+ _LANGUAGES = ["ind"] # We follow ISO639-3 language code (https://iso639-3.sil.org/code_tables/639/data)
14
+ _LOCAL = False
15
+ _CITATION = """\
16
+ @INPROCEEDINGS{8629259,
17
+ author={Qorib, Muhammad Reza and Adriani, Mirna},
18
+ booktitle={2018 International Conference on Asian Language Processing (IALP)},
19
+ title={Building MEDISCO: Indonesian Speech Corpus for Medical Domain},
20
+ year={2018},
21
+ volume={},
22
+ number={},
23
+ pages={133-138},
24
+ keywords={Training;Automatic speech recognition;Medical services;Writing;Buildings;Computer science;Indonesian Automatic Speech Recognition;Medical Speech Corpus;Text Corpus},
25
+ doi={10.1109/IALP.2018.8629259}
26
+ }
27
+ """
28
+
29
+ _DESCRIPTION = "MEDISCO is a medical Indonesian speech corpus that contains 731 medical terms and consists of 4,680 utterances with total duration 10 hours"
30
+
31
+ _HOMEPAGE = "https://mrqorib.github.io/2018/02/01/building-medisco.html"
32
+
33
+ _LICENSE = "GNU General Public License v3.0 (gpl-3.0)"
34
+
35
+ _URLs = {
36
+ "medisco": {
37
+ "train": {
38
+ "audio": "https://huggingface.co/datasets/mrqorib/MEDISCO/resolve/main/MEDISCO/train/audio.tar.gz",
39
+ "text": "https://huggingface.co/datasets/mrqorib/MEDISCO/resolve/main/MEDISCO/train/annotation/sentences.txt",
40
+ },
41
+ "test": {"audio": "https://huggingface.co/datasets/mrqorib/MEDISCO/resolve/main/MEDISCO/test/audio.tar.gz", "text": "https://huggingface.co/datasets/mrqorib/MEDISCO/resolve/main/MEDISCO/test/annotation/sentences.txt"},
42
+ }
43
+ }
44
+
45
+ _SUPPORTED_TASKS = [Tasks.SPEECH_RECOGNITION]
46
+
47
+ _SOURCE_VERSION = "1.0.0"
48
+ _SEACROWD_VERSION = "2024.06.20"
49
+
50
+
51
+ class Medisco(datasets.GeneratorBasedBuilder):
52
+ "MEDISCO is a medical Indonesian speech corpus that contains 731 medical terms and consists of 4,680 utterances with total duration 10 hours"
53
+
54
+ BUILDER_CONFIGS = [
55
+ SEACrowdConfig(
56
+ name="medisco_source",
57
+ version=datasets.Version(_SOURCE_VERSION),
58
+ description="MEDISCO source schema",
59
+ schema="source",
60
+ subset_id="medisco",
61
+ ),
62
+ SEACrowdConfig(
63
+ name="medisco_seacrowd_sptext",
64
+ version=datasets.Version(_SEACROWD_VERSION),
65
+ description="MEDISCO seacrowd schema",
66
+ schema="seacrowd_sptext",
67
+ subset_id="medisco",
68
+ ),
69
+ ]
70
+
71
+ DEFAULT_CONFIG_NAME = "medisco_source"
72
+
73
+ def _info(self):
74
+ if self.config.schema == "source":
75
+ features = datasets.Features(
76
+ {
77
+ "id": datasets.Value("string"),
78
+ "speaker_id": datasets.Value("string"),
79
+ "path": datasets.Value("string"),
80
+ "audio": datasets.Audio(sampling_rate=44_100),
81
+ "text": datasets.Value("string"),
82
+ }
83
+ )
84
+ elif self.config.schema == "seacrowd_sptext":
85
+ features = schemas.speech_text_features
86
+
87
+ return datasets.DatasetInfo(
88
+ description=_DESCRIPTION,
89
+ features=features,
90
+ homepage=_HOMEPAGE,
91
+ license=_LICENSE,
92
+ citation=_CITATION,
93
+ task_templates=[datasets.AutomaticSpeechRecognition(audio_column="audio", transcription_column="text")],
94
+ )
95
+
96
+ def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
97
+ base_path = _URLs["medisco"]
98
+
99
+ return [
100
+ datasets.SplitGenerator(
101
+ name=datasets.Split.TRAIN,
102
+ gen_kwargs={"filepath": dl_manager.download_and_extract(base_path["train"]["audio"]), "text_path": dl_manager.download_and_extract(base_path["train"]["text"]), "split": "train"},
103
+ ),
104
+ datasets.SplitGenerator(
105
+ name=datasets.Split.TEST,
106
+ gen_kwargs={"filepath": dl_manager.download_and_extract(base_path["test"]["audio"]), "text_path": dl_manager.download_and_extract(base_path["test"]["text"]), "split": "test"},
107
+ ),
108
+ ]
109
+
110
+ def _generate_examples(self, filepath: Path, text_path: Path, split: str) -> Tuple[int, Dict]:
111
+
112
+ with open(text_path, encoding="utf-8") as f:
113
+ texts = f.readlines() # contains trailing \n
114
+
115
+ for speaker_id in os.listdir(filepath):
116
+ speaker_path = os.path.join(filepath, speaker_id)
117
+ if not os.path.isdir(speaker_path):
118
+ continue
119
+ for audio_id in os.listdir(speaker_path):
120
+ audio_idx = int(audio_id.split(".", 1)[0]) - 1 # get 0-based index
121
+ audio_path = os.path.join(speaker_path, audio_id)
122
+ key = "{}_{}_{}".format(split, speaker_id, audio_idx)
123
+ example = {
124
+ "id": key,
125
+ "speaker_id": speaker_id,
126
+ "path": audio_path,
127
+ "audio": audio_path,
128
+ "text": texts[audio_idx].strip(),
129
+ }
130
+ if self.config.schema == "seacrowd_sptext":
131
+ gender = speaker_id.split("-", 1)[0]
132
+ example["metadata"] = {
133
+ "speaker_gender": gender,
134
+ "speaker_age": None,
135
+ }
136
+ yield key, example