|
import json |
|
import datasets |
|
|
|
|
|
_CITATION = """\ |
|
@inproceedings{gallina2019kptimes, |
|
title={KPTimes: A Large-Scale Dataset for Keyphrase Generation on News Documents}, |
|
author={Gallina, Ygor and Boudin, Florian and Daille, B{\'e}atrice}, |
|
booktitle={Proceedings of the 12th International Conference on Natural Language Generation}, |
|
pages={130--135}, |
|
year={2019} |
|
} |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
|
|
""" |
|
|
|
_HOMEPAGE = "https://github.com/ygorg/KPTimes" |
|
|
|
|
|
_LICENSE = "Apache License 2.0" |
|
|
|
|
|
|
|
_URLS = { |
|
"test": "test.jsonl", |
|
"train": "train.jsonl", |
|
"valid": "valid.jsonl" |
|
} |
|
|
|
|
|
|
|
class KPTimes(datasets.GeneratorBasedBuilder): |
|
"""TODO: Short description of my dataset.""" |
|
|
|
VERSION = datasets.Version("0.0.1") |
|
|
|
BUILDER_CONFIGS = [ |
|
datasets.BuilderConfig(name="extraction", version=VERSION, |
|
description="This part of my dataset covers extraction"), |
|
datasets.BuilderConfig(name="generation", version=VERSION, |
|
description="This part of my dataset covers generation"), |
|
datasets.BuilderConfig(name="raw", version=VERSION, description="This part of my dataset covers the raw data"), |
|
] |
|
|
|
DEFAULT_CONFIG_NAME = "extraction" |
|
|
|
def _info(self): |
|
if self.config.name == "extraction": |
|
features = datasets.Features( |
|
{ |
|
"id": datasets.Value("int64"), |
|
"document": datasets.features.Sequence(datasets.Value("string")), |
|
"doc_bio_tags": datasets.features.Sequence(datasets.Value("string")) |
|
|
|
} |
|
) |
|
elif self.config.name == "generation": |
|
features = datasets.Features( |
|
{ |
|
"id": datasets.Value("int64"), |
|
"document": datasets.features.Sequence(datasets.Value("string")), |
|
"extractive_keyphrases": datasets.features.Sequence(datasets.Value("string")), |
|
"abstractive_keyphrases": datasets.features.Sequence(datasets.Value("string")) |
|
|
|
} |
|
) |
|
else: |
|
features = datasets.Features( |
|
{ |
|
"id": datasets.Value("int64"), |
|
"document": datasets.features.Sequence(datasets.Value("string")), |
|
"doc_bio_tags": datasets.features.Sequence(datasets.Value("string")), |
|
"extractive_keyphrases": datasets.features.Sequence(datasets.Value("string")), |
|
"abstractive_keyphrases": datasets.features.Sequence(datasets.Value("string")), |
|
"other_metadata": datasets.features.Sequence( |
|
{ |
|
"id": datasets.Value("string"), |
|
"categories": datasets.features.Sequence(datasets.Value("string")), |
|
"date": datasets.Value("string"), |
|
"title": datasets.Value("string"), |
|
"abstract": datasets.Value("string"), |
|
"keyword": datasets.Value("string"), |
|
} |
|
) |
|
|
|
} |
|
) |
|
return datasets.DatasetInfo( |
|
|
|
description=_DESCRIPTION, |
|
|
|
features=features, |
|
homepage=_HOMEPAGE, |
|
|
|
license=_LICENSE, |
|
|
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
|
|
data_dir = dl_manager.download_and_extract(_URLS) |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
|
|
gen_kwargs={ |
|
"filepath": data_dir['train'], |
|
"split": "train", |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
|
|
gen_kwargs={ |
|
"filepath": data_dir['test'], |
|
"split": "test" |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.VALIDATION, |
|
|
|
gen_kwargs={ |
|
"filepath": data_dir['valid'], |
|
"split": "valid", |
|
}, |
|
), |
|
] |
|
|
|
|
|
def _generate_examples(self, filepath, split): |
|
with open(filepath, encoding="utf-8") as f: |
|
for key, row in enumerate(f): |
|
data = json.loads(row) |
|
if self.config.name == "extraction": |
|
|
|
yield key, { |
|
"id": data.get('paper_id'), |
|
"document": data["document"], |
|
"doc_bio_tags": data.get("doc_bio_tags") |
|
} |
|
elif self.config.name == "generation": |
|
yield key, { |
|
"id": data.get('paper_id'), |
|
"document": data["document"], |
|
"extractive_keyphrases": data.get("extractive_keyphrases"), |
|
"abstractive_keyphrases": data.get("abstractive_keyphrases") |
|
} |
|
else: |
|
yield key, { |
|
"id": data.get('paper_id'), |
|
"document": data["document"], |
|
"doc_bio_tags": data.get("doc_bio_tags"), |
|
"extractive_keyphrases": data.get("extractive_keyphrases"), |
|
"abstractive_keyphrases": data.get("abstractive_keyphrases"), |
|
"other_metadata": data["other_metadata"] |
|
} |
|
|