Datasets:
File size: 6,354 Bytes
9a4b2d3 2e55d71 9a4b2d3 2e55d71 9a4b2d3 4a0e8de 9a4b2d3 e99c58b 9a4b2d3 8884e59 9a4b2d3 4abd87b 9a4b2d3 1aa1632 9a4b2d3 598981c 9a4b2d3 1aa1632 9a4b2d3 1aa1632 9a4b2d3 1aa1632 9a4b2d3 f840afe 9a4b2d3 cd84d81 9a4b2d3 1aa1632 9a4b2d3 1aa1632 9a4b2d3 8884e59 f405d8e 9a4b2d3 f840afe 9a4b2d3 f840afe cd84d81 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# Copyright 2023 KBLab and 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.
import json
import os
import datasets
import pandas as pd
_CITATION = """\
@misc{rekathati2023rixvox:,
author = {Rekathati, Faton},
title = {The KBLab Blog: RixVox: A Swedish Speech Corpus with 5500 Hours of Speech from Parliamentary Debates},
url = {https://kb-labb.github.io/posts/2023-03-09-rixvox-a-swedish-speech-corpus/},
year = {2023}
}
"""
_DESCRIPTION = """\
RixVox is a speech dataset comprised of speeches from the Swedish Parliament (the Riksdag). Audio from speeches have been aligned with official transcripts, on the sentence level, using aeneas.
Speaker metadata is available for each observation, including the speaker's name, gender, party, birth year and electoral district. The dataset contains a total of 5493 hours of speech.
An observation may consist of one or several sentences (up to 30 seconds in duration).
"""
# TODO: Add a link to an official homepage for the dataset here
_HOMEPAGE = ""
_LICENSE = "CC BY 4.0"
_N_SHARDS = {"train": 126, "dev": 2, "test": 2}
_BASE_PATH = "data/"
_META_URL = _BASE_PATH + "{split}_metadata.parquet"
_DATA_URL = _BASE_PATH + "{split}/{split}_{shard_idx}.tar.gz"
# TODO: Name of the dataset usually matches the script name with CamelCase instead of snake_case
class Rixvox(datasets.GeneratorBasedBuilder):
VERSION = datasets.Version("1.0.0")
DEFAULT_CONFIG_NAME = "all"
def _info(self):
features = datasets.Features(
{
"dokid": datasets.Value("string"),
"anforande_nummer": datasets.Value("int16"),
"observation_nr": datasets.Value("int16"),
"audio": datasets.features.Audio(sampling_rate=16_000),
"text": datasets.Value("string"),
"debatedate": datasets.Value("date32"),
"speaker": datasets.Value("string"),
"party": datasets.Value("string"),
"gender": datasets.Value("string"),
"birth_year": datasets.Value("int64"),
"electoral_district": datasets.Value("string"),
"intressent_id": datasets.Value("string"),
"speaker_from_id": datasets.Value("bool"),
"speaker_audio_meta": datasets.Value("string"),
"start": datasets.Value("float64"),
"end": datasets.Value("float64"),
"duration": datasets.Value("float64"),
"bleu_score": datasets.Value("float64"),
"filename": datasets.Value("string"),
"path": datasets.Value("string"),
"speaker_total_hours": datasets.Value("float64"),
# These are the features of your dataset like images, labels ...
}
)
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=features,
homepage=_HOMEPAGE,
license=_LICENSE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
# If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
splits = ["train", "dev", "test"]
meta_urls = {split: [_META_URL.format(split=split)] for split in splits}
archive_urls = {
split: [_DATA_URL.format(split=split, shard_idx=idx) for idx in range(0, _N_SHARDS[split])]
for split in splits
}
archive_paths = dl_manager.download(archive_urls)
local_extracted_archives = dl_manager.extract(archive_paths) if not dl_manager.is_streaming else {}
meta_paths = dl_manager.download(meta_urls)
split_generators = []
split_names = {
"train": datasets.Split.TRAIN,
"dev": datasets.Split.VALIDATION,
"test": datasets.Split.TEST,
}
for split in splits:
split_generators.append(
datasets.SplitGenerator(
name=split_names.get(split),
gen_kwargs={
"local_extracted_archive_paths": local_extracted_archives.get(split),
"archive_iters": [dl_manager.iter_archive(path) for path in archive_paths.get(split)],
"meta_paths": meta_paths[split],
},
),
)
return split_generators
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
def _generate_examples(
self,
local_extracted_archive_paths,
archive_iters,
meta_paths,
):
key = 0
data = []
for meta_path in meta_paths:
data.append(pd.read_parquet(meta_path))
df_meta = pd.concat(data)
df_meta = df_meta.set_index("filename", drop=False)
# Column contains NAType, so we convert to object type column and NAType to None values.
df_meta["birth_year"] = df_meta["birth_year"].astype("object").where(df_meta["birth_year"].notnull(), None)
for i, audio_archive in enumerate(archive_iters):
for filename, file in audio_archive:
if filename not in df_meta.index:
continue
result = dict(df_meta.loc[filename])
path = (
os.path.join(local_extracted_archive_paths[i], filename)
if local_extracted_archive_paths is not None
else filename
)
result["audio"] = {"path": path, "bytes": file.read()}
result["path"] = path if local_extracted_archive_paths else filename
yield key, result
key += 1
|