File size: 3,100 Bytes
5c004d8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# 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