carlosdanielhernandezmena commited on
Commit
4fd5463
1 Parent(s): 908b83a

Delete loading script

Browse files
Files changed (1) hide show
  1. tedx_spanish.py +0 -119
tedx_spanish.py DELETED
@@ -1,119 +0,0 @@
1
- from collections import defaultdict
2
- import os
3
- import json
4
- import csv
5
- import datasets
6
-
7
- _NAME="tedx_spanish"
8
- _VERSION="1.0.0"
9
-
10
- _DESCRIPTION = """
11
- The TEDX SPANISH CORPUS is a dataset created from TEDx talks in Spanish and it
12
- aims to be used in the Automatic Speech Recognition (ASR) Task.
13
- """
14
-
15
- _CITATION = """
16
- @misc{carlosmenatedxspanish2019,
17
- title={TEDX SPANISH CORPUS: Audio and Transcripts in Spanish in a CIEMPIESS Corpus style, taken from the TEDx Talks.},
18
- author={Hernandez Mena, Carlos Daniel},
19
- year={2019},
20
- url={https://huggingface.co/ciempiess/tedx_spanish},
21
- }
22
- """
23
-
24
- _HOMEPAGE = "https://huggingface.co/ciempiess/tedx_spanish"
25
-
26
- _LICENSE = "CC-BY-NC-ND-4.0, See https://creativecommons.org/licenses/by-nc-nd/4.0/"
27
-
28
- _BASE_DATA_DIR = "corpus/"
29
- _METADATA_TRAIN = os.path.join(_BASE_DATA_DIR,"files", "metadata_train.tsv")
30
-
31
- _TARS_TRAIN = os.path.join(_BASE_DATA_DIR,"files", "tars_train.paths")
32
-
33
- class TedxSpanishConfig(datasets.BuilderConfig):
34
- """BuilderConfig for TEDX SPANISH CORPUS"""
35
-
36
- def __init__(self, name, **kwargs):
37
- name=_NAME
38
- super().__init__(name=name, **kwargs)
39
-
40
- class TedxSpanish(datasets.GeneratorBasedBuilder):
41
- """TEDX SPANISH CORPUS"""
42
-
43
- VERSION = datasets.Version(_VERSION)
44
- BUILDER_CONFIGS = [
45
- TedxSpanishConfig(
46
- name=_NAME,
47
- version=datasets.Version(_VERSION),
48
- )
49
- ]
50
-
51
- def _info(self):
52
- features = datasets.Features(
53
- {
54
- "audio_id": datasets.Value("string"),
55
- "audio": datasets.Audio(sampling_rate=16000),
56
- "speaker_id": datasets.Value("string"),
57
- "gender": datasets.Value("string"),
58
- "duration": datasets.Value("float32"),
59
- "normalized_text": datasets.Value("string"),
60
- }
61
- )
62
- return datasets.DatasetInfo(
63
- description=_DESCRIPTION,
64
- features=features,
65
- homepage=_HOMEPAGE,
66
- license=_LICENSE,
67
- citation=_CITATION,
68
- )
69
-
70
- def _split_generators(self, dl_manager):
71
-
72
- metadata_train=dl_manager.download_and_extract(_METADATA_TRAIN)
73
-
74
- tars_train=dl_manager.download_and_extract(_TARS_TRAIN)
75
-
76
- hash_tar_files=defaultdict(dict)
77
-
78
- with open(tars_train,'r') as f:
79
- hash_tar_files['train']=[path.replace('\n','') for path in f]
80
-
81
- hash_meta_paths={"train":metadata_train}
82
- audio_paths = dl_manager.download(hash_tar_files)
83
-
84
- splits=["train"]
85
- local_extracted_audio_paths = (
86
- dl_manager.extract(audio_paths) if not dl_manager.is_streaming else
87
- {
88
- split:[None] * len(audio_paths[split]) for split in splits
89
- }
90
- )
91
-
92
- return [
93
- datasets.SplitGenerator(
94
- name=datasets.Split.TRAIN,
95
- gen_kwargs={
96
- "audio_archives": [dl_manager.iter_archive(archive) for archive in audio_paths["train"]],
97
- "local_extracted_archives_paths": local_extracted_audio_paths["train"],
98
- "metadata_paths": hash_meta_paths["train"],
99
- }
100
- ),
101
- ]
102
-
103
- def _generate_examples(self, audio_archives, local_extracted_archives_paths, metadata_paths):
104
-
105
- features = ["speaker_id","gender","duration","normalized_text"]
106
-
107
- with open(metadata_paths) as f:
108
- metadata = {x["audio_id"]: x for x in csv.DictReader(f, delimiter="\t")}
109
-
110
- for audio_archive, local_extracted_archive_path in zip(audio_archives, local_extracted_archives_paths):
111
- for audio_filename, audio_file in audio_archive:
112
- audio_id =os.path.splitext(os.path.basename(audio_filename))[0]
113
- path = os.path.join(local_extracted_archive_path, audio_filename) if local_extracted_archive_path else audio_filename
114
-
115
- yield audio_id, {
116
- "audio_id": audio_id,
117
- **{feature: metadata[audio_id][feature] for feature in features},
118
- "audio": {"path": path, "bytes": audio_file.read()},
119
- }