Datasets:
knkarthick
commited on
Commit
•
2152969
1
Parent(s):
f15cd6e
Update dialogsum_reformat.py
Browse files- dialogsum_reformat.py +186 -65
dialogsum_reformat.py
CHANGED
@@ -1,9 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import json
|
2 |
-
|
|
|
|
|
3 |
import datasets
|
4 |
-
import os
|
5 |
|
6 |
-
logger = datasets.logging.get_logger(__name__)
|
7 |
|
8 |
_CITATION = """
|
9 |
@inproceedings{chen-etal-2021-dialogsum,
|
@@ -32,40 +49,30 @@ There are two features:
|
|
32 |
"""
|
33 |
_HOMEPAGE = "hhttps://aclanthology.org/2021.findings-acl.449"
|
34 |
_LICENSE = "CC BY-NC-ND 4.0"
|
35 |
-
|
36 |
-
_URL = "https://huggingface.co/datasets/knkarthick/dialogsum_reformat/resolve/main/"
|
37 |
-
# _URL = "https://huggingface.co/datasets/knkarthick/dialogsum_reformat/blob/main/"
|
38 |
-
|
39 |
-
_URLS = {
|
40 |
-
"train": _URL + "train.json",
|
41 |
-
"test": _URL + "test.json",
|
42 |
-
"val": _URL + "val.json",
|
43 |
-
}
|
44 |
-
|
45 |
|
46 |
|
47 |
class Dialogsum(datasets.GeneratorBasedBuilder):
|
48 |
-
"""
|
49 |
|
50 |
VERSION = datasets.Version("1.1.0")
|
51 |
|
52 |
BUILDER_CONFIGS = [
|
53 |
-
datasets.BuilderConfig(name="
|
54 |
]
|
55 |
|
56 |
def _info(self):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
return datasets.DatasetInfo(
|
58 |
description=_DESCRIPTION,
|
59 |
-
features=
|
60 |
-
{
|
61 |
-
"id": datasets.Value("string"),
|
62 |
-
"dialogue": datasets.Value("string"),
|
63 |
-
"summary": datasets.Value("string"),
|
64 |
-
"topic": datasets.Value("string"),
|
65 |
-
}
|
66 |
-
),
|
67 |
-
# No default supervised_keys (as we have to pass both question
|
68 |
-
# and context as input).
|
69 |
supervised_keys=None,
|
70 |
homepage=_HOMEPAGE,
|
71 |
license=_LICENSE,
|
@@ -73,47 +80,161 @@ class Dialogsum(datasets.GeneratorBasedBuilder):
|
|
73 |
)
|
74 |
|
75 |
def _split_generators(self, dl_manager):
|
76 |
-
|
|
|
77 |
return [
|
78 |
-
datasets.SplitGenerator(
|
79 |
-
|
80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
]
|
82 |
|
83 |
-
def _generate_examples(self, filepath):
|
84 |
-
"""
|
85 |
-
|
86 |
-
with open(
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
|
|
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 |
+
"""DIALOGSum dataset."""
|
16 |
+
|
17 |
+
|
18 |
import json
|
19 |
+
|
20 |
+
import py7zr
|
21 |
+
|
22 |
import datasets
|
|
|
23 |
|
|
|
24 |
|
25 |
_CITATION = """
|
26 |
@inproceedings{chen-etal-2021-dialogsum,
|
|
|
49 |
"""
|
50 |
_HOMEPAGE = "hhttps://aclanthology.org/2021.findings-acl.449"
|
51 |
_LICENSE = "CC BY-NC-ND 4.0"
|
52 |
+
_URL = "https://huggingface.co/datasets/knkarthick/dialogsum_reformat/resolve/main/corpus.7z"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
|
54 |
|
55 |
class Dialogsum(datasets.GeneratorBasedBuilder):
|
56 |
+
"""DIALOGSum Corpus dataset."""
|
57 |
|
58 |
VERSION = datasets.Version("1.1.0")
|
59 |
|
60 |
BUILDER_CONFIGS = [
|
61 |
+
datasets.BuilderConfig(name="dialogsum"),
|
62 |
]
|
63 |
|
64 |
def _info(self):
|
65 |
+
features = datasets.Features(
|
66 |
+
{
|
67 |
+
"id": datasets.Value("string"),
|
68 |
+
"dialogue": datasets.Value("string"),
|
69 |
+
"summary": datasets.Value("string"),
|
70 |
+
"topic": datasets.Value("string"),
|
71 |
+
}
|
72 |
+
)
|
73 |
return datasets.DatasetInfo(
|
74 |
description=_DESCRIPTION,
|
75 |
+
features=features,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
supervised_keys=None,
|
77 |
homepage=_HOMEPAGE,
|
78 |
license=_LICENSE,
|
|
|
80 |
)
|
81 |
|
82 |
def _split_generators(self, dl_manager):
|
83 |
+
"""Returns SplitGenerators."""
|
84 |
+
path = dl_manager.download(_URL)
|
85 |
return [
|
86 |
+
datasets.SplitGenerator(
|
87 |
+
name=datasets.Split.TRAIN,
|
88 |
+
gen_kwargs={
|
89 |
+
"filepath": (path, "train.json"),
|
90 |
+
"split": "train",
|
91 |
+
},
|
92 |
+
),
|
93 |
+
datasets.SplitGenerator(
|
94 |
+
name=datasets.Split.TEST,
|
95 |
+
gen_kwargs={
|
96 |
+
"filepath": (path, "test.json"),
|
97 |
+
"split": "test",
|
98 |
+
},
|
99 |
+
),
|
100 |
+
datasets.SplitGenerator(
|
101 |
+
name=datasets.Split.VALIDATION,
|
102 |
+
gen_kwargs={
|
103 |
+
"filepath": (path, "val.json"),
|
104 |
+
"split": "val",
|
105 |
+
},
|
106 |
+
),
|
107 |
]
|
108 |
|
109 |
+
def _generate_examples(self, filepath, split):
|
110 |
+
"""Yields examples."""
|
111 |
+
path, fname = filepath
|
112 |
+
with open(path, "rb") as f:
|
113 |
+
with py7zr.SevenZipFile(f, "r") as z:
|
114 |
+
for name, bio in z.readall().items():
|
115 |
+
if name == fname:
|
116 |
+
data = json.load(bio)
|
117 |
+
for example in data:
|
118 |
+
yield example["id"], example
|
119 |
+
|
120 |
+
###################### OLD #####################
|
121 |
+
|
122 |
+
# import json
|
123 |
+
# import pandas as pd
|
124 |
+
# import datasets
|
125 |
+
# import os
|
126 |
+
|
127 |
+
# logger = datasets.logging.get_logger(__name__)
|
128 |
+
|
129 |
+
# _CITATION = """
|
130 |
+
# @inproceedings{chen-etal-2021-dialogsum,
|
131 |
+
# title={{D}ialog{S}um: {A} Real-Life Scenario Dialogue Summarization Dataset},
|
132 |
+
# author={Chen, Yulong and Liu, Yang and Chen, Liang and Zhang, Yue},
|
133 |
+
# journal={arXiv preprint arXiv:1911.12237},
|
134 |
+
# year={2021},
|
135 |
+
# booktitle ={Findings of the Association for Computational Linguistics: ACL-IJCNLP 2021"},
|
136 |
+
# month = {aug},
|
137 |
+
# address = {Online},
|
138 |
+
# publisher = {Association for Computational Linguistics},
|
139 |
+
# url = {https://aclanthology.org/2021.findings-acl.449},
|
140 |
+
# doi = {10.18653/v1/2021.findings-acl.449},
|
141 |
+
# pages = {5062--5074}
|
142 |
+
# }
|
143 |
+
# """
|
144 |
+
|
145 |
+
# _DESCRIPTION = """
|
146 |
+
# DialogSUM Corpus contains 13460 chat dialogues with manually annotated
|
147 |
+
# summaries.
|
148 |
+
# There are two features:
|
149 |
+
# - dialogue: text of dialogue.
|
150 |
+
# - summary: human written summary of the dialogue.
|
151 |
+
# - topic: one liner summary of the dialogue.
|
152 |
+
# - id: id of a example.
|
153 |
+
# """
|
154 |
+
# _HOMEPAGE = "hhttps://aclanthology.org/2021.findings-acl.449"
|
155 |
+
# _LICENSE = "CC BY-NC-ND 4.0"
|
156 |
+
# # _URL = "https://huggingface.co/datasets/knkarthick/dialogsum_reformat/tree/main/"
|
157 |
+
# _URL = "https://huggingface.co/datasets/knkarthick/dialogsum_reformat/resolve/main/"
|
158 |
+
# # _URL = "https://huggingface.co/datasets/knkarthick/dialogsum_reformat/blob/main/"
|
159 |
+
|
160 |
+
# _URLS = {
|
161 |
+
# "train": _URL + "train.json",
|
162 |
+
# "test": _URL + "test.json",
|
163 |
+
# "val": _URL + "val.json",
|
164 |
+
# }
|
165 |
+
|
166 |
+
|
167 |
+
|
168 |
+
# class Dialogsum(datasets.GeneratorBasedBuilder):
|
169 |
+
# """Dialogsum Corpus dataset."""
|
170 |
+
|
171 |
+
# VERSION = datasets.Version("1.1.0")
|
172 |
+
|
173 |
+
# BUILDER_CONFIGS = [
|
174 |
+
# datasets.BuilderConfig(name="dialogsum_reformat"),
|
175 |
+
# ]
|
176 |
+
|
177 |
+
# def _info(self):
|
178 |
+
# return datasets.DatasetInfo(
|
179 |
+
# description=_DESCRIPTION,
|
180 |
+
# features=datasets.Features(
|
181 |
+
# {
|
182 |
+
# "id": datasets.Value("string"),
|
183 |
+
# "dialogue": datasets.Value("string"),
|
184 |
+
# "summary": datasets.Value("string"),
|
185 |
+
# "topic": datasets.Value("string"),
|
186 |
+
# }
|
187 |
+
# ),
|
188 |
+
# # No default supervised_keys (as we have to pass both question
|
189 |
+
# # and context as input).
|
190 |
+
# supervised_keys=None,
|
191 |
+
# homepage=_HOMEPAGE,
|
192 |
+
# license=_LICENSE,
|
193 |
+
# citation=_CITATION,
|
194 |
+
# )
|
195 |
+
|
196 |
+
# def _split_generators(self, dl_manager):
|
197 |
+
# downloaded_files = dl_manager.download_and_extract(_URLS)
|
198 |
+
# return [
|
199 |
+
# datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
|
200 |
+
# datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}),
|
201 |
+
# datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["val"]}),
|
202 |
+
# ]
|
203 |
+
|
204 |
+
# def _generate_examples(self, filepath):
|
205 |
+
# """This function returns the examples in the raw (text) form."""
|
206 |
+
# logger.info("generating examples from = %s", filepath)
|
207 |
+
# with open(filepath) as f :
|
208 |
+
# data = json.load(f)
|
209 |
+
|
210 |
+
# for info in data :
|
211 |
+
# dialogue_id = info['id']
|
212 |
+
# dialogue_name = info['dialogue']
|
213 |
+
# dialogue_summary = info['summary']
|
214 |
+
# dialogue_topic = info['topic']
|
215 |
+
|
216 |
+
# yield {
|
217 |
+
# "id" : dialogue_id,
|
218 |
+
# "dialogue" : dialogue_name,
|
219 |
+
# "summary" : dialogue_summary,
|
220 |
+
# "topic" : dialogue_topic,
|
221 |
+
# }
|
222 |
|
223 |
+
# # def _generate_examples(self, filepath, split):
|
224 |
+
# # """This function returns the examples in the raw (text) form."""
|
225 |
+
# # logger.info("generating examples from = %s", filepath)
|
226 |
+
# # with open(os.path.join(filepath, split)) as f :
|
227 |
+
# # data = json.load(f)
|
228 |
+
|
229 |
+
# # for info in data :
|
230 |
+
# # dialogue_id = info['id']
|
231 |
+
# # dialogue_name = info['dialogue']
|
232 |
+
# # dialogue_summary = info['summary']
|
233 |
+
# # dialogue_topic = info['topic']
|
234 |
+
|
235 |
+
# # yield key, {
|
236 |
+
# # "id" : dialogue_id,
|
237 |
+
# # "dialogue" : dialogue_name,
|
238 |
+
# # "summary" : dialogue_summary,
|
239 |
+
# # "topic" : dialogue_topic,
|
240 |
+
# # }
|