carlosdanielhernandezmena
commited on
Commit
•
85a9c54
1
Parent(s):
a40b4d7
Delete loading script
Browse files
prueba.py
DELETED
@@ -1,147 +0,0 @@
|
|
1 |
-
from collections import defaultdict
|
2 |
-
import os
|
3 |
-
import json
|
4 |
-
import csv
|
5 |
-
|
6 |
-
import datasets
|
7 |
-
|
8 |
-
_NAME="prueba"
|
9 |
-
_VERSION="1.0.0"
|
10 |
-
|
11 |
-
_DESCRIPTION = """
|
12 |
-
An extremely small corpus of 40 audio files taken from Common Voice (es) with the objective of testing how to share datasets in Hugging Face.
|
13 |
-
"""
|
14 |
-
|
15 |
-
_CITATION = """
|
16 |
-
@misc{toy_corpus_asr_es,
|
17 |
-
title={Toy Corpus for ASR in Spanish.},
|
18 |
-
author={Hernandez Mena, Carlos Daniel},
|
19 |
-
year={2022},
|
20 |
-
url={https://huggingface.co/datasets/carlosdanielhernandezmena/toy_corpus_asr_es},
|
21 |
-
}
|
22 |
-
"""
|
23 |
-
|
24 |
-
_HOMEPAGE = "https://huggingface.co/datasets/carlosdanielhernandezmena/toy_corpus_asr_es"
|
25 |
-
|
26 |
-
_LICENSE = "CC-BY-4.0, See https://creativecommons.org/licenses/by/4.0/"
|
27 |
-
|
28 |
-
_BASE_DATA_DIR = "corpus/"
|
29 |
-
_METADATA_TRAIN = os.path.join(_BASE_DATA_DIR,"files","metadata_train.tsv")
|
30 |
-
_METADATA_TEST = os.path.join(_BASE_DATA_DIR,"files", "metadata_test.tsv")
|
31 |
-
_METADATA_DEV = os.path.join(_BASE_DATA_DIR,"files", "metadata_dev.tsv")
|
32 |
-
|
33 |
-
_TARS_TRAIN = os.path.join(_BASE_DATA_DIR,"files","tars_train.paths")
|
34 |
-
_TARS_TEST = os.path.join(_BASE_DATA_DIR,"files", "tars_test.paths")
|
35 |
-
_TARS_DEV = os.path.join(_BASE_DATA_DIR,"files", "tars_dev.paths")
|
36 |
-
|
37 |
-
class ToyCorpusAsrEsConfig(datasets.BuilderConfig):
|
38 |
-
"""BuilderConfig for Toy Corpus ASR ES."""
|
39 |
-
|
40 |
-
def __init__(self, name, **kwargs):
|
41 |
-
name=_NAME
|
42 |
-
super().__init__(name=name, **kwargs)
|
43 |
-
|
44 |
-
class ToyCorpusAsrEs(datasets.GeneratorBasedBuilder):
|
45 |
-
"""The Toy Corpus ASR ES dataset."""
|
46 |
-
|
47 |
-
VERSION = datasets.Version(_VERSION)
|
48 |
-
BUILDER_CONFIGS = [
|
49 |
-
ToyCorpusAsrEsConfig(
|
50 |
-
name=_NAME,
|
51 |
-
version=datasets.Version(_VERSION),
|
52 |
-
)
|
53 |
-
]
|
54 |
-
|
55 |
-
def _info(self):
|
56 |
-
features = datasets.Features(
|
57 |
-
{
|
58 |
-
"audio_id": datasets.Value("string"),
|
59 |
-
"audio": datasets.Audio(sampling_rate=16000),
|
60 |
-
"split": datasets.Value("string"),
|
61 |
-
"gender": datasets.Value("string"),
|
62 |
-
"normalized_text": datasets.Value("string"),
|
63 |
-
"relative_path": datasets.Value("string"),
|
64 |
-
}
|
65 |
-
)
|
66 |
-
return datasets.DatasetInfo(
|
67 |
-
description=_DESCRIPTION,
|
68 |
-
features=features,
|
69 |
-
homepage=_HOMEPAGE,
|
70 |
-
license=_LICENSE,
|
71 |
-
citation=_CITATION,
|
72 |
-
)
|
73 |
-
|
74 |
-
def _split_generators(self, dl_manager):
|
75 |
-
|
76 |
-
metadata_train=dl_manager.download_and_extract(_METADATA_TRAIN)
|
77 |
-
metadata_test=dl_manager.download_and_extract(_METADATA_TEST)
|
78 |
-
metadata_dev=dl_manager.download_and_extract(_METADATA_DEV)
|
79 |
-
|
80 |
-
tars_train=dl_manager.download_and_extract(_TARS_TRAIN)
|
81 |
-
tars_test=dl_manager.download_and_extract(_TARS_TEST)
|
82 |
-
tars_dev=dl_manager.download_and_extract(_TARS_DEV)
|
83 |
-
|
84 |
-
hash_tar_files=defaultdict(dict)
|
85 |
-
with open(tars_train,'r') as f:
|
86 |
-
hash_tar_files['train']=[path.replace('\n','') for path in f]
|
87 |
-
|
88 |
-
with open(tars_test,'r') as f:
|
89 |
-
hash_tar_files['test']=[path.replace('\n','') for path in f]
|
90 |
-
|
91 |
-
with open(tars_dev,'r') as f:
|
92 |
-
hash_tar_files['dev']=[path.replace('\n','') for path in f]
|
93 |
-
|
94 |
-
hash_meta_paths={"train":metadata_train,"test":metadata_test,"dev":metadata_dev}
|
95 |
-
audio_paths = dl_manager.download(hash_tar_files)
|
96 |
-
|
97 |
-
splits=["train","dev","test"]
|
98 |
-
local_extracted_audio_paths = (
|
99 |
-
dl_manager.extract(audio_paths) if not dl_manager.is_streaming else
|
100 |
-
{
|
101 |
-
split:[None] * len(audio_paths[split]) for split in splits
|
102 |
-
}
|
103 |
-
)
|
104 |
-
|
105 |
-
return [
|
106 |
-
datasets.SplitGenerator(
|
107 |
-
name=datasets.Split.TRAIN,
|
108 |
-
gen_kwargs={
|
109 |
-
"audio_archives":[dl_manager.iter_archive(archive) for archive in audio_paths["train"]],
|
110 |
-
"local_extracted_archives_paths": local_extracted_audio_paths["train"],
|
111 |
-
"metadata_paths": hash_meta_paths["train"],
|
112 |
-
}
|
113 |
-
),
|
114 |
-
datasets.SplitGenerator(
|
115 |
-
name=datasets.Split.VALIDATION,
|
116 |
-
gen_kwargs={
|
117 |
-
"audio_archives": [dl_manager.iter_archive(archive) for archive in audio_paths["dev"]],
|
118 |
-
"local_extracted_archives_paths": local_extracted_audio_paths["dev"],
|
119 |
-
"metadata_paths": hash_meta_paths["dev"],
|
120 |
-
}
|
121 |
-
),
|
122 |
-
datasets.SplitGenerator(
|
123 |
-
name=datasets.Split.TEST,
|
124 |
-
gen_kwargs={
|
125 |
-
"audio_archives": [dl_manager.iter_archive(archive) for archive in audio_paths["test"]],
|
126 |
-
"local_extracted_archives_paths": local_extracted_audio_paths["test"],
|
127 |
-
"metadata_paths": hash_meta_paths["test"],
|
128 |
-
}
|
129 |
-
),
|
130 |
-
]
|
131 |
-
|
132 |
-
def _generate_examples(self, audio_archives, local_extracted_archives_paths, metadata_paths):
|
133 |
-
|
134 |
-
features = ["normalized_text","gender","split","relative_path"]
|
135 |
-
|
136 |
-
with open(metadata_paths) as f:
|
137 |
-
metadata = {x["audio_id"]: x for x in csv.DictReader(f, delimiter="\t")}
|
138 |
-
|
139 |
-
for audio_archive, local_extracted_archive_path in zip(audio_archives, local_extracted_archives_paths):
|
140 |
-
for audio_filename, audio_file in audio_archive:
|
141 |
-
audio_id =os.path.splitext(os.path.basename(audio_filename))[0]
|
142 |
-
path = os.path.join(local_extracted_archive_path, audio_filename) if local_extracted_archive_path else audio_filename
|
143 |
-
yield audio_id, {
|
144 |
-
"audio_id": audio_id,
|
145 |
-
**{feature: metadata[audio_id][feature] for feature in features},
|
146 |
-
"audio": {"path": path, "bytes": audio_file.read()},
|
147 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|