Datasets:
ArXiv:
License:
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor. | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
# See the License for the specific language governing permissions and | |
# limitations under the License. | |
# TODO: Address all TODOs and remove all explanatory comments | |
"""TODO: Add a description here.""" | |
import os | |
import csv | |
import json | |
import datasets | |
import pandas as pd | |
from scipy.io import wavfile | |
_CITATION = """\ | |
@inproceedings{Raju2022SnowMD, | |
title={Snow Mountain: Dataset of Audio Recordings of The Bible in Low Resource Languages}, | |
author={Kavitha Raju and V. Anjaly and R. Allen Lish and Joel Mathew}, | |
year={2022} | |
} | |
""" | |
_DESCRIPTION = """\ | |
The Snow Mountain dataset contains the audio recordings (in .mp3 format) and the corresponding text of The Bible | |
in 11 Indian languages. The recordings were done in a studio setting by native speakers. Each language has a single | |
speaker in the dataset. Most of these languages are geographically concentrated in the Northern part of India around | |
the state of Himachal Pradesh. Being related to Hindi they all use the Devanagari script for transcription. | |
""" | |
_HOMEPAGE = "https://gitlabdev.bridgeconn.com/software/research/datasets/snow-mountain" | |
_LICENSE = "" | |
_URL = "https://gitlabdev.bridgeconn.com/software/research/datasets/snow-mountain/" | |
_FILES = {} | |
_LANGUAGES = ['hindi', 'dogri', 'gaddi'] | |
for lang in _LANGUAGES: | |
file_dic = { | |
"train_500": f"data/experiments/{lang}/train_500.csv", | |
"val_500": f"data/experiments/{lang}/val_500.csv", | |
"train_1000": f"data/experiments/{lang}/train_1000.csv", | |
"val_1000": f"data/experiments/{lang}/val_1000.csv", | |
"train_2500": f"data/experiments/{lang}/train_2500.csv", | |
"val_2500": f"data/experiments/{lang}/val_2500.csv", | |
"train_short": f"data/experiments/{lang}/train_short.csv", | |
"val_short": f"data/experiments/{lang}/val_short.csv", | |
"train_full": f"data/experiments/{lang}/train_full.csv", | |
"val_full": f"data/experiments/{lang}/val_full.csv", | |
"test_common": f"data/experiments/{lang}/test_common.csv", | |
"all_verses": f"data/cleaned/{lang}/all_verses.csv", | |
"short_verses": f"data/cleaned/{lang}/short_verses.csv", | |
} | |
_FILES[lang] = file_dic | |
class Test(datasets.GeneratorBasedBuilder): | |
VERSION = datasets.Version("1.0.0") | |
BUILDER_CONFIGS = [] | |
for lang in _LANGUAGES: | |
text = lang.capitalize()+" data" | |
BUILDER_CONFIGS.append(datasets.BuilderConfig(name=f"{lang}", version=VERSION, description=text)) | |
DEFAULT_CONFIG_NAME = "hindi" | |
def _info(self): | |
features = datasets.Features( | |
{ | |
"sentence": datasets.Value("string"), | |
"audio": datasets.features.Audio(sampling_rate=16_000), | |
"path": datasets.Value("string"), | |
} | |
) | |
return datasets.DatasetInfo( | |
description=_DESCRIPTION, | |
features=features, | |
supervised_keys=("sentence", "path"), | |
homepage=_HOMEPAGE, | |
license=_LICENSE, | |
citation=_CITATION, | |
) | |
def _split_generators(self, dl_manager): | |
downloaded_files = dl_manager.download(_FILES[self.config.name]) | |
data_size = ['500', '1000', '2500', 'short', 'full'] | |
splits = [] | |
for size in data_size: | |
splits.append( | |
datasets.SplitGenerator( | |
name=f"train_{size}", | |
gen_kwargs={ | |
"filepath": downloaded_files[f"train_{size}"], | |
"dl_manager": dl_manager, | |
}, | |
) | |
) | |
splits.append( | |
datasets.SplitGenerator( | |
name=f"val_{size}", | |
gen_kwargs={ | |
"filepath": downloaded_files[f"val_{size}"], | |
"dl_manager": dl_manager, | |
}, | |
) | |
) | |
splits.append( | |
datasets.SplitGenerator( | |
name="test_common", | |
gen_kwargs={ | |
"filepath": downloaded_files["test_common"], | |
"dl_manager": dl_manager, | |
}, | |
) | |
) | |
splits.append( | |
datasets.SplitGenerator( | |
name="all_verses", | |
gen_kwargs={ | |
"filepath": downloaded_files["all_verses"], | |
"dl_manager": dl_manager, | |
}, | |
) | |
) | |
splits.append( | |
datasets.SplitGenerator( | |
name="short_verses", | |
gen_kwargs={ | |
"filepath": downloaded_files["short_verses"], | |
"dl_manager": dl_manager, | |
}, | |
) | |
) | |
return splits | |
def _generate_examples(self, filepath, dl_manager): | |
key = 0 | |
with open(filepath) as f: | |
data_df = pd.read_csv(f,sep=',') | |
audio_data = {} | |
for index,row in data_df.iterrows(): | |
audio = row['path'].split('/')[-1] | |
if audio in audio_data: | |
content = audio_data[audio] | |
else: | |
archive_url = '/'.join(row["path"].split('/')[:-1])+'.tar.gz' | |
archive_path = dl_manager.download(archive_url) | |
for path, file in dl_manager.iter_archive(archive_path): | |
audio_ = path.split('/')[-1] | |
if audio_ not in audio_data: | |
content = file.read() | |
audio_data[audio_] = content | |
if audio in audio_data: | |
content = audio_data[audio] | |
yield key, { | |
"sentence": row["sentence"], | |
"path": row["path"], | |
"audio":{"path": row["path"], "bytes": content} | |
} | |
key+=1 | |