Datasets:
remove draft data loader script
Browse files- nb_samtale.py +0 -165
nb_samtale.py
DELETED
@@ -1,165 +0,0 @@
|
|
1 |
-
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
|
2 |
-
#
|
3 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
-
# you may not use this file except in compliance with the License.
|
5 |
-
# You may obtain a copy of the License at
|
6 |
-
#
|
7 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8 |
-
#
|
9 |
-
# Unless required by applicable law or agreed to in writing, software
|
10 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
-
# See the License for the specific language governing permissions and
|
13 |
-
# limitations under the License.
|
14 |
-
|
15 |
-
# Lint as: python3
|
16 |
-
"""NB Samtale: Norwegian conversation speech corpus"""
|
17 |
-
|
18 |
-
|
19 |
-
import csv
|
20 |
-
import json
|
21 |
-
import os
|
22 |
-
|
23 |
-
import datasets
|
24 |
-
|
25 |
-
|
26 |
-
# TODO: Add BibTeX citation
|
27 |
-
# Find for instance the citation on arxiv or on the dataset repo/website
|
28 |
-
|
29 |
-
|
30 |
-
_DESCRIPTION = """\
|
31 |
-
NB Samtale is a speech corpus made by the Language Bank at the National Library of Norway.
|
32 |
-
The corpus contains orthographically transcribed speech from podcasts and recordings of live events at the National Library.
|
33 |
-
The corpus is intended as an open source dataset for Automatic Speech Recognition (ASR) development,
|
34 |
-
and is specifically aimed at improving ASR systems’ handle on conversational speech.
|
35 |
-
"""
|
36 |
-
|
37 |
-
_HOMEPAGE = "https://www.nb.no/sprakbanken/en/resource-catalogue/oai-nb-no-sbr-85/"
|
38 |
-
|
39 |
-
_LICENSE = "CC-ZERO-license"
|
40 |
-
|
41 |
-
# TODO: Add link to the official dataset URLs here
|
42 |
-
# The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
|
43 |
-
# This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
|
44 |
-
_URLS = {
|
45 |
-
"first_domain": "https://huggingface.co/great-new-dataset-first_domain.zip",
|
46 |
-
"second_domain": "https://huggingface.co/great-new-dataset-second_domain.zip",
|
47 |
-
}
|
48 |
-
|
49 |
-
|
50 |
-
# TODO: Name of the dataset usually matches the script name with CamelCase instead of snake_case
|
51 |
-
class NewDataset(datasets.GeneratorBasedBuilder):
|
52 |
-
"""TODO: Short description of my dataset."""
|
53 |
-
|
54 |
-
VERSION = datasets.Version("1.1.0")
|
55 |
-
|
56 |
-
# This is an example of a dataset with multiple configurations.
|
57 |
-
# If you don't want/need to define several sub-sets in your dataset,
|
58 |
-
# just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
|
59 |
-
|
60 |
-
# If you need to make complex sub-parts in the datasets with configurable options
|
61 |
-
# You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
|
62 |
-
# BUILDER_CONFIG_CLASS = MyBuilderConfig
|
63 |
-
|
64 |
-
# You will be able to load one or the other configurations in the following list with
|
65 |
-
# data = datasets.load_dataset('my_dataset', 'first_domain')
|
66 |
-
# data = datasets.load_dataset('my_dataset', 'second_domain')
|
67 |
-
BUILDER_CONFIGS = [
|
68 |
-
datasets.BuilderConfig(name="first_domain", version=VERSION, description="This part of my dataset covers a first domain"),
|
69 |
-
datasets.BuilderConfig(name="second_domain", version=VERSION, description="This part of my dataset covers a second domain"),
|
70 |
-
]
|
71 |
-
|
72 |
-
DEFAULT_CONFIG_NAME = "first_domain" # It's not mandatory to have a default configuration. Just use one if it make sense.
|
73 |
-
|
74 |
-
def _info(self):
|
75 |
-
# TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
|
76 |
-
if self.config.name == "first_domain": # This is the name of the configuration selected in BUILDER_CONFIGS above
|
77 |
-
features = datasets.Features(
|
78 |
-
{
|
79 |
-
"sentence": datasets.Value("string"),
|
80 |
-
"option1": datasets.Value("string"),
|
81 |
-
"answer": datasets.Value("string")
|
82 |
-
# These are the features of your dataset like images, labels ...
|
83 |
-
}
|
84 |
-
)
|
85 |
-
else: # This is an example to show how to have different features for "first_domain" and "second_domain"
|
86 |
-
features = datasets.Features(
|
87 |
-
{
|
88 |
-
"sentence": datasets.Value("string"),
|
89 |
-
"option2": datasets.Value("string"),
|
90 |
-
"second_domain_answer": datasets.Value("string")
|
91 |
-
# These are the features of your dataset like images, labels ...
|
92 |
-
}
|
93 |
-
)
|
94 |
-
return datasets.DatasetInfo(
|
95 |
-
# This is the description that will appear on the datasets page.
|
96 |
-
description=_DESCRIPTION,
|
97 |
-
# This defines the different columns of the dataset and their types
|
98 |
-
features=features, # Here we define them above because they are different between the two configurations
|
99 |
-
# If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
|
100 |
-
# specify them. They'll be used if as_supervised=True in builder.as_dataset.
|
101 |
-
# supervised_keys=("sentence", "label"),
|
102 |
-
# Homepage of the dataset for documentation
|
103 |
-
homepage=_HOMEPAGE,
|
104 |
-
# License for the dataset if available
|
105 |
-
license=_LICENSE,
|
106 |
-
# Citation for the dataset
|
107 |
-
citation=_CITATION,
|
108 |
-
)
|
109 |
-
|
110 |
-
def _split_generators(self, dl_manager):
|
111 |
-
# TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
|
112 |
-
# If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
|
113 |
-
|
114 |
-
# dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
|
115 |
-
# It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
|
116 |
-
# By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
|
117 |
-
urls = _URLS[self.config.name]
|
118 |
-
data_dir = dl_manager.download_and_extract(urls)
|
119 |
-
return [
|
120 |
-
datasets.SplitGenerator(
|
121 |
-
name=datasets.Split.TRAIN,
|
122 |
-
# These kwargs will be passed to _generate_examples
|
123 |
-
gen_kwargs={
|
124 |
-
"filepath": os.path.join(data_dir, "train.jsonl"),
|
125 |
-
"split": "train",
|
126 |
-
},
|
127 |
-
),
|
128 |
-
datasets.SplitGenerator(
|
129 |
-
name=datasets.Split.VALIDATION,
|
130 |
-
# These kwargs will be passed to _generate_examples
|
131 |
-
gen_kwargs={
|
132 |
-
"filepath": os.path.join(data_dir, "dev.jsonl"),
|
133 |
-
"split": "dev",
|
134 |
-
},
|
135 |
-
),
|
136 |
-
datasets.SplitGenerator(
|
137 |
-
name=datasets.Split.TEST,
|
138 |
-
# These kwargs will be passed to _generate_examples
|
139 |
-
gen_kwargs={
|
140 |
-
"filepath": os.path.join(data_dir, "test.jsonl"),
|
141 |
-
"split": "test"
|
142 |
-
},
|
143 |
-
),
|
144 |
-
]
|
145 |
-
|
146 |
-
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
147 |
-
def _generate_examples(self, filepath, split):
|
148 |
-
# TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
|
149 |
-
# The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
|
150 |
-
with open(filepath, encoding="utf-8") as f:
|
151 |
-
for key, row in enumerate(f):
|
152 |
-
data = json.loads(row)
|
153 |
-
if self.config.name == "first_domain":
|
154 |
-
# Yields examples as (key, example) tuples
|
155 |
-
yield key, {
|
156 |
-
"sentence": data["sentence"],
|
157 |
-
"option1": data["option1"],
|
158 |
-
"answer": "" if split == "test" else data["answer"],
|
159 |
-
}
|
160 |
-
else:
|
161 |
-
yield key, {
|
162 |
-
"sentence": data["sentence"],
|
163 |
-
"option2": data["option2"],
|
164 |
-
"second_domain_answer": "" if split == "test" else data["second_domain_answer"],
|
165 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|