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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
SEA Crowd Data Loader for Bloom Speech.
|
| 3 |
+
"""
|
| 4 |
+
from typing import Dict, List, Tuple
|
| 5 |
+
|
| 6 |
+
import datasets
|
| 7 |
+
from datasets.download.download_manager import DownloadManager
|
| 8 |
+
|
| 9 |
+
from seacrowd.utils import schemas
|
| 10 |
+
from seacrowd.utils.configs import SEACrowdConfig
|
| 11 |
+
from seacrowd.utils.constants import TASK_TO_SCHEMA, Licenses, Tasks
|
| 12 |
+
|
| 13 |
+
_CITATION = r"""
|
| 14 |
+
@inproceedings{leong-etal-2022-bloom,
|
| 15 |
+
title = "Bloom Library: Multimodal Datasets in 300+ Languages for a Variety of Downstream Tasks",
|
| 16 |
+
author = "Leong, Colin and
|
| 17 |
+
Nemecek, Joshua and
|
| 18 |
+
Mansdorfer, Jacob and
|
| 19 |
+
Filighera, Anna and
|
| 20 |
+
Owodunni, Abraham and
|
| 21 |
+
Whitenack, Daniel",
|
| 22 |
+
editor = "Goldberg, Yoav and
|
| 23 |
+
Kozareva, Zornitsa and
|
| 24 |
+
Zhang, Yue",
|
| 25 |
+
booktitle = "Proceedings of the 2022 Conference on Empirical Methods in Natural Language Processing",
|
| 26 |
+
month = dec,
|
| 27 |
+
year = "2022",
|
| 28 |
+
address = "Abu Dhabi, United Arab Emirates",
|
| 29 |
+
publisher = "Association for Computational Linguistics",
|
| 30 |
+
url = "https://aclanthology.org/2022.emnlp-main.590",
|
| 31 |
+
doi = "10.18653/v1/2022.emnlp-main.590",
|
| 32 |
+
pages = "8608--8621",
|
| 33 |
+
}
|
| 34 |
+
"""
|
| 35 |
+
|
| 36 |
+
logger = datasets.logging.get_logger(__name__)
|
| 37 |
+
|
| 38 |
+
# this config is created for SEACrowd Dataloader
|
| 39 |
+
_LANG_CONFIG = {"bjn": "Banjar", "bzi": "Bisu", "ceb": "Cebuano", "ind": "Indonesian", "jra": "Jarai", "kqr": "Kimaragang", "mya": "Burmese", "tgl": "Tagalog"}
|
| 40 |
+
|
| 41 |
+
_LOCAL = False
|
| 42 |
+
_LANGUAGES = list(_LANG_CONFIG.keys())
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
_DATASETNAME = "bloom_speech"
|
| 46 |
+
_DESCRIPTION = r"""
|
| 47 |
+
This version of the Bloom Library data is developed specifically for the automatic speech recognition and speech-to-text tasks.
|
| 48 |
+
It includes data from 56 languages across 18 language families. 8 languages are spoken in Southeast Asia.
|
| 49 |
+
Before using this dataloader, please accept the acknowledgement at https://huggingface.co/datasets/sil-ai/bloom-speech and use huggingface-cli login for authentication.
|
| 50 |
+
"""
|
| 51 |
+
|
| 52 |
+
_HOMEPAGE = "https://huggingface.co/datasets/sil-ai/bloom-speech"
|
| 53 |
+
_LICENSE = Licenses.CC.value
|
| 54 |
+
|
| 55 |
+
_URL = "https://huggingface.co/datasets/sil-ai/bloom-speech"
|
| 56 |
+
_HF_REMOTE_REF = "/".join(_URL.split("/")[-2:])
|
| 57 |
+
|
| 58 |
+
_SUPPORTED_TASKS = [Tasks.SPEECH_RECOGNITION]
|
| 59 |
+
_SOURCE_VERSION = "0.0.1"
|
| 60 |
+
_SEACROWD_VERSION = "2024.06.20"
|
| 61 |
+
|
| 62 |
+
CONFIG_SUFFIXES_FOR_TASK = [TASK_TO_SCHEMA.get(task).lower() for task in _SUPPORTED_TASKS]
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def construct_configs_on_langs(languages: list = None) -> List[SEACrowdConfig]:
|
| 66 |
+
"""
|
| 67 |
+
The function `construct_configs` constructs a list of SEACrowdConfig objects based on the provided
|
| 68 |
+
languages or a default language, and returns the list.
|
| 69 |
+
|
| 70 |
+
input:
|
| 71 |
+
languages (list, default None): The `languages` parameter is a list that specifies the languages for which the
|
| 72 |
+
configurations need to be constructed. If no languages are provided (value=None), the first value in language config
|
| 73 |
+
will be used.
|
| 74 |
+
output:
|
| 75 |
+
a list of `SEACrowdConfig` objects based on instantiated init variables
|
| 76 |
+
"""
|
| 77 |
+
|
| 78 |
+
# set output var
|
| 79 |
+
config_list = []
|
| 80 |
+
|
| 81 |
+
# construct zipped arg for config instantiation
|
| 82 |
+
TASKS_AND_CONFIG_SUFFIX_PAIRS = list(zip(_SUPPORTED_TASKS, CONFIG_SUFFIXES_FOR_TASK))
|
| 83 |
+
|
| 84 |
+
# implement source schema
|
| 85 |
+
version, config_name_prefix = _SOURCE_VERSION, "source"
|
| 86 |
+
config_list += [
|
| 87 |
+
SEACrowdConfig(
|
| 88 |
+
name=f"{_DATASETNAME}_{_LANG}_{config_name_prefix}",
|
| 89 |
+
version=datasets.Version(version),
|
| 90 |
+
description=f"{_DATASETNAME} {config_name_prefix} schema for language code {_LANG}",
|
| 91 |
+
schema=f"{config_name_prefix}",
|
| 92 |
+
subset_id=_LANG,
|
| 93 |
+
)
|
| 94 |
+
for _LANG in languages
|
| 95 |
+
]
|
| 96 |
+
|
| 97 |
+
# implement SEACrowd schema
|
| 98 |
+
version, config_name_prefix = _SEACROWD_VERSION, "seacrowd"
|
| 99 |
+
for task_obj, config_name_suffix in TASKS_AND_CONFIG_SUFFIX_PAIRS:
|
| 100 |
+
config_list += [
|
| 101 |
+
SEACrowdConfig(
|
| 102 |
+
name=f"{_DATASETNAME}_{_LANG}_{config_name_prefix}_{config_name_suffix}",
|
| 103 |
+
version=datasets.Version(version),
|
| 104 |
+
description=f"{_DATASETNAME} {config_name_prefix} schema for {task_obj.name} and language code {_LANG}",
|
| 105 |
+
schema=f"{config_name_prefix}_{config_name_suffix}",
|
| 106 |
+
subset_id=_LANG,
|
| 107 |
+
)
|
| 108 |
+
for _LANG in languages
|
| 109 |
+
]
|
| 110 |
+
return config_list
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
class BloomSpeechDataset(datasets.GeneratorBasedBuilder):
|
| 114 |
+
"""Bloom Speech dataset, subsetted from https://huggingface.co/datasets/sil-ai/bloom-speech"""
|
| 115 |
+
|
| 116 |
+
# get all schema w/o lang arg + get all schema w/ lang arg
|
| 117 |
+
BUILDER_CONFIGS = construct_configs_on_langs(_LANGUAGES)
|
| 118 |
+
|
| 119 |
+
def _info(self) -> datasets.DatasetInfo:
|
| 120 |
+
_config_schema_name = self.config.schema
|
| 121 |
+
logger.info(f"Received schema name: {self.config.schema}")
|
| 122 |
+
# source schema
|
| 123 |
+
if _config_schema_name == "source":
|
| 124 |
+
features = datasets.Features(
|
| 125 |
+
{
|
| 126 |
+
"file": datasets.Value("string"),
|
| 127 |
+
"audio": datasets.Audio(sampling_rate=16_000),
|
| 128 |
+
"text": datasets.Value("string"),
|
| 129 |
+
"book": datasets.Value("string"),
|
| 130 |
+
"instance": datasets.Value("string"),
|
| 131 |
+
"license": datasets.Value("string"),
|
| 132 |
+
"credits": datasets.Value("string"),
|
| 133 |
+
"original_lang_tag": datasets.Value("string"),
|
| 134 |
+
}
|
| 135 |
+
)
|
| 136 |
+
|
| 137 |
+
# speech-text schema
|
| 138 |
+
elif _config_schema_name == "seacrowd_sptext":
|
| 139 |
+
features = schemas.speech_text_features
|
| 140 |
+
|
| 141 |
+
else:
|
| 142 |
+
raise ValueError(f"Received unexpected config schema of {_config_schema_name}!")
|
| 143 |
+
|
| 144 |
+
return datasets.DatasetInfo(
|
| 145 |
+
description=_DESCRIPTION,
|
| 146 |
+
features=features,
|
| 147 |
+
homepage=_HOMEPAGE,
|
| 148 |
+
license=_LICENSE,
|
| 149 |
+
citation=_CITATION,
|
| 150 |
+
)
|
| 151 |
+
|
| 152 |
+
def _split_generators(self, dl_manager: DownloadManager) -> List[datasets.SplitGenerator]:
|
| 153 |
+
hf_dset_dict = datasets.load_dataset(_HF_REMOTE_REF, self.config.subset_id)
|
| 154 |
+
|
| 155 |
+
return [datasets.SplitGenerator(name=datasets.Split(dset_key), gen_kwargs={"hf_dset": dset}) for dset_key, dset in hf_dset_dict.items() if dset.num_rows > 0]
|
| 156 |
+
|
| 157 |
+
def _generate_examples(self, hf_dset) -> Tuple[int, Dict]:
|
| 158 |
+
_config_schema_name = self.config.schema
|
| 159 |
+
|
| 160 |
+
_idx = 0
|
| 161 |
+
for datapoints in hf_dset:
|
| 162 |
+
# since no _idx is available to be used, we're creating it manually for both schema
|
| 163 |
+
if _config_schema_name == "source":
|
| 164 |
+
yield _idx, {colname: datapoints[colname] for colname in self.info.features}
|
| 165 |
+
|
| 166 |
+
elif _config_schema_name == "seacrowd_sptext":
|
| 167 |
+
yield _idx, {"id": _idx, "path": datapoints["file"], "audio": datapoints["audio"], "text": datapoints["text"], "speaker_id": None, "metadata": {"speaker_age": None, "speaker_gender": None}}
|
| 168 |
+
|
| 169 |
+
else:
|
| 170 |
+
raise ValueError(f"Received unexpected config schema of {_config_schema_name}!")
|
| 171 |
+
|
| 172 |
+
_idx += 1
|