Datasets:
prvInSpace
commited on
Commit
•
d037432
1
Parent(s):
b379045
Upload banc-trawsgrifiadau-bangor.py
Browse files- banc-trawsgrifiadau-bangor.py +103 -0
banc-trawsgrifiadau-bangor.py
ADDED
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Huggingface Dataset version of Banc Trawsgrifiadau Bangor"""
|
2 |
+
|
3 |
+
|
4 |
+
import os
|
5 |
+
import datasets
|
6 |
+
|
7 |
+
|
8 |
+
# TODO: Add BibTeX citation
|
9 |
+
_CITATION = """\
|
10 |
+
}
|
11 |
+
"""
|
12 |
+
_DESCRIPTION = """Huggingface Dataset version of Banc Trawsgrifiadau Bangor"""
|
13 |
+
_HOMEPAGE = "https://git.techiaith.bangor.ac.uk/data-porth-technolegau-iaith/banc-trawsgrifiadau-bangor"
|
14 |
+
_LICENSE = "Creative Commons Zero v1.0 Universal"
|
15 |
+
_URL = "https://huggingface.co/datasets/prvInSpace/banc-trawsgrifiadau-bangor/resolve/main"
|
16 |
+
|
17 |
+
# TODO: Name of the dataset usually matches the script name with CamelCase instead of snake_case
|
18 |
+
|
19 |
+
|
20 |
+
class BancTrawsgrifiadauBangor(datasets.GeneratorBasedBuilder):
|
21 |
+
"""Huggingface Dataset version of Banc Trawsgrifiadau Bangor"""
|
22 |
+
|
23 |
+
VERSION = datasets.Version("1.0.0")
|
24 |
+
|
25 |
+
def _info(self):
|
26 |
+
features = datasets.Features(
|
27 |
+
{
|
28 |
+
"audio_filename": datasets.Value("string"),
|
29 |
+
"audio_filesize": datasets.Value("string"),
|
30 |
+
"transcript": datasets.Value("string"),
|
31 |
+
"duration": datasets.Value("int64"),
|
32 |
+
"audio": datasets.features.Audio(sampling_rate=16_000)
|
33 |
+
# These are the features of your dataset like images, labels ...
|
34 |
+
}
|
35 |
+
)
|
36 |
+
return datasets.DatasetInfo(
|
37 |
+
# This is the description that will appear on the datasets page.
|
38 |
+
description=_DESCRIPTION,
|
39 |
+
# This defines the different columns of the dataset and their types
|
40 |
+
# Here we define them above because they are different between the two configurations
|
41 |
+
features=features,
|
42 |
+
# If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
|
43 |
+
# specify them. They'll be used if as_supervised=True in builder.as_dataset.
|
44 |
+
# supervised_keys=("sentence", "label"),
|
45 |
+
# Homepage of the dataset for documentation
|
46 |
+
homepage=_HOMEPAGE,
|
47 |
+
# License for the dataset if available
|
48 |
+
license=_LICENSE,
|
49 |
+
# Citation for the dataset
|
50 |
+
citation=_CITATION,
|
51 |
+
)
|
52 |
+
|
53 |
+
def _split_generators(self, dl_manager):
|
54 |
+
|
55 |
+
# Download the clips
|
56 |
+
data_dir = dl_manager.download_and_extract(
|
57 |
+
f"{_URL}/clips.zip")
|
58 |
+
|
59 |
+
# Generate the splits
|
60 |
+
return [
|
61 |
+
datasets.SplitGenerator(
|
62 |
+
name="clips",
|
63 |
+
# These kwargs will be passed to _generate_examples
|
64 |
+
gen_kwargs={
|
65 |
+
"filepath": dl_manager.download(f"{_URL}/clips.tsv"),
|
66 |
+
"path_to_clips": os.path.join(data_dir, "clips")
|
67 |
+
},
|
68 |
+
),
|
69 |
+
datasets.SplitGenerator(
|
70 |
+
name=datasets.Split.TRAIN,
|
71 |
+
# These kwargs will be passed to _generate_examples
|
72 |
+
gen_kwargs={
|
73 |
+
"filepath": dl_manager.download(f"{_URL}/train.tsv"),
|
74 |
+
"path_to_clips": os.path.join(data_dir, "clips")
|
75 |
+
},
|
76 |
+
),
|
77 |
+
datasets.SplitGenerator(
|
78 |
+
name=datasets.Split.TEST,
|
79 |
+
# These kwargs will be passed to _generate_examples
|
80 |
+
gen_kwargs={
|
81 |
+
"filepath": dl_manager.download(f"{_URL}/test.tsv"),
|
82 |
+
"path_to_clips": os.path.join(data_dir, "clips")
|
83 |
+
},
|
84 |
+
),
|
85 |
+
]
|
86 |
+
|
87 |
+
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
88 |
+
def _generate_examples(self, filepath, path_to_clips):
|
89 |
+
print(path_to_clips)
|
90 |
+
import csv
|
91 |
+
# TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
|
92 |
+
# The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
|
93 |
+
with open(filepath, encoding="utf-8") as f:
|
94 |
+
reader = csv.DictReader(f, delimiter="\t")
|
95 |
+
for row in reader:
|
96 |
+
path = f'{path_to_clips}/{row["audio_filename"]}'
|
97 |
+
|
98 |
+
# Add the audio data
|
99 |
+
with open(path, "rb") as file:
|
100 |
+
row['audio'] = {
|
101 |
+
'path': path, 'bytes': file.read()
|
102 |
+
}
|
103 |
+
yield path, row
|