|
|
"""KPTimes benchmark dataset for keyphrase extraction an generation.""" |
|
|
|
|
|
|
|
|
import csv |
|
|
import json |
|
|
import os |
|
|
|
|
|
import datasets |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_CITATION = """\ |
|
|
@inproceedings{gallina-etal-2019-kptimes, |
|
|
title = "{KPT}imes: A Large-Scale Dataset for Keyphrase Generation on News Documents", |
|
|
author = "Gallina, Ygor and |
|
|
Boudin, Florian and |
|
|
Daille, Beatrice", |
|
|
booktitle = "Proceedings of the 12th International Conference on Natural Language Generation", |
|
|
month = oct # "{--}" # nov, |
|
|
year = "2019", |
|
|
address = "Tokyo, Japan", |
|
|
publisher = "Association for Computational Linguistics", |
|
|
url = "https://aclanthology.org/W19-8617", |
|
|
doi = "10.18653/v1/W19-8617", |
|
|
pages = "130--135", |
|
|
abstract = "Keyphrase generation is the task of predicting a set of lexical units that conveys the main content of a source text. Existing datasets for keyphrase generation are only readily available for the scholarly domain and include non-expert annotations. In this paper we present KPTimes, a large-scale dataset of news texts paired with editor-curated keyphrases. Exploring the dataset, we show how editors tag documents, and how their annotations differ from those found in existing datasets. We also train and evaluate state-of-the-art neural keyphrase generation models on KPTimes to gain insights on how well they perform on the news domain. The dataset is available online at https:// github.com/ygorg/KPTimes.", |
|
|
} |
|
|
""" |
|
|
|
|
|
|
|
|
_DESCRIPTION = """\ |
|
|
KPTimes benchmark dataset for keyphrase extraction an generation. |
|
|
""" |
|
|
|
|
|
|
|
|
_HOMEPAGE = "https://aclanthology.org/W03-1028.pdf" |
|
|
|
|
|
|
|
|
_LICENSE = "Apache 2.0 License" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_URLS = { |
|
|
"test": "test.jsonl", |
|
|
"train": "train.jsonl", |
|
|
"dev": "dev.jsonl" |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class KPTimes(datasets.GeneratorBasedBuilder): |
|
|
"""TODO: Short description of my dataset.""" |
|
|
|
|
|
VERSION = datasets.Version("1.1.0") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BUILDER_CONFIGS = [ |
|
|
datasets.BuilderConfig(name="raw", version=VERSION, description="This part of my dataset covers the raw data."), |
|
|
] |
|
|
|
|
|
DEFAULT_CONFIG_NAME = "raw" |
|
|
|
|
|
def _info(self): |
|
|
|
|
|
if self.config.name == "raw": |
|
|
features = datasets.Features( |
|
|
{ |
|
|
"id": datasets.Value("string"), |
|
|
"title": datasets.Value("string"), |
|
|
"abstract": datasets.Value("string"), |
|
|
"keyphrases": datasets.features.Sequence(datasets.Value("string")), |
|
|
"prmu": datasets.features.Sequence(datasets.Value("string")), |
|
|
"date": datasets.Value("string"), |
|
|
"categories": datasets.features.Sequence(datasets.Value("string")), |
|
|
} |
|
|
) |
|
|
return datasets.DatasetInfo( |
|
|
|
|
|
description=_DESCRIPTION, |
|
|
|
|
|
features=features, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
homepage=_HOMEPAGE, |
|
|
|
|
|
license=_LICENSE, |
|
|
|
|
|
citation=_CITATION, |
|
|
) |
|
|
|
|
|
def _split_generators(self, dl_manager): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
urls = _URLS |
|
|
data_dir = dl_manager.download_and_extract(urls) |
|
|
return [ |
|
|
datasets.SplitGenerator( |
|
|
name=datasets.Split.TRAIN, |
|
|
|
|
|
gen_kwargs={ |
|
|
"filepath": os.path.join(data_dir["train"]), |
|
|
"split": "train", |
|
|
}, |
|
|
), |
|
|
datasets.SplitGenerator( |
|
|
name=datasets.Split.TEST, |
|
|
|
|
|
gen_kwargs={ |
|
|
"filepath": os.path.join(data_dir["test"]), |
|
|
"split": "test" |
|
|
}, |
|
|
), |
|
|
datasets.SplitGenerator( |
|
|
name=datasets.Split.VALIDATION, |
|
|
|
|
|
gen_kwargs={ |
|
|
"filepath": os.path.join(data_dir["dev"]), |
|
|
"split": "dev", |
|
|
}, |
|
|
), |
|
|
] |
|
|
|
|
|
|
|
|
def _generate_examples(self, filepath, split): |
|
|
|
|
|
|
|
|
with open(filepath, encoding="utf-8") as f: |
|
|
for key, row in enumerate(f): |
|
|
data = json.loads(row) |
|
|
|
|
|
yield key, { |
|
|
"id": data["id"], |
|
|
"title": data["title"], |
|
|
"abstract": data["abstract"], |
|
|
"keyphrases": data["keyphrases"], |
|
|
"prmu": data["prmu"], |
|
|
"date": data["date"], |
|
|
"categories": data["categories"], |
|
|
} |
|
|
|
|
|
|