Datasets:
File size: 14,482 Bytes
64af2a3 e97d234 ba53cfb e97d234 d142940 e97d234 d142940 e97d234 64af2a3 52eebd1 64af2a3 52eebd1 64af2a3 52eebd1 64af2a3 52eebd1 64af2a3 52eebd1 64af2a3 52eebd1 64af2a3 52eebd1 64af2a3 52eebd1 64af2a3 52eebd1 64af2a3 52eebd1 64af2a3 52eebd1 64af2a3 52eebd1 64af2a3 52eebd1 64af2a3 52eebd1 64af2a3 52eebd1 96f86c6 64af2a3 52eebd1 64af2a3 52eebd1 64af2a3 52eebd1 96f86c6 64af2a3 52eebd1 64af2a3 52eebd1 64af2a3 52eebd1 96f86c6 64af2a3 52eebd1 64af2a3 52eebd1 64af2a3 52eebd1 96f86c6 64af2a3 52eebd1 64af2a3 52eebd1 64af2a3 52eebd1 b403b4a 96f86c6 64af2a3 52eebd1 64af2a3 52eebd1 64af2a3 52eebd1 b403b4a 96f86c6 64af2a3 52eebd1 64af2a3 52eebd1 64af2a3 52eebd1 96f86c6 64af2a3 52eebd1 64af2a3 52eebd1 64af2a3 52eebd1 57b989f 64af2a3 52eebd1 d142940 52eebd1 d142940 52eebd1 64af2a3 |
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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 |
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import io
import datasets
import pickle
import logging
# General Constants:
LABEL_NAME = 'label'
numbers = {
1: "first",
2: "second",
3: "third",
4: "fourth",
5: "fifth",
6: "sixth",
7: "seventh",
8: "eighth",
9: "ninth"
}
TEXT_COLUMN_NAME = [f"{numbers[i]}_sentence" for i in range(1, 10)]
# SSPabs Constants:
SSPABS = 'SSPabs'
SSPABS_TRAIN_NAME = 'train.txt'
SSPABS_VALID_NAME = 'valid.txt'
SSPABS_TEST_NAME = 'test.txt'
SSPABS_DATA_DIR = 'data/SSP/abs'
SSPABS_LABELS = {
"0": "Does not belong to abstract",
"1": "Belongs to abstract",
}
SSPABS_TEXT_COLUMNS = 1
# PDTB Constants:
PDTB_I = 'PDTB_I'
PDTB_E = 'PDTB_E'
PDTB_TRAIN_NAME = 'train.txt'
PDTB_VALID_NAME = 'valid.txt'
PDTB_TEST_NAME = 'test.txt'
PDTB_DATA_DIR = 'data/PDTB'
PDTB_DIRS = {PDTB_E: 'Explicit', PDTB_I: 'Implicit'}
PDTB_E_LABELS = [
'Comparison.Concession',
'Comparison.Contrast',
'Contingency.Cause',
'Contingency.Condition',
'Contingency.Pragmatic condition',
'Expansion.Alternative',
'Expansion.Conjunction',
'Expansion.Instantiation',
'Expansion.List',
'Expansion.Restatement',
'Temporal.Asynchronous',
'Temporal.Synchrony',
]
PDTB_E_LABELS = {str(i): label for i, label in enumerate(PDTB_E_LABELS)}
PDTB_I_LABELS = [
'Comparison.Concession',
'Comparison.Contrast',
'Contingency.Cause',
'Contingency.Pragmatic cause',
'Expansion.Alternative',
'Expansion.Conjunction',
'Expansion.Instantiation',
'Expansion.List',
'Expansion.Restatement',
'Temporal.Asynchronous',
'Temporal.Synchrony',
]
PDTB_I_LABELS = {str(i): label for i, label in enumerate(PDTB_I_LABELS)}
PDTB_E_TEXT_COLUMNS = 2
PDTB_I_TEXT_COLUMNS = 2
# SP Constants:
SPARXIV = 'SParxiv'
SPROCSTORY = 'SProcstory'
SPWIKI = 'SPwiki'
SP_TRAIN_NAME = 'train.txt'
SP_VALID_NAME = 'valid.txt'
SP_TEST_NAME = 'test.txt'
SP_DATA_DIR = 'data/SP'
SP_DIRS = {SPARXIV: 'arxiv', SPROCSTORY: 'rocstory', SPWIKI: 'wiki'}
SP_LABELS = {
"0": 'First sentence',
"1": 'Second sentence',
"2": 'Third sentence',
"3": "Fourth sentence",
"4": "Fifth sentence",
}
SP_TEXT_COLUMNS = 5
# BSO Constants:
BSOARXIV = 'BSOarxiv'
BSOROCSTORY = 'BSOrocstory'
BSOWIKI = 'BSOwiki'
BSO_TRAIN_NAME = 'train.txt'
BSO_VALID_NAME = 'valid.txt'
BSO_TEST_NAME = 'test.txt'
BSO_DATA_DIR = 'data/BSO'
BSO_DIRS = {BSOARXIV: 'arxiv', BSOROCSTORY: 'rocstory', BSOWIKI: 'wiki'}
BSO_LABELS = {
"0": 'Incorrect order',
"1": 'Correct order',
}
BSO_TEXT_COLUMNS = 2
# DC Constants:
DCCHAT = 'DCchat'
DCWIKI = 'DCwiki'
DC_TRAIN_NAME = 'train.txt'
DC_VALID_NAME = 'valid.txt'
DC_TEST_NAME = 'test.txt'
DC_DATA_DIR = 'data/DC'
DC_DIRS = {DCCHAT: 'chat', DCWIKI: 'wiki'}
DC_LABELS = {
"0": "Incoherent",
"1": "Coherent",
}
DC_TEXT_COLUMNS = 6
# RST Constants:
RST = 'RST'
RST_TRAIN_NAME = 'RST_TRAIN.pkl'
RST_VALID_NAME = 'RST_DEV.pkl'
RST_TEST_NAME = 'RST_TEST.pkl'
RST_DATA_DIR = 'data/RST'
RST_LABELS = [
'NS-Explanation',
'NS-Evaluation',
'NN-Condition',
'NS-Summary',
'SN-Cause',
'SN-Background',
'NS-Background',
'SN-Summary',
'NS-Topic-Change',
'NN-Explanation',
'SN-Topic-Comment',
'NS-Elaboration',
'SN-Attribution',
'SN-Manner-Means',
'NN-Evaluation',
'NS-Comparison',
'NS-Contrast',
'SN-Condition',
'NS-Temporal',
'NS-Enablement',
'SN-Evaluation',
'NN-Topic-Comment',
'NN-Temporal',
'NN-Textual-organization',
'NN-Same-unit',
'NN-Comparison',
'NN-Topic-Change',
'SN-Temporal',
'NN-Joint',
'SN-Enablement',
'SN-Explanation',
'NN-Contrast',
'NN-Cause',
'SN-Contrast',
'NS-Attribution',
'NS-Topic-Comment',
'SN-Elaboration',
'SN-Comparison',
'NS-Cause',
'NS-Condition',
'NS-Manner-Means'
]
RST_TEXT_COLUMNS = 2
DATASET_NAMES = [
SSPABS,
PDTB_I,
PDTB_E,
SPARXIV,
SPROCSTORY,
SPWIKI,
BSOARXIV,
BSOROCSTORY,
BSOWIKI,
DCCHAT,
DCWIKI,
RST,
]
_CITATION = """\
@InProceedings{mchen-discoeval-19,
title = {Evaluation Benchmarks and Learning Criteria for Discourse-Aware Sentence Representations},
author = {Mingda Chen and Zewei Chu and Kevin Gimpel},
booktitle = {Proc. of {EMNLP}},
year={2019}
}
"""
_DESCRIPTION = """\
This dataset contains all tasks of the DiscoEval benchmark for sentence representation learning.
"""
_HOMEPAGE = "https://github.com/ZeweiChu/DiscoEval"
class DiscoEvalSentence(datasets.GeneratorBasedBuilder):
"""DiscoEval Benchmark"""
VERSION = datasets.Version("1.1.0")
BUILDER_CONFIGS = [
datasets.BuilderConfig(
name=SPARXIV,
version=VERSION,
description="Sentence positioning dataset from arXiv",
),
datasets.BuilderConfig(
name=SPROCSTORY,
version=VERSION,
description="Sentence positioning dataset from ROCStory",
),
datasets.BuilderConfig(
name=SPWIKI,
version=VERSION,
description="Sentence positioning dataset from Wikipedia",
),
datasets.BuilderConfig(
name=DCCHAT,
version=VERSION,
description="Discourse Coherence dataset from chat",
),
datasets.BuilderConfig(
name=DCWIKI,
version=VERSION,
description="Discourse Coherence dataset from Wikipedia",
),
datasets.BuilderConfig(
name=RST,
version=VERSION,
description="The RST Discourse Treebank dataset ",
),
datasets.BuilderConfig(
name=PDTB_E,
version=VERSION,
description="The Penn Discourse Treebank - Explicit dataset.",
),
datasets.BuilderConfig(
name=PDTB_I,
version=VERSION,
description="The Penn Discourse Treebank - Implicit dataset.",
),
datasets.BuilderConfig(
name=SSPABS,
version=VERSION,
description="The SSP dataset.",
),
datasets.BuilderConfig(
name=BSOARXIV,
version=VERSION,
description="The BSO Task with the arxiv dataset.",
),
datasets.BuilderConfig(
name=BSOWIKI,
version=VERSION,
description="The BSO Task with the wiki dataset.",
),
datasets.BuilderConfig(
name=BSOROCSTORY,
version=VERSION,
description="The BSO Task with the rocstory dataset.",
),
]
def _info(self):
if self.config.name in [SPARXIV, SPROCSTORY, SPWIKI]:
features_dict = {
TEXT_COLUMN_NAME[i]: datasets.Value('string')
for i in range(SP_TEXT_COLUMNS)
}
features_dict[LABEL_NAME] = datasets.ClassLabel(
names=list(SP_LABELS.values()),
)
features = datasets.Features(features_dict)
elif self.config.name in [BSOARXIV, BSOWIKI, BSOROCSTORY]:
features_dict = {
TEXT_COLUMN_NAME[i]: datasets.Value('string')
for i in range(BSO_TEXT_COLUMNS)
}
features_dict[LABEL_NAME] = datasets.ClassLabel(
names=list(BSO_LABELS.values())
)
features = datasets.Features(features_dict)
elif self.config.name in [DCCHAT, DCWIKI]:
features_dict = {
TEXT_COLUMN_NAME[i]: datasets.Value('string')
for i in range(DC_TEXT_COLUMNS)
}
features_dict[LABEL_NAME] = datasets.ClassLabel(
names=list(DC_LABELS.values())
)
features = datasets.Features(features_dict)
elif self.config.name in [RST]:
features_dict = {
TEXT_COLUMN_NAME[i]: [datasets.Value('string')]
for i in range(RST_TEXT_COLUMNS)
}
features_dict[LABEL_NAME] = datasets.ClassLabel(
names=RST_LABELS
)
features = datasets.Features(features_dict)
elif self.config.name in [PDTB_E]:
features_dict = {
TEXT_COLUMN_NAME[i]: datasets.Value('string')
for i in range(PDTB_E_TEXT_COLUMNS)
}
features_dict[LABEL_NAME] = datasets.ClassLabel(
names=list(PDTB_E_LABELS.values())
)
features = datasets.Features(features_dict)
elif self.config.name in [PDTB_I]:
features_dict = {
TEXT_COLUMN_NAME[i]: datasets.Value('string')
for i in range(PDTB_I_TEXT_COLUMNS)
}
features_dict[LABEL_NAME] = datasets.ClassLabel(
names=list(PDTB_I_LABELS.values())
)
features = datasets.Features(features_dict)
elif self.config.name in [SSPABS]:
features_dict = {
TEXT_COLUMN_NAME[i]: datasets.Value('string')
for i in range(SSPABS_TEXT_COLUMNS)
}
features_dict[LABEL_NAME] = datasets.ClassLabel(
names=list(SSPABS_LABELS.values())
)
features = datasets.Features(features_dict)
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=features,
homepage=_HOMEPAGE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
if self.config.name in [SPARXIV, SPROCSTORY, SPWIKI]:
data_dir = SP_DATA_DIR + "/" + SP_DIRS[self.config.name]
train_name = SP_TRAIN_NAME
valid_name = SP_VALID_NAME
test_name = SP_TEST_NAME
elif self.config.name in [BSOARXIV, BSOWIKI, BSOROCSTORY]:
data_dir = BSO_DATA_DIR + "/" + BSO_DIRS[self.config.name]
train_name = BSO_TRAIN_NAME
valid_name = BSO_VALID_NAME
test_name = BSO_TEST_NAME
elif self.config.name in [DCCHAT, DCWIKI]:
data_dir = DC_DATA_DIR + "/" + DC_DIRS[self.config.name]
train_name = DC_TRAIN_NAME
valid_name = DC_VALID_NAME
test_name = DC_TEST_NAME
elif self.config.name in [RST]:
data_dir = RST_DATA_DIR
train_name = RST_TRAIN_NAME
valid_name = RST_VALID_NAME
test_name = RST_TEST_NAME
elif self.config.name in [PDTB_E, PDTB_I]:
data_dir = os.path.join(PDTB_DATA_DIR, PDTB_DIRS[self.config.name])
train_name = PDTB_TRAIN_NAME
valid_name = PDTB_VALID_NAME
test_name = PDTB_TEST_NAME
elif self.config.name in [SSPABS]:
data_dir = SSPABS_DATA_DIR
train_name = SSPABS_TRAIN_NAME
valid_name = SSPABS_VALID_NAME
test_name = SSPABS_TEST_NAME
urls_to_download = {
"train": data_dir + "/" + train_name,
"valid": data_dir + "/" + valid_name,
"test": data_dir + "/" + test_name,
}
logger = logging.getLogger(__name__)
data_dirs = dl_manager.download_and_extract(urls_to_download)
logger.info(f"Data directories: {data_dirs}")
downloaded_files = dl_manager.download_and_extract(data_dirs)
logger.info(f"Downloading Completed")
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"filepath": downloaded_files['train'],
"split": "train",
},
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
gen_kwargs={
"filepath": downloaded_files['valid'],
"split": "dev",
},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={
"filepath": downloaded_files['test'],
"split": "test"
},
),
]
def _generate_examples(self, filepath, split):
logger = logging.getLogger(__name__)
logger.info(f"Current working dir: {os.getcwd()}")
logger.info("generating examples from = %s", filepath)
if self.config.name == RST:
data = pickle.load(open(filepath, "rb"))
for key, line in enumerate(data):
example = {TEXT_COLUMN_NAME[i]: sent for i, sent in enumerate(line[1:])}
example[LABEL_NAME] = line[0]
yield key, example
else:
with io.open(filepath, mode='r', encoding='utf-8') as f:
for key, line in enumerate(f):
line = line.strip().split("\t")
example = {TEXT_COLUMN_NAME[i]: sent for i, sent in enumerate(line[1:])}
if self.config.name == PDTB_E:
example[LABEL_NAME] = PDTB_E_LABELS[line[0]]
if self.config.name == PDTB_I:
example[LABEL_NAME] = PDTB_I_LABELS[line[0]]
elif self.config.name in (DCCHAT, DCWIKI):
example[LABEL_NAME] = DC_LABELS[line[0]]
elif self.config.name == SSPABS:
example[LABEL_NAME] = SSPABS_LABELS[line[0]]
elif self.config.name in (SPWIKI, SPROCSTORY, SPARXIV):
example[LABEL_NAME] = SP_LABELS[line[0]]
elif self.config.name in (BSOARXIV, BSOWIKI, BSOROCSTORY):
example[LABEL_NAME] = BSO_LABELS[line[0]]
yield key, example
|