|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""NST_hesitate_hesitate: Nordic Language Technology""" |
|
|
|
import io |
|
import json |
|
import tarfile |
|
import datasets |
|
|
|
|
|
_CITATION = """\ |
|
@inproceedings{, |
|
title={}, |
|
author={}, |
|
booktitle={}, |
|
year={2022}, |
|
url={https://arxiv.org/abs/} |
|
} |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
This database was created by Nordic Language Technology for the development of automatic speech recognition and dictation in Norwegian. In this version, the organization of the data have been altered to improve the usefulness of the database. |
|
|
|
The acoustic databases described below were developed by the firm Nordisk språkteknologi holding AS (NST_hesitate), which went bankrupt in 2003. In 2006, a consortium consisting of the University of Oslo, the University of Bergen, the Norwegian University of Science and Technology, the Norwegian Language Council and IBM bought the bankruptcy estate of NST_hesitate, in order to ensure that the language resources developed by NST_hesitate were preserved. In 2009, the Norwegian Ministry of Culture charged the National Library of Norway with the task of creating a Norwegian language bank, which they initiated in 2010. The resources from NST_hesitate were transferred to the National Library in May 2011, and are now made available in Språkbanken, for the time being without any further modification. Språkbanken is open for feedback from users about how the resources can be improved, and we are also interested in improved versions of the databases that users wish to share with other users. Please send response and feedback to [email protected]. |
|
""" |
|
|
|
_HOMEPAGE = "https://www.nb.no/sprakbanken/en/resource-catalogue/oai-nb-no-sbr-54/" |
|
|
|
|
|
_DATA_URL = "https://huggingface.co/datasets/NbAiLab/NST_hesitate/resolve/main/data/{split}/NST_hesitate_{lang_code}-{shard_idx:04d}-of-{shard_total:04d}.tar.gz" |
|
|
|
_METADATA_URL = "https://huggingface.co/datasets/NbAiLab/NST_hesitate/resolve/main/data/{split}/NST_hesitate_{lang_code}-{shard_idx:04d}-of-{shard_total:04d}.json" |
|
|
|
_SHARDS = { |
|
"no": { |
|
"test":1, |
|
"train": 1, |
|
}, |
|
} |
|
|
|
_METADATA_MAPPING = { |
|
"id": "Id", |
|
"speakerId": "SpeakerId", |
|
"speakerName": "SpeakerName", |
|
"speakerAge": "SpeakerAge", |
|
"sex": "Sex", |
|
"speakerBirthPlace": "SpeakerBirthPlace", |
|
"speakerYouth": "SpeakerYouth", |
|
"speakerSheet": "SpeakerSheet", |
|
"script": "Script", |
|
"version": "Version", |
|
"board": "Board", |
|
"coding": "Coding", |
|
"frequency": "Frequency", |
|
"channels": "Channels", |
|
"byteFormat": "Byteformat", |
|
"delimiter": "Delimiter", |
|
"characterSet": "CharacterSet", |
|
"ansi_codepage": "Ansi_codepage", |
|
"dos_codepage": "Dos_codepage", |
|
"normalizedText": "normalizedText", |
|
"text": "text", |
|
"file": "file", |
|
|
|
} |
|
|
|
|
|
class NST_hesitateConfig(datasets.BuilderConfig): |
|
"""BuilderConfig for NST_hesitate.""" |
|
|
|
def __init__(self, *args, **kwargs): |
|
"""BuilderConfig for NST_hesitate. |
|
Args: |
|
**kwargs: keyword arguments forwarded to super. |
|
""" |
|
super(NST_hesitateConfig, self).__init__(*args, **kwargs) |
|
|
|
|
|
class NST_hesitate(datasets.GeneratorBasedBuilder): |
|
"""NST_hesitate dataset.""" |
|
|
|
DEFAULT_WRITER_BATCH_SIZE = 1000 |
|
BUILDER_CONFIGS = [ |
|
NST_hesitateConfig( |
|
name="no", |
|
version=datasets.Version("1.0.1"), |
|
description="NST_hesitate Norwegian", |
|
), |
|
|
|
] |
|
|
|
def _info(self): |
|
sampling_rate = 16000 |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=datasets.Features({ |
|
"id": datasets.Value("string"), |
|
"audio": datasets.features.Audio(sampling_rate=sampling_rate), |
|
"speakerId": datasets.Value("string"), |
|
"speakerName": datasets.Value("string"), |
|
"speakerAge": datasets.Value("string"), |
|
"sex": datasets.Value("string"), |
|
"speakerBirthPlace": datasets.Value("string"), |
|
"speakerYouth": datasets.Value("string"), |
|
"speakerSheet": datasets.Value("string"), |
|
"script": datasets.Value("string"), |
|
"version": datasets.Value("string"), |
|
"board": datasets.Value("string"), |
|
"coding": datasets.Value("string"), |
|
"frequency": datasets.Value("string"), |
|
"channels": datasets.Value("string"), |
|
"byteFormat": datasets.Value("string"), |
|
"delimiter": datasets.Value("string"), |
|
"characterSet": datasets.Value("string"), |
|
"ansi_codepage": datasets.Value("string"), |
|
"dos_codepage": datasets.Value("string"), |
|
"normalizedText": datasets.Value("string"), |
|
"text": datasets.Value("string"), |
|
"file": datasets.Value("string"), |
|
|
|
}), |
|
supervised_keys=None, |
|
homepage=_HOMEPAGE, |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
"""Returns SplitGenerators.""" |
|
data_urls = {} |
|
|
|
|
|
for split in ["train", "test"]: |
|
data_urls[split] = [] |
|
|
|
shard_total = _SHARDS["no"][split] |
|
for shard_idx in range(1, shard_total + 1): |
|
|
|
|
|
string_formatting = dict( |
|
split=split, |
|
lang_code="no", |
|
shard_idx=shard_idx, |
|
shard_total=shard_total |
|
) |
|
data_urls[split] += [( |
|
_METADATA_URL.format(**string_formatting), |
|
_DATA_URL.format(**string_formatting) |
|
)] |
|
train_downloaded_data = dl_manager.download(data_urls["train"]) |
|
test_downloaded_data = dl_manager.download(data_urls["test"]) |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, gen_kwargs={ |
|
"filepaths": train_downloaded_data, |
|
} |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, gen_kwargs={ |
|
"filepaths": test_downloaded_data, |
|
} |
|
), |
|
] |
|
|
|
def _generate_examples(self, filepaths): |
|
"""Yields examples.""" |
|
|
|
data_fields = list(self._info().features.keys()) |
|
data_fields.remove("id") |
|
data_fields.remove("audio") |
|
for metadata_path, archive_path in filepaths: |
|
metadata = {} |
|
with open(metadata_path) as metadata_file: |
|
for line in metadata_file.read().split("\n"): |
|
if line: |
|
metadata_object = json.loads(line) |
|
metadata_key = metadata_object["id"] |
|
|
|
metadata[metadata_key] = metadata_object |
|
with open(archive_path, "rb") as archive_fs: |
|
archive_bytes = io.BytesIO(archive_fs.read()) |
|
with tarfile.open(fileobj=archive_bytes, mode="r") as tar: |
|
for audio_file in tar.getmembers(): |
|
if audio_file.isfile() and audio_file.name.endswith(".mp3"): |
|
metadata_key = f'{audio_file.name.replace(".mp3", "")}' |
|
audio_bytes = tar.extractfile(audio_file).read() |
|
audio_dict = {"bytes": audio_bytes, "path": audio_file.name} |
|
fields = {key: metadata[metadata_key].get(_METADATA_MAPPING[key], "") for key in data_fields} |
|
fields["channels"] = 1 |
|
fields["file"] = fields["file"].replace(".wav", ".mp3") |
|
fields["frequency"] = 16000 |
|
|
|
|
|
yield metadata_key, { |
|
"id": metadata_key, |
|
"audio": audio_dict, |
|
**fields |
|
} |
|
|