Datasets:
imvladikon
commited on
Commit
•
395ac9f
1
Parent(s):
f3c3607
Create to_generate.py
Browse files- to_generate.py +131 -0
to_generate.py
ADDED
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
# -*- coding: utf-8 -*-
|
3 |
+
import glob
|
4 |
+
import json
|
5 |
+
import os
|
6 |
+
from functools import partial
|
7 |
+
from pathlib import Path
|
8 |
+
|
9 |
+
import datasets
|
10 |
+
|
11 |
+
VERSION = datasets.Version("0.0.1")
|
12 |
+
|
13 |
+
SAMPLE_RATE = 16000
|
14 |
+
|
15 |
+
URLS = {'introduction_psychology': 'data/introduction_psychology.zip',
|
16 |
+
'a_descriptive_statistics': 'data/a_descriptive_statistics.zip',
|
17 |
+
'inherited_how_does_the_internet_work': 'data/inherited_how_does_the_internet_work.zip',
|
18 |
+
'data_structures': 'data/data_structures.zip',
|
19 |
+
'computational_thinking': 'data/computational_thinking.zip',
|
20 |
+
'physics_intro': 'data/physics_intro.zip',
|
21 |
+
'data_intro': 'data/data_intro.zip',
|
22 |
+
'introduction_to_the_philosophy_of_education': 'data/introduction_to_the_philosophy_of_education.zip',
|
23 |
+
'yad_vashem': 'data/yad_vashem.zip',
|
24 |
+
'algorithms': 'data/algorithms.zip',
|
25 |
+
'blue-and-white_tv': 'data/blue-and-white_tv.zip',
|
26 |
+
'covid_mindfulness': 'data/covid_mindfulness.zip',
|
27 |
+
'preparation_for_a_job_interview-_ways_to_success': 'data/preparation_for_a_job_interview-_ways_to_success.zip',
|
28 |
+
'what_is_the_world_introduction_to_general_chemistry': 'data/what_is_the_world_introduction_to_general_chemistry.zip',
|
29 |
+
'networking_create_a_network_of_professional_progress': 'data/networking_create_a_network_of_professional_progress.zip',
|
30 |
+
'how_to_learn': 'data/how_to_learn.zip',
|
31 |
+
'post_modern_education': 'data/post_modern_education.zip',
|
32 |
+
'introduction_to_renewable_energy': 'data/introduction_to_renewable_energy.zip',
|
33 |
+
'science_communication': 'data/science_communication.zip',
|
34 |
+
'introduction_to_physics_-_mechanics': 'data/introduction_to_physics_-_mechanics.zip',
|
35 |
+
'negotiations_different_cultures_and_what_between_them': 'data/negotiations_different_cultures_and_what_between_them.zip',
|
36 |
+
'computation_models': 'data/computation_models.zip',
|
37 |
+
'object_oriented_programming': 'data/object_oriented_programming.zip',
|
38 |
+
'from_another_angle_math': 'data/from_another_angle_math.zip'}
|
39 |
+
|
40 |
+
|
41 |
+
class CampusHebrewSpeech(datasets.GeneratorBasedBuilder):
|
42 |
+
BUILDER_CONFIGS = [
|
43 |
+
datasets.BuilderConfig(name="campus_hebrew_speech",
|
44 |
+
version=VERSION,
|
45 |
+
description=f"Campus Hebrew Speech Recognition dataset")
|
46 |
+
]
|
47 |
+
|
48 |
+
def _info(self):
|
49 |
+
return datasets.DatasetInfo(
|
50 |
+
description="Hebrew speech datasets",
|
51 |
+
features=datasets.Features(
|
52 |
+
{
|
53 |
+
"uid": datasets.Value("string"),
|
54 |
+
"file_id": datasets.Value("string"),
|
55 |
+
"audio": datasets.Audio(sampling_rate=SAMPLE_RATE),
|
56 |
+
"sentence": datasets.Value("string"),
|
57 |
+
"n_segment": datasets.Value("int32"),
|
58 |
+
"duration_ms": datasets.Value("float32"),
|
59 |
+
"language": datasets.Value("string"),
|
60 |
+
"sample_rate": datasets.Value("int32"),
|
61 |
+
"course": datasets.Value("string"),
|
62 |
+
"sentence_length": datasets.Value("int32"),
|
63 |
+
"n_tokens": datasets.Value("int32"),
|
64 |
+
}
|
65 |
+
),
|
66 |
+
supervised_keys=("audio", "sentence"),
|
67 |
+
homepage="https://huggingface.co/datasets/imvladikon/hebrew_speech_campus",
|
68 |
+
citation="TODO",
|
69 |
+
)
|
70 |
+
|
71 |
+
def _split_generators(self, dl_manager):
|
72 |
+
# course_links = {
|
73 |
+
# course: dl_manager.download_and_extract(link) + "/" + course
|
74 |
+
# for course, link in URLS.items()
|
75 |
+
# }
|
76 |
+
course_links = {
|
77 |
+
'from_another_angle-_mathematics_teaching_practices': 'data/from_another_angle-_mathematics_teaching_practices',
|
78 |
+
'introduction_to_renewable_energy': 'data/introduction_to_renewable_energy',
|
79 |
+
'negotiations_different_cultures_and_what_between_them': 'data/negotiations_different_cultures_and_what_between_them',
|
80 |
+
'introduction_to_physics_-_mechanics': 'data/introduction_to_physics_-_mechanics',
|
81 |
+
'networking-_create_a_network_of_professional_progress': 'data/networking-_create_a_network_of_professional_progress',
|
82 |
+
'post_modern_education': 'data/post_modern_education',
|
83 |
+
'physics_intro': 'data/physics_intro',
|
84 |
+
'algorithms': 'data/algorithms',
|
85 |
+
'blue-and-white_tv': 'data/blue-and-white_tv',
|
86 |
+
'what_is_the_world-_introduction_to_general_chemistry': 'data/what_is_the_world-_introduction_to_general_chemistry',
|
87 |
+
'computational_thinking': 'data/computational_thinking',
|
88 |
+
'preparation_for_a_job_interview-_ways_to_success': 'data/preparation_for_a_job_interview-_ways_to_success',
|
89 |
+
'a_descriptive_statistics': 'data/a_descriptive_statistics',
|
90 |
+
'yad_vashem': 'data/yad_vashem',
|
91 |
+
'introduction_to_the_philosophy_of_education': 'data/introduction_to_the_philosophy_of_education',
|
92 |
+
'covid_mindfulness': 'data/covid_mindfulness',
|
93 |
+
'data_structures': 'data/data_structures',
|
94 |
+
'computation_models': 'data/computation_models',
|
95 |
+
'introduction_psychology': 'data/introduction_psychology',
|
96 |
+
'how_to_learn': 'data/how_to_learn',
|
97 |
+
'inherited_-_how_does_the_internet_work': 'data/inherited_-_how_does_the_internet_work',
|
98 |
+
'object_oriented_programming': 'data/object_oriented_programming',
|
99 |
+
'science_communication': 'data/science_communication',
|
100 |
+
'data_intro': 'data/data_intro'}
|
101 |
+
|
102 |
+
return [
|
103 |
+
datasets.SplitGenerator(
|
104 |
+
name=datasets.Split.TRAIN,
|
105 |
+
gen_kwargs={
|
106 |
+
"course_links": course_links,
|
107 |
+
"split": "train"},
|
108 |
+
)
|
109 |
+
]
|
110 |
+
|
111 |
+
def _generate_examples(self, course_links, split):
|
112 |
+
idx = 0
|
113 |
+
for course, root_path in course_links.items():
|
114 |
+
root_path = "/content/hebrew_speech_campus/" + root_path
|
115 |
+
for metadata_file in Path(root_path).glob("*.json"):
|
116 |
+
audio_file = Path(metadata_file).stem + ".wav"
|
117 |
+
metadata = json.load(open(metadata_file, encoding="utf-8"))
|
118 |
+
yield idx, {
|
119 |
+
"uid": metadata["file"].split("_")[0],
|
120 |
+
"file_id": Path(metadata["file"]).stem,
|
121 |
+
"audio": os.path.join(root_path, audio_file),
|
122 |
+
"sentence": metadata["text"],
|
123 |
+
"n_segment": metadata["n_segment"],
|
124 |
+
"duration_ms": 1000 * metadata["duration"],
|
125 |
+
"language": metadata["language"],
|
126 |
+
"sample_rate": SAMPLE_RATE,
|
127 |
+
"course": course,
|
128 |
+
"sentence_length": len(metadata["text"]),
|
129 |
+
"n_tokens": metadata["text"].count(" ") + 1,
|
130 |
+
}
|
131 |
+
idx += 1
|