|
from typing import List |
|
import os |
|
import csv |
|
import ast |
|
import gzip |
|
|
|
import datasets |
|
from datasets.utils.logging import get_logger |
|
|
|
logger = get_logger(__name__) |
|
|
|
_URL = "https://asappresearch.github.io/slue-toolkit/" |
|
|
|
_DL_URLS = { |
|
"slue-hvb": "data/slue-hvb_blind.zip", |
|
} |
|
|
|
_LICENSE = """ |
|
======================================================= |
|
The license of this script |
|
MIT License |
|
Copyright (c) 2023 ASAPP Inc. |
|
Permission is hereby granted, free of charge, to any person obtaining a copy |
|
of this software and associated documentation files (the "Software"), to deal |
|
in the Software without restriction, including without limitation the rights |
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
copies of the Software, and to permit persons to whom the Software is |
|
furnished to do so, subject to the following conditions: |
|
The above copyright notice and this permission notice shall be included in all |
|
copies or substantial portions of the Software. |
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|
SOFTWARE. |
|
======================================================= |
|
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) |
|
|
|
Additionally, we provide dialog act classification annotation and it is covered with the same license as CC-BY-4.0. |
|
======================================================= |
|
|
|
""" |
|
|
|
_CITATION = """\ |
|
@inproceedings{shon2023slue_phase2, |
|
title={SLUE Phase-2: A Benchmark Suite of Diverse Spoken Language Understanding Tasks}, |
|
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}, |
|
booktitle={ACL}, |
|
year={2023}, |
|
} |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
Spoken Language Understanding Evaluation (SLUE) benchmark Phase 2. |
|
""" |
|
|
|
class SLUE2Config(datasets.BuilderConfig): |
|
"""BuilderConfig for SLUE.""" |
|
|
|
def __init__(self, **kwargs): |
|
""" |
|
Args: |
|
data_dir: `string`, the path to the folder containing the files in the |
|
downloaded .tar |
|
citation: `string`, citation for the data set |
|
url: `string`, url for information about the data set |
|
**kwargs: keyword arguments forwarded to super. |
|
""" |
|
super(SLUE2Config, self).__init__( |
|
version=datasets.Version("2.4.0", ""), **kwargs |
|
) |
|
|
|
|
|
class SLUE2(datasets.GeneratorBasedBuilder): |
|
"""Librispeech dataset.""" |
|
|
|
DEFAULT_WRITER_BATCH_SIZE = 256 |
|
DEFAULT_CONFIG_NAME = "hvb" |
|
BUILDER_CONFIGS = [ |
|
SLUE2Config( |
|
name="hvb", |
|
description="SLUE-HVB set.", |
|
), |
|
] |
|
|
|
def _info(self): |
|
if self.config.name == "hvb": |
|
features = { |
|
"issue_id": datasets.Value("string"), |
|
"audio": datasets.Audio(sampling_rate=16_000), |
|
"speaker_id": datasets.Value("string"), |
|
"text": datasets.Value("string"), |
|
"utt_index": datasets.Value("int32"), |
|
"channel": datasets.Value("int32"), |
|
"role": datasets.Value("string"), |
|
"start_ms": datasets.Value("int32"), |
|
"duration_ms": datasets.Value("int32"), |
|
"intent": datasets.Value("string"), |
|
"dialog_acts": datasets.Sequence( |
|
datasets.Value("string"), |
|
), |
|
} |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=datasets.Features(features), |
|
supervised_keys=("file", "text"), |
|
homepage=_URL, |
|
citation=_CITATION, |
|
license=_LICENSE, |
|
) |
|
|
|
def _split_generators( |
|
self, dl_manager: datasets.DownloadManager |
|
) -> List[datasets.SplitGenerator]: |
|
|
|
config_name = f"slue-{self.config.name}" |
|
|
|
dl_dir = dl_manager.download_and_extract(_DL_URLS[config_name]) |
|
data_dir = os.path.join(dl_dir, config_name) |
|
print(data_dir) |
|
|
|
splits = [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs={ |
|
"filepath": os.path.join( |
|
data_dir or "", f"{config_name}_fine-tune.tsv" |
|
), |
|
"data_dir": data_dir, |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.VALIDATION, |
|
gen_kwargs={ |
|
"filepath": os.path.join(data_dir or "", f"{config_name}_dev.tsv"), |
|
"data_dir": data_dir, |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
gen_kwargs={ |
|
"filepath": os.path.join( |
|
data_dir or "", f"{config_name}_test_blind.tsv" |
|
), |
|
"data_dir": data_dir, |
|
}, |
|
), |
|
] |
|
return splits |
|
|
|
def _generate_examples(self, filepath, data_dir): |
|
logger.info(f"generating examples from = {filepath}") |
|
|
|
with open(filepath) as f: |
|
reader = csv.DictReader(f, delimiter="\t") |
|
|
|
for idx, row in enumerate(reader): |
|
if self.config.name == "hvb": |
|
split = "test" if "test" in filepath else "dev" if "dev" in filepath else "fine-tune" |
|
audio_file = os.path.join( |
|
data_dir, split, |
|
f'{row["issue_id"]}_{row["start_ms"]}_{int(row["start_ms"]) + int(row["duration_ms"])}.wav' |
|
) |
|
example = { |
|
"issue_id": row["issue_id"], |
|
"audio": audio_file, |
|
"speaker_id": row["speaker_id"], |
|
"text": row["text"], |
|
"utt_index": int(row["utt_index"]), |
|
"channel": int(row["channel"]), |
|
"role": row["role"], |
|
"start_ms": int(row["start_ms"]), |
|
"duration_ms": int(row["duration_ms"]), |
|
"intent": row["intent"], |
|
"dialog_acts": eval(row.get("dialog_acts", "[]")), |
|
} |
|
yield idx, example |