add loading script
Browse files- slue-phase-2.py +180 -0
slue-phase-2.py
ADDED
@@ -0,0 +1,180 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import List
|
2 |
+
import os
|
3 |
+
import csv
|
4 |
+
import ast
|
5 |
+
import gzip
|
6 |
+
|
7 |
+
import datasets
|
8 |
+
from datasets.utils.logging import get_logger
|
9 |
+
|
10 |
+
logger = get_logger(__name__)
|
11 |
+
|
12 |
+
_URL = "https://asappresearch.github.io/slue-toolkit/"
|
13 |
+
|
14 |
+
_DL_URLS = {
|
15 |
+
"slue-hvb": "data/slue-hvb_blind.zip",
|
16 |
+
}
|
17 |
+
|
18 |
+
_LICENSE = """
|
19 |
+
=======================================================
|
20 |
+
The license of this script
|
21 |
+
MIT License
|
22 |
+
Copyright (c) 2023 ASAPP Inc.
|
23 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
24 |
+
of this software and associated documentation files (the "Software"), to deal
|
25 |
+
in the Software without restriction, including without limitation the rights
|
26 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
27 |
+
copies of the Software, and to permit persons to whom the Software is
|
28 |
+
furnished to do so, subject to the following conditions:
|
29 |
+
The above copyright notice and this permission notice shall be included in all
|
30 |
+
copies or substantial portions of the Software.
|
31 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
32 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
33 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
34 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
35 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
36 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
37 |
+
SOFTWARE.
|
38 |
+
=======================================================
|
39 |
+
SLUE-HVB dataset contains a subset of the Gridspace-Stanford Harper Valley speech dataset and the copyright of this subset remains the same with the original license, CC-BY-4.0. See also original license notice (https://github.com/cricketclub/gridspace-stanford-harper-valley/blob/master/LICENSE)
|
40 |
+
|
41 |
+
Additionally, we provide dialog act classification annotation and it is covered with the same license as CC-BY-4.0.
|
42 |
+
=======================================================
|
43 |
+
|
44 |
+
"""
|
45 |
+
|
46 |
+
_CITATION = """\
|
47 |
+
@inproceedings{shon2023slue_phase2,
|
48 |
+
title={SLUE Phase-2: A Benchmark Suite of Diverse Spoken Language Understanding Tasks},
|
49 |
+
author={Shon, Suwon and Arora, Siddhant and Lin, Chyi-Jiunn and Pasad, Ankita and Wu, Felix and Sharma, Roshan and Wu, Wei-Lun and Lee, Hung-Yi and Livescu, Karen and Watanabe, Shinji},
|
50 |
+
booktitle={ACL},
|
51 |
+
year={2023},
|
52 |
+
}
|
53 |
+
"""
|
54 |
+
|
55 |
+
_DESCRIPTION = """\
|
56 |
+
Spoken Language Understanding Evaluation (SLUE) benchmark Phase 2.
|
57 |
+
"""
|
58 |
+
|
59 |
+
class SLUE2Config(datasets.BuilderConfig):
|
60 |
+
"""BuilderConfig for SLUE."""
|
61 |
+
|
62 |
+
def __init__(self, **kwargs):
|
63 |
+
"""
|
64 |
+
Args:
|
65 |
+
data_dir: `string`, the path to the folder containing the files in the
|
66 |
+
downloaded .tar
|
67 |
+
citation: `string`, citation for the data set
|
68 |
+
url: `string`, url for information about the data set
|
69 |
+
**kwargs: keyword arguments forwarded to super.
|
70 |
+
"""
|
71 |
+
super(SLUE2Config, self).__init__(
|
72 |
+
version=datasets.Version("2.4.0", ""), **kwargs
|
73 |
+
)
|
74 |
+
|
75 |
+
|
76 |
+
class SLUE2(datasets.GeneratorBasedBuilder):
|
77 |
+
"""Librispeech dataset."""
|
78 |
+
|
79 |
+
DEFAULT_WRITER_BATCH_SIZE = 256
|
80 |
+
DEFAULT_CONFIG_NAME = "hvb"
|
81 |
+
BUILDER_CONFIGS = [
|
82 |
+
SLUE2Config(
|
83 |
+
name="hvb",
|
84 |
+
description="SLUE-HVB set.",
|
85 |
+
),
|
86 |
+
]
|
87 |
+
|
88 |
+
def _info(self):
|
89 |
+
if self.config.name == "hvb":
|
90 |
+
features = {
|
91 |
+
"id": datasets.Value("string"),
|
92 |
+
"audio": datasets.Audio(sampling_rate=16_000),
|
93 |
+
"speaker_id": datasets.Value("string"),
|
94 |
+
"text": datasets.Value("string"),
|
95 |
+
"utt_index": datasets.Value("int32"),
|
96 |
+
"channel": datasets.Value("int32"),
|
97 |
+
"role": datasets.Value("string"),
|
98 |
+
"start_ms": datasets.Value("float64"),
|
99 |
+
"duration_ms": datasets.Value("float64"),
|
100 |
+
"intent": datasets.Value("string"),
|
101 |
+
"dialog_acts": datasets.Sequence(
|
102 |
+
{
|
103 |
+
"type": datasets.Value("string"),
|
104 |
+
}
|
105 |
+
),
|
106 |
+
}
|
107 |
+
return datasets.DatasetInfo(
|
108 |
+
description=_DESCRIPTION,
|
109 |
+
features=datasets.Features(features),
|
110 |
+
supervised_keys=("file", "text"),
|
111 |
+
homepage=_URL,
|
112 |
+
citation=_CITATION,
|
113 |
+
license=_LICENSE,
|
114 |
+
)
|
115 |
+
|
116 |
+
def _split_generators(
|
117 |
+
self, dl_manager: datasets.DownloadManager
|
118 |
+
) -> List[datasets.SplitGenerator]:
|
119 |
+
|
120 |
+
config_name = f"slue-{self.config.name}"
|
121 |
+
|
122 |
+
dl_dir = dl_manager.download_and_extract(_DL_URLS[config_name])
|
123 |
+
data_dir = os.path.join(dl_dir, config_name)
|
124 |
+
print(data_dir)
|
125 |
+
|
126 |
+
splits = [
|
127 |
+
datasets.SplitGenerator(
|
128 |
+
name=datasets.Split.TRAIN,
|
129 |
+
gen_kwargs={
|
130 |
+
"filepath": os.path.join(
|
131 |
+
data_dir or "", f"{config_name}_fine-tune.tsv"
|
132 |
+
),
|
133 |
+
"data_dir": data_dir,
|
134 |
+
},
|
135 |
+
),
|
136 |
+
datasets.SplitGenerator(
|
137 |
+
name=datasets.Split.VALIDATION,
|
138 |
+
gen_kwargs={
|
139 |
+
"filepath": os.path.join(data_dir or "", f"{config_name}_dev.tsv"),
|
140 |
+
"data_dir": data_dir,
|
141 |
+
},
|
142 |
+
),
|
143 |
+
datasets.SplitGenerator(
|
144 |
+
name=datasets.Split.TEST,
|
145 |
+
gen_kwargs={
|
146 |
+
"filepath": os.path.join(
|
147 |
+
data_dir or "", f"{config_name}_test_blind.tsv"
|
148 |
+
),
|
149 |
+
"data_dir": data_dir,
|
150 |
+
},
|
151 |
+
),
|
152 |
+
]
|
153 |
+
return splits
|
154 |
+
|
155 |
+
def _generate_examples(self, filepath, data_dir):
|
156 |
+
logger.info(f"generating examples from = {filepath}")
|
157 |
+
|
158 |
+
with open(filepath) as f:
|
159 |
+
reader = csv.DictReader(f, delimiter="\t")
|
160 |
+
|
161 |
+
for idx, row in enumerate(reader):
|
162 |
+
if self.config.name == "hvb":
|
163 |
+
audio_file = os.path.join(
|
164 |
+
data_dir, "slue-hvb", row["split"],
|
165 |
+
f'{row["id"]}_{row["start_ms"]}_{row["start_ms"] + row["duration_ms"]}.wav'
|
166 |
+
)
|
167 |
+
example = {
|
168 |
+
"id": row["id"],
|
169 |
+
"audio": audio_file,
|
170 |
+
"speaker_id": row["speaker_id"],
|
171 |
+
"text": row["text"],
|
172 |
+
"utt_index": row["utt_index"],
|
173 |
+
"channel": row["channel"],
|
174 |
+
"role": row["role"],
|
175 |
+
"start_ms": row["start_ms"],
|
176 |
+
"duration_ms": row["duration_ms"],
|
177 |
+
"intent": row["intent"],
|
178 |
+
"dialog_acts": row["dialog_acts"],
|
179 |
+
}
|
180 |
+
yield idx, example
|