# coding=utf-8 # Copyright 2020 HuggingFace Datasets Authors. # # 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. # Lint as: python3 """This is a dataset for NiajaSpeechT5""" import datasets import pandas import pandas as pd import json import numpy as np logger = datasets.logging.get_logger(__name__) # def convert_to_array(array_string): # numeric_values = re.findall(r"[-+]?\d*\.\d+|\d+", array_string) # return np.array([float(val) for val in numeric_values]) # def convert_to_array(array_string): # # Split the string by non-numeric characters and filter out empty strings # numeric_values = [val for val in array_string.replace(',', ' ').split() if val.replace('.', '').replace('-', '').isdigit()] # return np.array([float(val) for val in numeric_values]) # lawallanre/hausa_common_voice_audio _CITATION = """ @inproceedings{ hausa_common_voice_audio, author = "Olanrewaju", month = "Dev", year = "2023", address = "Lagos, Nigeria", } """ _DESCRIPTION = """ hausa_common_voice_audio is a dataset for Hausa language. The dataset is a collection of audio files and their corresponding transcripts. The dataset is a subset of the Common Voice dataset. The dataset is split into train, test and validation sets. The dataset is useful for Automatic Speech Recognition and Natural Language Processing tasks. The language is:- English (eng) """ _URL = "https://github.com/lawallanre00490038/hausaCommonVoice/raw/main/" _TRAINING_FILE = "train.json" _DEV_FILE = "dev.json" _TEST_FILE = "test.json" class HausasCommonConfig(datasets.BuilderConfig): """BuilderConfig for GeoNLPsenti""" def __init__(self, **kwargs): """BuilderConfig for commonvoice. Args: **kwargs: keyword arguments forwarded to super. """ super(HausasCommonConfig, self).__init__(**kwargs) class HausaCommonVoice(datasets.GeneratorBasedBuilder): """commonvoice dataset.""" BUILDER_CONFIGS = [ HausasCommonConfig(name="en", version=datasets.Version("1.0.0"), description="Nollysenti English dataset") ] def _info(self): return datasets.DatasetInfo( description=_DESCRIPTION, features=datasets.Features( { "speaker_id": datasets.Value("string"), "audioname": datasets.Value("string"), "normalized_text": datasets.Value("string"), # "audio": datasets.Value("float32") } ), supervised_keys=None, homepage="https://github.com/lawallanre00490038/hausaCommonVoice", citation=_CITATION, ) def _split_generators(self, dl_manager): """Returns SplitGenerators.""" urls_to_download = { "train": f"{_URL}{self.config.name}/{_TRAINING_FILE}", "dev": f"{_URL}{self.config.name}/{_DEV_FILE}", "test": f"{_URL}{self.config.name}/{_TEST_FILE}", } downloaded_files = dl_manager.download_and_extract(urls_to_download) return [ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}), datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}), datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}), ] def _generate_examples(self, filepath): logger.info("⏳ Generating examples from = %s", filepath) # df = pd.read_json(filepath) # df = df.dropna() # N = df.shape[0] with open(filepath, "r", encoding="utf-8") as file: data = json.load(file) # for id_ in range(N): # yield id_, { # "speaker_id": df['speaker_id'].iloc[id_], # "audioname": df['audioname'].iloc[id_], # "normalized_text": df['normalized_text'].iloc[id_], # "audio": df['audio'].iloc[id_], # } for id_, example in enumerate(data): yield id_, { "speaker_id": example['speaker_id'], "audioname": example['audioname'], "normalized_text": example['normalized_text'], # "audio": example['audio'], }