Vladislav Sokolovskii commited on
Commit
e8c2ea0
·
1 Parent(s): 735128a

Load files are added, cleaning is needed

Browse files

Signed-off-by: Vladislav Sokolovskii <[email protected]>

slue-voxpopuli_dev.tsv DELETED
The diff for this file is too large to render. See raw diff
 
slue-voxpopuli_fine-tune.tsv DELETED
The diff for this file is too large to render. See raw diff
 
slue-voxpopuli_test_blind.tsv DELETED
The diff for this file is too large to render. See raw diff
 
voxceleb/voxceleb.py ADDED
@@ -0,0 +1,194 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # TODO: Address all TODOs and remove all explanatory comments
15
+ """TODO: Add a description here."""
16
+
17
+
18
+ import csv
19
+ import json
20
+ import os
21
+ import sys
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
+ _CITATION = """\
29
+ @InProceedings{huggingface:dataset,
30
+ title = {A great new dataset},
31
+ author={huggingface, Inc.
32
+ },
33
+ year={2020}
34
+ }
35
+ """
36
+
37
+ # TODO: Add description of the dataset here
38
+ # You can copy an official description
39
+ _DESCRIPTION = """\
40
+ This new dataset is designed to solve this great NLP task and is crafted with a lot of care.
41
+ """
42
+
43
+ # TODO: Add a link to an official homepage for the dataset here
44
+ _HOMEPAGE = ""
45
+
46
+ # TODO: Add the licence for the dataset here if you can find it
47
+ _LICENSE = ""
48
+
49
+ # TODO: Add link to the official dataset URLs here
50
+ # The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
51
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
52
+ _URLS = {
53
+ "voxceleb": "https://public-dataset-model-store.awsdev.asapp.com/users/sshon/public/slue/slue-voxceleb_v0.2_blind.zip"
54
+ }
55
+
56
+
57
+ # TODO: Name of the dataset usually matches the script name with CamelCase instead of snake_case
58
+ class SLUEVoxceleb(datasets.GeneratorBasedBuilder):
59
+ """TODO: Short description of my dataset."""
60
+
61
+ VERSION = datasets.Version("1.1.0")
62
+
63
+ # This is an example of a dataset with multiple configurations.
64
+ # If you don't want/need to define several sub-sets in your dataset,
65
+ # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
66
+
67
+ # If you need to make complex sub-parts in the datasets with configurable options
68
+ # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
69
+ # BUILDER_CONFIG_CLASS = MyBuilderConfig
70
+
71
+ # You will be able to load one or the other configurations in the following list with
72
+ # data = datasets.load_dataset('my_dataset', 'first_domain')
73
+ # data = datasets.load_dataset('my_dataset', 'second_domain')
74
+ BUILDER_CONFIGS = [
75
+ datasets.BuilderConfig(name="voxceleb", version=VERSION, description="This part of my dataset covers a first domain"),
76
+ ]
77
+
78
+ #DEFAULT_CONFIG_NAME = "first_domain" # It's not mandatory to have a default configuration. Just use one if it make sense.
79
+
80
+ def _info(self):
81
+ # TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
82
+ if self.config.name == "voxceleb": # This is the name of the configuration selected in BUILDER_CONFIGS above
83
+ # get the current split
84
+
85
+ features = datasets.Features(
86
+ {
87
+ "id": datasets.Value("string"),
88
+ "normalized_text": datasets.Value("string"),
89
+ "speaker_id": datasets.Value("int32"),
90
+ "split": datasets.Value("string"),
91
+ "sentiment": datasets.Value("string"),
92
+ "start_second": datasets.Value("float32"),
93
+ "end_second": datasets.Value("float32"),
94
+ "audio_path": datasets.Value("string"),
95
+ }
96
+ )
97
+
98
+ return datasets.DatasetInfo(
99
+ # This is the description that will appear on the datasets page.
100
+ description=_DESCRIPTION,
101
+ # This defines the different columns of the dataset and their types
102
+ features=features, # Here we define them above because they are different between the two configurations
103
+ # If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
104
+ # specify them. They'll be used if as_supervised=True in builder.as_dataset.
105
+ # supervised_keys=("sentence", "label"),
106
+ # Homepage of the dataset for documentation
107
+ homepage=_HOMEPAGE,
108
+ # License for the dataset if available
109
+ license=_LICENSE,
110
+ # Citation for the dataset
111
+ citation=_CITATION,
112
+ )
113
+
114
+ def _split_generators(self, dl_manager):
115
+ # TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
116
+ # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
117
+
118
+ # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
119
+ # 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.
120
+ # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
121
+ urls = _URLS[self.config.name]
122
+ data_dir = dl_manager.download_and_extract(urls)
123
+
124
+
125
+ return [
126
+ datasets.SplitGenerator(
127
+ name=datasets.Split.TRAIN,
128
+ # These kwargs will be passed to _generate_examples
129
+ gen_kwargs={
130
+ "filepath": os.path.join(data_dir, "slue-voxceleb", "slue-voxceleb_fine-tune.tsv"),
131
+ "split": "fine-tune",
132
+ "audio_dir": os.path.join(data_dir, "slue-voxceleb", "fine-tune_raw"),
133
+ },
134
+ ),
135
+ datasets.SplitGenerator(
136
+ name=datasets.Split.VALIDATION,
137
+ # These kwargs will be passed to _generate_examples
138
+ gen_kwargs={
139
+ "filepath": os.path.join(data_dir, "slue-voxceleb", "slue-voxceleb_dev.tsv"),
140
+ "split": "dev",
141
+ "audio_dir": os.path.join(data_dir, "slue-voxceleb", "dev_raw"),
142
+ },
143
+ ),
144
+ datasets.SplitGenerator(
145
+ name=datasets.Split.TEST,
146
+ # These kwargs will be passed to _generate_examples
147
+ gen_kwargs={
148
+ "filepath": os.path.join(data_dir, "slue-voxceleb", "slue-voxceleb_test_blind.tsv"),
149
+ "split": "test-blind",
150
+ "audio_dir": os.path.join(data_dir, "slue-voxceleb", "test_raw"),
151
+ },
152
+ ),
153
+ ]
154
+
155
+
156
+ # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
157
+ def _generate_examples(self, filepath, split, audio_dir):
158
+ # read tsv file by rows
159
+ with open(filepath, encoding="utf-8") as f:
160
+ reader = csv.DictReader(f, delimiter="\t", quoting=csv.QUOTE_NONE)
161
+ with open("debug.txt", "w") as f1:
162
+ f1.write(str(split) + '\n')
163
+ for row in reader:
164
+ f1.write(str(row))
165
+ speaker_id = row["speaker_id"]
166
+ if not speaker_id.isdigit():
167
+ speaker_id = -1
168
+ else:
169
+ speaker_id = int(speaker_id)
170
+
171
+ audio_file = f"{row['id']}.flac"
172
+ if split == "test-blind":
173
+ yield row["id"], {
174
+ "id": row["id"],
175
+ "normalized_text": None,
176
+ "speaker_id": speaker_id,
177
+ "split": split,
178
+ "sentiment": None,
179
+ "start_second": float(row["start_second"]),
180
+ "end_second": float(row["end_second"]),
181
+ "audio_path": os.path.join(audio_dir, audio_file),
182
+ }
183
+ elif split == "fine-tune" or split == "dev":
184
+ yield row["id"], {
185
+ "id": row["id"],
186
+ "normalized_text": row["normalized_text"],
187
+ "speaker_id": speaker_id,
188
+ "split": split,
189
+ "sentiment": row["sentiment"],
190
+ "start_second": float(row["start_second"]),
191
+ "end_second": float(row["end_second"]),
192
+ "audio_path": os.path.join(audio_dir, audio_file),
193
+ }
194
+
voxpopuli/voxpopuli.py ADDED
@@ -0,0 +1,194 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # TODO: Address all TODOs and remove all explanatory comments
15
+ """TODO: Add a description here."""
16
+
17
+
18
+ import csv
19
+ import json
20
+ import os
21
+ import sys
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
+ _CITATION = """\
29
+ @InProceedings{huggingface:dataset,
30
+ title = {A great new dataset},
31
+ author={huggingface, Inc.
32
+ },
33
+ year={2020}
34
+ }
35
+ """
36
+
37
+ # TODO: Add description of the dataset here
38
+ # You can copy an official description
39
+ _DESCRIPTION = """\
40
+ This new dataset is designed to solve this great NLP task and is crafted with a lot of care.
41
+ """
42
+
43
+ # TODO: Add a link to an official homepage for the dataset here
44
+ _HOMEPAGE = ""
45
+
46
+ # TODO: Add the licence for the dataset here if you can find it
47
+ _LICENSE = ""
48
+
49
+ # TODO: Add link to the official dataset URLs here
50
+ # The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
51
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
52
+ _URLS = {
53
+ "voxpopuli": "https://public-dataset-model-store.awsdev.asapp.com/users/sshon/public/slue/slue-voxpopuli_v0.2_blind.zip"
54
+ }
55
+
56
+
57
+ # TODO: Name of the dataset usually matches the script name with CamelCase instead of snake_case
58
+ class SLUEVoxpopuli(datasets.GeneratorBasedBuilder):
59
+ """TODO: Short description of my dataset."""
60
+
61
+ VERSION = datasets.Version("1.1.0")
62
+
63
+ # This is an example of a dataset with multiple configurations.
64
+ # If you don't want/need to define several sub-sets in your dataset,
65
+ # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
66
+
67
+ # If you need to make complex sub-parts in the datasets with configurable options
68
+ # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
69
+ # BUILDER_CONFIG_CLASS = MyBuilderConfig
70
+
71
+ # You will be able to load one or the other configurations in the following list with
72
+ # data = datasets.load_dataset('my_dataset', 'first_domain')
73
+ # data = datasets.load_dataset('my_dataset', 'second_domain')
74
+ BUILDER_CONFIGS = [
75
+ datasets.BuilderConfig(name="voxpopuli", version=VERSION, description="This part of my dataset covers a first domain"),
76
+ ]
77
+
78
+ #DEFAULT_CONFIG_NAME = "first_domain" # It's not mandatory to have a default configuration. Just use one if it make sense.
79
+
80
+ def _info(self):
81
+ # TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
82
+ if self.config.name == "voxpopuli": # This is the name of the configuration selected in BUILDER_CONFIGS above
83
+ # get the current split
84
+
85
+ features = datasets.Features(
86
+ {
87
+ "id": datasets.Value("string"),
88
+ "raw_text": datasets.Value("string"),
89
+ "normalized_text": datasets.Value("string"),
90
+ "speaker_id": datasets.Value("int32"),
91
+ "split": datasets.Value("string"),
92
+ "raw_ner": datasets.Value("string"),
93
+ "normalized_ner": datasets.Value("string"),
94
+ "audio_path": datasets.Value("string"),
95
+ }
96
+ )
97
+
98
+ return datasets.DatasetInfo(
99
+ # This is the description that will appear on the datasets page.
100
+ description=_DESCRIPTION,
101
+ # This defines the different columns of the dataset and their types
102
+ features=features, # Here we define them above because they are different between the two configurations
103
+ # If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
104
+ # specify them. They'll be used if as_supervised=True in builder.as_dataset.
105
+ # supervised_keys=("sentence", "label"),
106
+ # Homepage of the dataset for documentation
107
+ homepage=_HOMEPAGE,
108
+ # License for the dataset if available
109
+ license=_LICENSE,
110
+ # Citation for the dataset
111
+ citation=_CITATION,
112
+ )
113
+
114
+ def _split_generators(self, dl_manager):
115
+ # TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
116
+ # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
117
+
118
+ # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
119
+ # 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.
120
+ # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
121
+ urls = _URLS[self.config.name]
122
+ data_dir = dl_manager.download_and_extract(urls)
123
+
124
+
125
+ return [
126
+ datasets.SplitGenerator(
127
+ name=datasets.Split.TRAIN,
128
+ # These kwargs will be passed to _generate_examples
129
+ gen_kwargs={
130
+ "filepath": os.path.join(data_dir, "slue-voxpopuli", "slue-voxpopuli_fine-tune.tsv"),
131
+ "split": "fine-tune",
132
+ "audio_dir": os.path.join(data_dir, "slue-voxpopuli", "fine-tune"),
133
+ },
134
+ ),
135
+ datasets.SplitGenerator(
136
+ name=datasets.Split.VALIDATION,
137
+ # These kwargs will be passed to _generate_examples
138
+ gen_kwargs={
139
+ "filepath": os.path.join(data_dir, "slue-voxpopuli", "slue-voxpopuli_dev.tsv"),
140
+ "split": "dev",
141
+ "audio_dir": os.path.join(data_dir, "slue-voxpopuli", "dev"),
142
+ },
143
+ ),
144
+ datasets.SplitGenerator(
145
+ name=datasets.Split.TEST,
146
+ # These kwargs will be passed to _generate_examples
147
+ gen_kwargs={
148
+ "filepath": os.path.join(data_dir, "slue-voxpopuli", "slue-voxpopuli_test_blind.tsv"),
149
+ "split": "test-blind",
150
+ "audio_dir": os.path.join(data_dir, "slue-voxpopuli", "test"),
151
+ },
152
+ ),
153
+ ]
154
+
155
+
156
+ # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
157
+ def _generate_examples(self, filepath, split, audio_dir):
158
+ # read tsv file by rows
159
+ with open(filepath, encoding="utf-8") as f:
160
+ reader = csv.DictReader(f, delimiter="\t", quoting=csv.QUOTE_NONE)
161
+ with open("debug.txt", "w") as f1:
162
+ f1.write(str(split) + '\n')
163
+ for row in reader:
164
+ f1.write(str(row))
165
+ speaker_id = row["speaker_id"]
166
+ if not speaker_id.isdigit():
167
+ speaker_id = -1
168
+ else:
169
+ speaker_id = int(speaker_id)
170
+
171
+ audio_file = f"{row['id']}.ogg"
172
+ if split == "test-blind":
173
+ yield row["id"], {
174
+ "id": row["id"],
175
+ "raw_text": row["raw_text"],
176
+ "normalized_text": row["normalized_text"],
177
+ "speaker_id": speaker_id,
178
+ "split": split,
179
+ "audio_path": os.path.join(audio_dir, audio_file),
180
+ "raw_ner": None,
181
+ "normalized_ner": None
182
+ }
183
+ elif split == "fine-tune" or split == "dev":
184
+ yield row["id"], {
185
+ "id": row["id"],
186
+ "raw_text": row["raw_text"],
187
+ "normalized_text": row["normalized_text"],
188
+ "speaker_id": speaker_id,
189
+ "split": split,
190
+ "raw_ner": row["raw_ner"],
191
+ "normalized_ner": row["normalized_ner"],
192
+ "audio_path": os.path.join(audio_dir, audio_file),
193
+ }
194
+