Datasets:
Tasks:
Automatic Speech Recognition
Formats:
parquet
Size:
10K - 100K
Tags:
speech-recognition
License:
Commit
•
20892cd
1
Parent(s):
7beff1e
Delete loading script
Browse files- pangloss.py +0 -202
pangloss.py
DELETED
@@ -1,202 +0,0 @@
|
|
1 |
-
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
|
2 |
-
#
|
3 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
-
# you may not use this file except in compliance with the License.
|
5 |
-
# You may obtain a copy of the License at
|
6 |
-
#
|
7 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8 |
-
#
|
9 |
-
# Unless required by applicable law or agreed to in writing, software
|
10 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
-
# See the License for the specific language governing permissions and
|
13 |
-
# limitations under the License.
|
14 |
-
"""Pangloss datasets for Yongning Na (yong1288) and Japhug (japh1234)"""
|
15 |
-
|
16 |
-
import csv
|
17 |
-
import json
|
18 |
-
import os
|
19 |
-
import datasets
|
20 |
-
from datasets.tasks import AutomaticSpeechRecognition
|
21 |
-
|
22 |
-
_CITATION = {
|
23 |
-
"yong1288": """
|
24 |
-
@misc{michaud_alexis_2021_5336698,
|
25 |
-
author = {Michaud, Alexis and
|
26 |
-
Galliot, Benjamin and
|
27 |
-
Guillaume, Séverine},
|
28 |
-
title = {{Yongning Na for Natural Language Processing: a
|
29 |
-
single-speaker audio corpus with transcriptions}},
|
30 |
-
month = aug,
|
31 |
-
year = 2021,
|
32 |
-
publisher = {Zenodo},
|
33 |
-
version = {1.0},
|
34 |
-
doi = {10.5281/zenodo.5336698},
|
35 |
-
url = {https://doi.org/10.5281/zenodo.5336698}
|
36 |
-
}
|
37 |
-
""",
|
38 |
-
"japh1234": """\
|
39 |
-
@misc{jacques_guillaume_2021_5521112,
|
40 |
-
author = {Jacques, Guillaume and
|
41 |
-
Galliot, Benjamin and
|
42 |
-
Guillaume, Séverine},
|
43 |
-
title = {{Japhug for Natural Language Processing: a single-
|
44 |
-
speaker audio corpus with transcriptions}},
|
45 |
-
month = sep,
|
46 |
-
year = 2021,
|
47 |
-
publisher = {Zenodo},
|
48 |
-
version = {1.0},
|
49 |
-
doi = {10.5281/zenodo.5521112},
|
50 |
-
url = {https://doi.org/10.5281/zenodo.5521112}
|
51 |
-
}
|
52 |
-
"""
|
53 |
-
}
|
54 |
-
|
55 |
-
_DESCRIPTION = """\
|
56 |
-
These datasets are extracts from the Pangloss collection and have
|
57 |
-
been preprocessed for ASR experiments in Na and Japhug.
|
58 |
-
"""
|
59 |
-
|
60 |
-
_HOMEPAGE = "https://pangloss.cnrs.fr/"
|
61 |
-
|
62 |
-
_LICENSE = "https://creativecommons.org/licenses/by-nc-sa/4.0/fr/legalcode"
|
63 |
-
|
64 |
-
# The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
|
65 |
-
# This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
|
66 |
-
|
67 |
-
_VERSION = datasets.Version("1.0.0")
|
68 |
-
|
69 |
-
_LANGUAGES = {
|
70 |
-
"yong1288": {
|
71 |
-
"url": "https://mycore.core-cloud.net/index.php/s/vaGMeRf4Iij8MWR/download",
|
72 |
-
"homepage": "https://zenodo.org/record/5336698",
|
73 |
-
"description": "Yongning Na dataset",
|
74 |
-
"translations": ["fr", "en", "zh"]
|
75 |
-
},
|
76 |
-
"japh1234": {
|
77 |
-
"url": "https://mycore.core-cloud.net/index.php/s/kuQCxmyVcUFWroV/download",
|
78 |
-
"homepage": "https://zenodo.org/record/5521112",
|
79 |
-
"description": "Japhug dataset",
|
80 |
-
"translations": ["fr", "zh"]
|
81 |
-
}
|
82 |
-
}
|
83 |
-
|
84 |
-
# TODO: Name of the dataset usually match the script name with CamelCase instead of snake_case
|
85 |
-
class PanglossDataset(datasets.GeneratorBasedBuilder):
|
86 |
-
"""The Pangloss datasets are extracts from Pangloss Collections that can be used for ASR experiments in these languages."""
|
87 |
-
field_translations = {
|
88 |
-
"chemin_audio": "path",
|
89 |
-
"nature": "doctype",
|
90 |
-
"forme": "sentence",
|
91 |
-
"locuteur": "speaker",
|
92 |
-
"traduction:fr": "translation:fr",
|
93 |
-
"traduction:en": "translation:en",
|
94 |
-
"traduction:zh": "translation:zh"
|
95 |
-
}
|
96 |
-
|
97 |
-
# This is an example of a dataset with multiple configurations.
|
98 |
-
# If you don't want/need to define several sub-sets in your dataset,
|
99 |
-
# just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
|
100 |
-
|
101 |
-
# If you need to make complex sub-parts in the datasets with configurable options
|
102 |
-
# You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
|
103 |
-
# BUILDER_CONFIG_CLASS = MyBuilderConfig
|
104 |
-
|
105 |
-
# You will be able to load one or the other configurations in the following list with
|
106 |
-
# data = datasets.load_dataset('my_dataset', 'first_domain')
|
107 |
-
# data = datasets.load_dataset('my_dataset', 'second_domain')
|
108 |
-
BUILDER_CONFIGS = [
|
109 |
-
datasets.BuilderConfig(name=language_name, version=_VERSION, description=language_data["description"])
|
110 |
-
for language_name, language_data in _LANGUAGES.items()
|
111 |
-
]
|
112 |
-
|
113 |
-
#DEFAULT_CONFIG_NAME = "na" # It's not mandatory to have a default configuration. Just use one if it make sense.
|
114 |
-
|
115 |
-
def _info(self):
|
116 |
-
# TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
|
117 |
-
features = datasets.Features(
|
118 |
-
{
|
119 |
-
"path": datasets.Value("string"),
|
120 |
-
"audio": datasets.features.Audio(sampling_rate=16_000),
|
121 |
-
"sentence": datasets.Value("string"),
|
122 |
-
"doctype": datasets.Value("string"),
|
123 |
-
"speaker": datasets.Value("string"),
|
124 |
-
**{f"translation:{language_code}": datasets.Value("string") for language_code in _LANGUAGES[self.config.name]["translations"]}
|
125 |
-
}
|
126 |
-
)
|
127 |
-
|
128 |
-
return datasets.DatasetInfo(
|
129 |
-
# This is the description that will appear on the datasets page.
|
130 |
-
description=_DESCRIPTION,
|
131 |
-
# This defines the different columns of the dataset and their types
|
132 |
-
features=features, # Here we define them above because they are different between the two configurations
|
133 |
-
# If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
|
134 |
-
# specify them. They'll be used if as_supervised=True in builder.as_dataset.
|
135 |
-
# supervised_keys=("sentence", "label"),
|
136 |
-
# Homepage of the dataset for documentation
|
137 |
-
homepage=_HOMEPAGE,
|
138 |
-
# License for the dataset if available
|
139 |
-
license=_LICENSE,
|
140 |
-
# Citation for the dataset
|
141 |
-
citation=_CITATION,
|
142 |
-
task_templates=[AutomaticSpeechRecognition(audio_column="audio", transcription_column="forme")],
|
143 |
-
|
144 |
-
)
|
145 |
-
|
146 |
-
def _split_generators(self, dl_manager):
|
147 |
-
# TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
|
148 |
-
# If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
|
149 |
-
|
150 |
-
# dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
|
151 |
-
# It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
|
152 |
-
# By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
|
153 |
-
urls = _LANGUAGES[self.config.name]["url"]
|
154 |
-
data_dir = dl_manager.download_and_extract(urls)
|
155 |
-
return [
|
156 |
-
datasets.SplitGenerator(
|
157 |
-
name=datasets.Split.TRAIN,
|
158 |
-
# These kwargs will be passed to _generate_examples
|
159 |
-
gen_kwargs={
|
160 |
-
"filepath": os.path.join(data_dir, self.config.name, "train.csv"),
|
161 |
-
"split": "train"
|
162 |
-
},
|
163 |
-
),
|
164 |
-
datasets.SplitGenerator(
|
165 |
-
name=datasets.Split.TEST,
|
166 |
-
# These kwargs will be passed to _generate_examples
|
167 |
-
gen_kwargs={
|
168 |
-
"filepath": os.path.join(data_dir, self.config.name, "test.csv"),
|
169 |
-
"split": "test"
|
170 |
-
},
|
171 |
-
),
|
172 |
-
datasets.SplitGenerator(
|
173 |
-
name=datasets.Split.VALIDATION,
|
174 |
-
# These kwargs will be passed to _generate_examples
|
175 |
-
gen_kwargs={
|
176 |
-
"filepath": os.path.join(data_dir, self.config.name, "validation.csv"),
|
177 |
-
"split": "validation"
|
178 |
-
},
|
179 |
-
),
|
180 |
-
]
|
181 |
-
|
182 |
-
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
183 |
-
def _generate_examples(self, filepath, split):
|
184 |
-
# TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
|
185 |
-
# The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
|
186 |
-
with open(filepath, encoding="utf-8") as file_descriptor:
|
187 |
-
reader = csv.DictReader(file_descriptor)
|
188 |
-
for key, row in enumerate(reader):
|
189 |
-
translated_fieldnames = [self.field_translations[fieldname] for fieldname in reader.fieldnames if fieldname in self.field_translations.keys()]
|
190 |
-
data = dict(zip(translated_fieldnames, row.values()))
|
191 |
-
data["audio"] = os.path.join(os.path.dirname(filepath), data["path"])
|
192 |
-
# Yields examples as (key, example) tuples
|
193 |
-
yield key, data
|
194 |
-
|
195 |
-
|
196 |
-
if __name__ == "__main__":
|
197 |
-
# for language in _LANGUAGES.keys():
|
198 |
-
datasets.load_dataset("datasets/pangloss/pangloss.py", "japh1234")
|
199 |
-
|
200 |
-
# datasets-cli test datasets/pangloss --save_infos --all_configs
|
201 |
-
# datasets-cli dummy_data datasets/pangloss --auto_generate
|
202 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|