|
import csv |
|
import json |
|
import os |
|
|
|
import datasets |
|
from typing import List, Any |
|
|
|
|
|
_CITATION = """\ |
|
author: amardeep |
|
""" |
|
|
|
|
|
_DESCRIPTION = """\ |
|
This new dataset is designed to solve kp NLP task and is crafted with a lot of care. |
|
""" |
|
|
|
|
|
_HOMEPAGE = "" |
|
|
|
|
|
_LICENSE = "" |
|
|
|
|
|
|
|
_URLS = { |
|
"test": "test.jsonl", |
|
|
|
"valid": "valid.jsonl" |
|
} |
|
|
|
|
|
|
|
class TestLDKP(datasets.GeneratorBasedBuilder): |
|
"""TODO: Short description of my dataset.""" |
|
|
|
VERSION = datasets.Version("1.1.0") |
|
|
|
BUILDER_CONFIGS = [ |
|
datasets.BuilderConfig(name="extraction", version=VERSION, description="This part of my dataset covers long document"), |
|
datasets.BuilderConfig(name="generation", version=VERSION, description="This part of my dataset covers abstract only"), |
|
datasets.BuilderConfig(name="raw", version=VERSION, description="This part of my dataset covers abstract only"), |
|
datasets.BuilderConfig(name="ldkp_generation", version=VERSION, description="This part of my dataset covers abstract only"), |
|
datasets.BuilderConfig(name="ldkp_extraction", version=VERSION, description="This part of my dataset covers abstract only"), |
|
|
|
] |
|
|
|
DEFAULT_CONFIG_NAME = "extraction" |
|
|
|
def _info(self): |
|
if self.config.name == "extraction" or self.config.name == "ldkp_extraction": |
|
features = datasets.Features( |
|
{ |
|
"id": datasets.Value("int64"), |
|
"document": datasets.features.Sequence(datasets.Value("string")), |
|
"BIO_tags": datasets.features.Sequence(datasets.Value("string")) |
|
|
|
} |
|
) |
|
elif self.config.name == "generation" or self.config.name == "ldkp_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")), |
|
"document_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( |
|
{ |
|
"text": datasets.features.Sequence(datasets.Value("string")), |
|
"tags":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): |
|
|
|
data_dir = dl_manager.download_and_extract(_URLS) |
|
return [ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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['paper_id'] |
|
"document": data["document"], |
|
"BIO_tags": data["document_tags"] |
|
} |
|
elif self.config.name == "ldkp_extraction": |
|
yield key, { |
|
"id": data['paper_id'] |
|
"document": data["document"]+data["other_metadata"]['text'], |
|
"BIO_tags": data["document_tags"] + data["other_metadata"]['tags'] |
|
} |
|
elif self.config.name == "ldkp_generation": |
|
yield key, { |
|
"id": data['paper_id'] |
|
"document": data["document"]+data["other_metadata"]['text'], |
|
"extractive_keyphrases": data["extractive_keyphrases"], |
|
"abstractive_keyphrases": data["abstractive_keyphrases"] |
|
} |
|
elif self.config.name == "generation": |
|
yield key, { |
|
"id": data['paper_id'] |
|
"document": data["document"], |
|
"extractive_keyphrases": data["extractive_keyphrases"], |
|
"abstractive_keyphrases": data["abstractive_keyphrases"] |
|
} |
|
else: |
|
yield key, { |
|
"id": data['paper_id'] |
|
"document": data["document"], |
|
"document_tags": data["document_tags"], |
|
"extractive_keyphrases": data["extractive_keyphrases"], |
|
"abstractive_keyphrases": data["abstractive_keyphrases"], |
|
"other_metadata": data["other_metadata"] |
|
} |
|
|