Datasets:
Commit
·
ffc3097
1
Parent(s):
7f3de98
Upload super_dialseg.py
Browse files- super_dialseg.py +108 -0
super_dialseg.py
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
|
| 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 |
+
"""SuperDialseg: A Large-scale Dataset for Supervised Dialogue Segmentation"""
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
import json
|
| 19 |
+
|
| 20 |
+
import datasets
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
_CITATION = """\
|
| 24 |
+
"""
|
| 25 |
+
|
| 26 |
+
_DESCRIPTION = """\
|
| 27 |
+
"""
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
_HOMEPAGE = "https://github.com/Coldog2333/SuperDialseg"
|
| 31 |
+
|
| 32 |
+
_LICENSE = """\
|
| 33 |
+
"""
|
| 34 |
+
# TODO: Add link to the official dataset URLs here
|
| 35 |
+
# The HuggingFace dataset library don't host the datasets but only point to the original files
|
| 36 |
+
# This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
|
| 37 |
+
_URLs = {
|
| 38 |
+
"train": "https://huggingface.co/datasets/Coldog2333/super_dialseg/resolve/main/train.json",
|
| 39 |
+
"validation": "https://huggingface.co/datasets/Coldog2333/super_dialseg/resolve/main/validation.json",
|
| 40 |
+
"test": "https://huggingface.co/datasets/Coldog2333/super_dialseg/resolve/main/test.json",
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
class SuperDialsegConfig(datasets.BuilderConfig):
|
| 45 |
+
"""BuilderConfig for SuperDialseg"""
|
| 46 |
+
|
| 47 |
+
def __init__(self, **kwargs):
|
| 48 |
+
"""
|
| 49 |
+
Args:
|
| 50 |
+
**kwargs: keyword arguments forwarded to super.
|
| 51 |
+
"""
|
| 52 |
+
super().__init__(version=datasets.Version("1.0.0", ""), **kwargs)
|
| 53 |
+
self.dataset_name = "super_dialseg"
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
class SuperDialseg(datasets.GeneratorBasedBuilder):
|
| 57 |
+
"""SuperDialseg: A Large-scale Dataset for Supervised Dialogue Segmentation"""
|
| 58 |
+
|
| 59 |
+
VERSION = datasets.Version("1.0.0")
|
| 60 |
+
|
| 61 |
+
def _info(self):
|
| 62 |
+
return datasets.DatasetInfo(
|
| 63 |
+
description=_DESCRIPTION,
|
| 64 |
+
features=datasets.Features(
|
| 65 |
+
{
|
| 66 |
+
"dial_id": datasets.Value("string"),
|
| 67 |
+
"turns": datasets.features.Sequence(
|
| 68 |
+
{
|
| 69 |
+
"da": datasets.Value("string"),
|
| 70 |
+
"role": datasets.Value("string"),
|
| 71 |
+
"turn_id": datasets.Value("int32"),
|
| 72 |
+
"utterance": datasets.Value("string"),
|
| 73 |
+
"topic_id": datasets.Value("int32"),
|
| 74 |
+
"segmentation_label": datasets.Value("int32"),
|
| 75 |
+
}
|
| 76 |
+
)
|
| 77 |
+
}
|
| 78 |
+
),
|
| 79 |
+
supervised_keys=None,
|
| 80 |
+
homepage=_HOMEPAGE,
|
| 81 |
+
license=_LICENSE,
|
| 82 |
+
citation=_CITATION,
|
| 83 |
+
)
|
| 84 |
+
|
| 85 |
+
def _split_generators(self, dl_manager):
|
| 86 |
+
"""Returns SplitGenerators."""
|
| 87 |
+
downloaded_files = dl_manager.download_and_extract(_URLs)
|
| 88 |
+
return [
|
| 89 |
+
datasets.SplitGenerator(
|
| 90 |
+
name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}
|
| 91 |
+
),
|
| 92 |
+
datasets.SplitGenerator(
|
| 93 |
+
name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["validation"]}
|
| 94 |
+
),
|
| 95 |
+
datasets.SplitGenerator(
|
| 96 |
+
name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}
|
| 97 |
+
)
|
| 98 |
+
]
|
| 99 |
+
|
| 100 |
+
def _generate_examples(self, filepath):
|
| 101 |
+
"""Yields examples."""
|
| 102 |
+
with open(filepath, encoding="utf-8") as f:
|
| 103 |
+
data = json.load(f)["dial_data"][self.dataset_name]
|
| 104 |
+
for id_, row in enumerate(data):
|
| 105 |
+
yield id_, {
|
| 106 |
+
"dial_id": row["dial_id"],
|
| 107 |
+
"turns": row["turns"],
|
| 108 |
+
}
|