icsi_summ / icsi_summ.py
YuanPJ's picture
add loading script
5c004d8
# coding=utf-8
#
"""ICSI summary dataset."""
import json
import datasets
_CITATION = """\
"""
_DESCRIPTION = """\
"""
_HOMEPAGE = "https://groups.inf.ed.ac.uk/ami/icsi/"
_LICENSE = "CC BY 4.0"
_BASE_DATA_URL = "https://huggingface.co/datasets/yuanpj/icsi_summ/resolve/main/data/"
_SPLIT_URL = _BASE_DATA_URL + "{split}.json"
logger = datasets.utils.logging.get_logger(__name__)
class IcsisummConfig(datasets.BuilderConfig):
"""BuilderConfig for the summary subset of ICSI Corpus."""
def __init__(self, name, *args, **kwargs):
"""BuilderConfig for the summary subset of ICSI Corpus"""
super().__init__(name=name, *args, **kwargs)
class Icsisumm(datasets.GeneratorBasedBuilder):
"""ICSI summary dataset."""
VERSION = datasets.Version("1.0.0")
BUILDER_CONFIGS = [IcsisummConfig(name="icsi_summ")]
def _info(self):
features = datasets.Features(
{
"sample_id": datasets.Value("string"),
"dialogue": [
{
"id": datasets.Value("string"),
"speaker": datasets.Value("string"),
"starttime": datasets.Value("string"),
"startwordid": datasets.Value("string"),
"endtime": datasets.Value("string"),
"endwordid": datasets.Value("string"),
"text": datasets.Value("string"),
"label": datasets.Value("string"),
"original_label": datasets.Value("string"),
"attributes": datasets.Value("string"),
}
],
"summary": [
{
"id": datasets.Value("string"),
"text": datasets.Value("string"),
"type": datasets.Value("string"),
}
],
}
)
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=features,
supervised_keys=None,
homepage=_HOMEPAGE,
license=_LICENSE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
"""Returns SplitGenerators."""
split_urls = {}
for split in ["dev", "test"]:
split_urls[split] = _SPLIT_URL.format(split=split)
file_paths = dl_manager.download(split_urls)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"path": file_paths["dev"],
},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={
"path": file_paths["test"],
},
),
]
def _generate_examples(self, path):
"""Yields examples."""
data = json.load(open(path, "r", encoding="utf-8"))
for example in data:
yield example["sample_id"], example