hebrew_speech_campus / to_generate.py
imvladikon's picture
Create to_generate.py
395ac9f
raw
history blame
6.89 kB
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import glob
import json
import os
from functools import partial
from pathlib import Path
import datasets
VERSION = datasets.Version("0.0.1")
SAMPLE_RATE = 16000
URLS = {'introduction_psychology': 'data/introduction_psychology.zip',
'a_descriptive_statistics': 'data/a_descriptive_statistics.zip',
'inherited_how_does_the_internet_work': 'data/inherited_how_does_the_internet_work.zip',
'data_structures': 'data/data_structures.zip',
'computational_thinking': 'data/computational_thinking.zip',
'physics_intro': 'data/physics_intro.zip',
'data_intro': 'data/data_intro.zip',
'introduction_to_the_philosophy_of_education': 'data/introduction_to_the_philosophy_of_education.zip',
'yad_vashem': 'data/yad_vashem.zip',
'algorithms': 'data/algorithms.zip',
'blue-and-white_tv': 'data/blue-and-white_tv.zip',
'covid_mindfulness': 'data/covid_mindfulness.zip',
'preparation_for_a_job_interview-_ways_to_success': 'data/preparation_for_a_job_interview-_ways_to_success.zip',
'what_is_the_world_introduction_to_general_chemistry': 'data/what_is_the_world_introduction_to_general_chemistry.zip',
'networking_create_a_network_of_professional_progress': 'data/networking_create_a_network_of_professional_progress.zip',
'how_to_learn': 'data/how_to_learn.zip',
'post_modern_education': 'data/post_modern_education.zip',
'introduction_to_renewable_energy': 'data/introduction_to_renewable_energy.zip',
'science_communication': 'data/science_communication.zip',
'introduction_to_physics_-_mechanics': 'data/introduction_to_physics_-_mechanics.zip',
'negotiations_different_cultures_and_what_between_them': 'data/negotiations_different_cultures_and_what_between_them.zip',
'computation_models': 'data/computation_models.zip',
'object_oriented_programming': 'data/object_oriented_programming.zip',
'from_another_angle_math': 'data/from_another_angle_math.zip'}
class CampusHebrewSpeech(datasets.GeneratorBasedBuilder):
BUILDER_CONFIGS = [
datasets.BuilderConfig(name="campus_hebrew_speech",
version=VERSION,
description=f"Campus Hebrew Speech Recognition dataset")
]
def _info(self):
return datasets.DatasetInfo(
description="Hebrew speech datasets",
features=datasets.Features(
{
"uid": datasets.Value("string"),
"file_id": datasets.Value("string"),
"audio": datasets.Audio(sampling_rate=SAMPLE_RATE),
"sentence": datasets.Value("string"),
"n_segment": datasets.Value("int32"),
"duration_ms": datasets.Value("float32"),
"language": datasets.Value("string"),
"sample_rate": datasets.Value("int32"),
"course": datasets.Value("string"),
"sentence_length": datasets.Value("int32"),
"n_tokens": datasets.Value("int32"),
}
),
supervised_keys=("audio", "sentence"),
homepage="https://huggingface.co/datasets/imvladikon/hebrew_speech_campus",
citation="TODO",
)
def _split_generators(self, dl_manager):
# course_links = {
# course: dl_manager.download_and_extract(link) + "/" + course
# for course, link in URLS.items()
# }
course_links = {
'from_another_angle-_mathematics_teaching_practices': 'data/from_another_angle-_mathematics_teaching_practices',
'introduction_to_renewable_energy': 'data/introduction_to_renewable_energy',
'negotiations_different_cultures_and_what_between_them': 'data/negotiations_different_cultures_and_what_between_them',
'introduction_to_physics_-_mechanics': 'data/introduction_to_physics_-_mechanics',
'networking-_create_a_network_of_professional_progress': 'data/networking-_create_a_network_of_professional_progress',
'post_modern_education': 'data/post_modern_education',
'physics_intro': 'data/physics_intro',
'algorithms': 'data/algorithms',
'blue-and-white_tv': 'data/blue-and-white_tv',
'what_is_the_world-_introduction_to_general_chemistry': 'data/what_is_the_world-_introduction_to_general_chemistry',
'computational_thinking': 'data/computational_thinking',
'preparation_for_a_job_interview-_ways_to_success': 'data/preparation_for_a_job_interview-_ways_to_success',
'a_descriptive_statistics': 'data/a_descriptive_statistics',
'yad_vashem': 'data/yad_vashem',
'introduction_to_the_philosophy_of_education': 'data/introduction_to_the_philosophy_of_education',
'covid_mindfulness': 'data/covid_mindfulness',
'data_structures': 'data/data_structures',
'computation_models': 'data/computation_models',
'introduction_psychology': 'data/introduction_psychology',
'how_to_learn': 'data/how_to_learn',
'inherited_-_how_does_the_internet_work': 'data/inherited_-_how_does_the_internet_work',
'object_oriented_programming': 'data/object_oriented_programming',
'science_communication': 'data/science_communication',
'data_intro': 'data/data_intro'}
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"course_links": course_links,
"split": "train"},
)
]
def _generate_examples(self, course_links, split):
idx = 0
for course, root_path in course_links.items():
root_path = "/content/hebrew_speech_campus/" + root_path
for metadata_file in Path(root_path).glob("*.json"):
audio_file = Path(metadata_file).stem + ".wav"
metadata = json.load(open(metadata_file, encoding="utf-8"))
yield idx, {
"uid": metadata["file"].split("_")[0],
"file_id": Path(metadata["file"]).stem,
"audio": os.path.join(root_path, audio_file),
"sentence": metadata["text"],
"n_segment": metadata["n_segment"],
"duration_ms": 1000 * metadata["duration"],
"language": metadata["language"],
"sample_rate": SAMPLE_RATE,
"course": course,
"sentence_length": len(metadata["text"]),
"n_tokens": metadata["text"].count(" ") + 1,
}
idx += 1