First version of common_voice_11_0_eues dataset
Browse files- common_voice_11_0_eues.py +108 -0
common_voice_11_0_eues.py
ADDED
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2023 Mikel Penagarikano
|
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 |
+
|
16 |
+
# Lint as: python3
|
17 |
+
"""Albayzin automatic speech recognition dataset.
|
18 |
+
"""
|
19 |
+
|
20 |
+
import os
|
21 |
+
from pathlib import Path
|
22 |
+
|
23 |
+
import datasets
|
24 |
+
from datasets.tasks import AutomaticSpeechRecognition
|
25 |
+
from datasets.utils import logging
|
26 |
+
from random import shuffle
|
27 |
+
import re
|
28 |
+
|
29 |
+
_CITATION = """\
|
30 |
+
"""
|
31 |
+
|
32 |
+
_DESCRIPTION = """\
|
33 |
+
"""
|
34 |
+
|
35 |
+
_HOMEPAGE = ""
|
36 |
+
|
37 |
+
|
38 |
+
class CommonVoiceEUESConfig(datasets.BuilderConfig):
|
39 |
+
"""BuilderConfig for Common Voice Mixed."""
|
40 |
+
|
41 |
+
def __init__(self, **kwargs):
|
42 |
+
"""
|
43 |
+
Args:
|
44 |
+
data_dir: `string`, the path to the folder containing the files in the
|
45 |
+
downloaded .tar
|
46 |
+
citation: `string`, citation for the data set
|
47 |
+
url: `string`, url for information about the data set
|
48 |
+
**kwargs: keyword arguments forwarded to super.
|
49 |
+
"""
|
50 |
+
super(CommonVoiceEUESConfig, self).__init__(version=datasets.Version("11.0.0", ""), **kwargs)
|
51 |
+
|
52 |
+
|
53 |
+
class CommonVoiceEUES(datasets.GeneratorBasedBuilder):
|
54 |
+
"""Common Voice Mixed dataset."""
|
55 |
+
|
56 |
+
BUILDER_CONFIGS = [CommonVoiceEUESConfig(name="eues", description="eu+es joint configuration.")]
|
57 |
+
|
58 |
+
CV_EU_ARGS = ['mozilla-foundation/common_voice_11_0','eu']
|
59 |
+
print('Loading',*CV_EU_ARGS)
|
60 |
+
CV_EU_INFO = datasets.load_dataset_builder(*CV_EU_ARGS)
|
61 |
+
CV_EU = datasets.load_dataset(*CV_EU_ARGS)
|
62 |
+
CV_ES_ARGS = ['mozilla-foundation/common_voice_11_0','es']
|
63 |
+
print('Loading',*CV_ES_ARGS)
|
64 |
+
CV_ES_INFO = datasets.load_dataset_builder(*CV_ES_ARGS)
|
65 |
+
CV_ES = datasets.load_dataset(*CV_ES_ARGS)
|
66 |
+
assert CV_EU_INFO.info.features == CV_ES_INFO.info.features
|
67 |
+
|
68 |
+
def _info(self):
|
69 |
+
features = self.CV_EU_INFO.info.features.copy()
|
70 |
+
features['simplified_sentence'] = datasets.Value('string')
|
71 |
+
return datasets.DatasetInfo(
|
72 |
+
description=_DESCRIPTION,
|
73 |
+
features=features,
|
74 |
+
homepage=_HOMEPAGE,
|
75 |
+
citation=_CITATION,
|
76 |
+
)
|
77 |
+
|
78 |
+
def _split_generators(self, dl_manager):
|
79 |
+
split_generators = []
|
80 |
+
for name in self.CV_EU_INFO.info.splits.keys():
|
81 |
+
split_generators.append(
|
82 |
+
datasets.SplitGenerator(
|
83 |
+
name=name ,
|
84 |
+
gen_kwargs={"split":name}
|
85 |
+
)
|
86 |
+
)
|
87 |
+
|
88 |
+
return split_generators
|
89 |
+
|
90 |
+
_TRANTAB = str.maketrans('áéíóúÁÉÍÓÚüÜv', 'aeiouaeiouuub')
|
91 |
+
_ALPHABET_PATTERN = re.compile('[^abcdefghijklmnñopqrstuvwxyz ]+')
|
92 |
+
def _simplyfy(self,txt):
|
93 |
+
txt = txt.lower()
|
94 |
+
txt = txt.translate(self._TRANTAB)
|
95 |
+
txt = txt.replace('ch','X').replace('h','').replace('X','ch')
|
96 |
+
txt = self._ALPHABET_PATTERN.sub(' ',txt)
|
97 |
+
return ' '.join(txt.split())
|
98 |
+
|
99 |
+
def _generate_examples(self, split):
|
100 |
+
index = ([0] * len(self.CV_EU[split])) + ([1] * len(self.CV_ES[split]))
|
101 |
+
shuffle(index)
|
102 |
+
it = ( iter(self.CV_EU[split]) , iter(self.CV_ES[split]) )
|
103 |
+
print('\n************************ ELIMINAR [:2000] ***************')
|
104 |
+
for key,lang in enumerate(index[:2000]) :
|
105 |
+
feature = next(it[lang])
|
106 |
+
feature['simplified_sentence'] = self._simplyfy(feature['sentence'])
|
107 |
+
yield key,feature
|
108 |
+
|