Nikita Pavlichenko commited on
Commit
9c87086
1 Parent(s): 3751f8f

First version of CrowdSpeech

Browse files
Files changed (1) hide show
  1. CrowdSpeech.py +114 -0
CrowdSpeech.py ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2021 YANDEX LLC.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ # Lint as: python3
17
+ """CrowdSpeech: Benchmark Dataset for Crowdsourced Audio Transcription."""
18
+
19
+
20
+ import json
21
+
22
+ import datasets
23
+ from datasets.tasks import Summarization
24
+
25
+
26
+ logger = datasets.logging.get_logger(__name__)
27
+
28
+ _DESCRIPTION = """\
29
+ CrowdSpeech is a publicly available large-scale dataset of crowdsourced audio transcriptions. \
30
+ It contains annotations for more than 50 hours of English speech transcriptions from more \
31
+ than 1,000 crowd workers.
32
+ """
33
+
34
+ _URL = "https://raw.githubusercontent.com/pilot7747/VoxDIY/main/data/huggingface/"
35
+ _URLS = {
36
+ "train-clean": _URL + "train-clean.json",
37
+ "dev-clean": _URL + "dev-clean.json",
38
+ "dev-other": _URL + "dev-other.json",
39
+ "test-clean": _URL + "test-clean.json",
40
+ "test-other": _URL + "test-other.json",
41
+ }
42
+
43
+
44
+ class CrowdSpeechConfig(datasets.BuilderConfig):
45
+ """BuilderConfig for CrowdSpeech."""
46
+
47
+ def __init__(self, **kwargs):
48
+ """BuilderConfig for CrowdSpeech.
49
+
50
+ Args:
51
+ **kwargs: keyword arguments forwarded to super.
52
+ """
53
+ super(CrowdSpeechConfig, self).__init__(**kwargs)
54
+
55
+
56
+ class CrowdSpeech(datasets.GeneratorBasedBuilder):
57
+ """CrowdSpeech: Benchmark Dataset for Crowdsourced Audio Transcription."""
58
+
59
+ BUILDER_CONFIGS = [
60
+ CrowdSpeechConfig(
61
+ name="plain_text",
62
+ version=datasets.Version("1.0.0", ""),
63
+ description="Plain text",
64
+ ),
65
+ ]
66
+
67
+ def _info(self):
68
+ return datasets.DatasetInfo(
69
+ description=_DESCRIPTION,
70
+ features=datasets.Features(
71
+ {
72
+ "task": datasets.Value("string"),
73
+ "transcriptions": datasets.Value("string"),
74
+ "performers": datasets.Value("string"),
75
+ "gt": datasets.Value("string"),
76
+ }
77
+ ),
78
+ supervised_keys=None,
79
+ homepage="https://github.com/pilot7747/VoxDIY/",
80
+ # citation=_CITATION,
81
+ task_templates=[
82
+ Summarization(
83
+ text_column="transcriptions", summary_column="gt"
84
+ )
85
+ ],
86
+ )
87
+
88
+ def _split_generators(self, dl_manager):
89
+ downloaded_files = dl_manager.download_and_extract(_URLS)
90
+
91
+ return [
92
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train-clean"]}),
93
+ datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test-clean"]}),
94
+ datasets.SplitGenerator(name='test-other', gen_kwargs={"filepath": downloaded_files["test-other"]}),
95
+ datasets.SplitGenerator(name='dev-clean', gen_kwargs={"filepath": downloaded_files["dev-clean"]}),
96
+ datasets.SplitGenerator(name='dev-other', gen_kwargs={"filepath": downloaded_files["dev-clean"]}),
97
+ ]
98
+
99
+ def _generate_examples(self, filepath):
100
+ """This function returns the examples in the raw (text) form."""
101
+ logger.info("generating examples from = %s", filepath)
102
+ with open(filepath, encoding="utf-8") as f:
103
+ crowdspeech = json.load(f)
104
+ for audio in crowdspeech["data"]:
105
+ task = audio.get("task", "")
106
+ transcriptions = audio.get("transcriptions", "")
107
+ performers = audio.get("performers", "")
108
+ gt = audio.get("gt", "")
109
+
110
+ yield task, {
111
+ "transcriptions": transcriptions,
112
+ "performers": performers,
113
+ "gt": gt,
114
+ }