banc-trawsgrifiadau-bangor / banc-trawsgrifiadau-bangor.py
prvInSpace's picture
Upload banc-trawsgrifiadau-bangor.py
d037432
raw
history blame
4.23 kB
"""Huggingface Dataset version of Banc Trawsgrifiadau Bangor"""
import os
import datasets
# TODO: Add BibTeX citation
_CITATION = """\
}
"""
_DESCRIPTION = """Huggingface Dataset version of Banc Trawsgrifiadau Bangor"""
_HOMEPAGE = "https://git.techiaith.bangor.ac.uk/data-porth-technolegau-iaith/banc-trawsgrifiadau-bangor"
_LICENSE = "Creative Commons Zero v1.0 Universal"
_URL = "https://huggingface.co/datasets/prvInSpace/banc-trawsgrifiadau-bangor/resolve/main"
# TODO: Name of the dataset usually matches the script name with CamelCase instead of snake_case
class BancTrawsgrifiadauBangor(datasets.GeneratorBasedBuilder):
"""Huggingface Dataset version of Banc Trawsgrifiadau Bangor"""
VERSION = datasets.Version("1.0.0")
def _info(self):
features = datasets.Features(
{
"audio_filename": datasets.Value("string"),
"audio_filesize": datasets.Value("string"),
"transcript": datasets.Value("string"),
"duration": datasets.Value("int64"),
"audio": datasets.features.Audio(sampling_rate=16_000)
# These are the features of your dataset like images, labels ...
}
)
return datasets.DatasetInfo(
# This is the description that will appear on the datasets page.
description=_DESCRIPTION,
# This defines the different columns of the dataset and their types
# Here we define them above because they are different between the two configurations
features=features,
# If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
# specify them. They'll be used if as_supervised=True in builder.as_dataset.
# supervised_keys=("sentence", "label"),
# Homepage of the dataset for documentation
homepage=_HOMEPAGE,
# License for the dataset if available
license=_LICENSE,
# Citation for the dataset
citation=_CITATION,
)
def _split_generators(self, dl_manager):
# Download the clips
data_dir = dl_manager.download_and_extract(
f"{_URL}/clips.zip")
# Generate the splits
return [
datasets.SplitGenerator(
name="clips",
# These kwargs will be passed to _generate_examples
gen_kwargs={
"filepath": dl_manager.download(f"{_URL}/clips.tsv"),
"path_to_clips": os.path.join(data_dir, "clips")
},
),
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
# These kwargs will be passed to _generate_examples
gen_kwargs={
"filepath": dl_manager.download(f"{_URL}/train.tsv"),
"path_to_clips": os.path.join(data_dir, "clips")
},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
# These kwargs will be passed to _generate_examples
gen_kwargs={
"filepath": dl_manager.download(f"{_URL}/test.tsv"),
"path_to_clips": os.path.join(data_dir, "clips")
},
),
]
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
def _generate_examples(self, filepath, path_to_clips):
print(path_to_clips)
import csv
# TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
# The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
with open(filepath, encoding="utf-8") as f:
reader = csv.DictReader(f, delimiter="\t")
for row in reader:
path = f'{path_to_clips}/{row["audio_filename"]}'
# Add the audio data
with open(path, "rb") as file:
row['audio'] = {
'path': path, 'bytes': file.read()
}
yield path, row