|
import csv |
|
import json |
|
import os |
|
|
|
import datasets |
|
from typing import List, Any |
|
|
|
|
|
_CITATION = """\ |
|
TBA |
|
""" |
|
|
|
|
|
_DESCRIPTION = """\ |
|
This new dataset is designed to solve kp NLP task and is crafted with a lot of care. |
|
""" |
|
|
|
|
|
_HOMEPAGE = "" |
|
|
|
|
|
_LICENSE = "" |
|
|
|
|
|
|
|
_URLS = { |
|
"test": ["data/test.jsonl"], |
|
"train": ["train.jsonl"], |
|
"valid": ["data/valid.jsonl"], |
|
|
|
} |
|
|
|
|
|
|
|
class LDKP3k(datasets.GeneratorBasedBuilder): |
|
"""TODO: Short description of my dataset.""" |
|
|
|
VERSION = datasets.Version("1.1.0") |
|
|
|
BUILDER_CONFIGS = [ |
|
datasets.BuilderConfig(name="small", version=VERSION, description="This part of my dataset covers long document"), |
|
datasets.BuilderConfig(name="medium", version=VERSION, description="This part of my dataset covers abstract only"), |
|
datasets.BuilderConfig(name="large", version=VERSION, description="This part of my dataset covers abstract only") |
|
|
|
|
|
] |
|
|
|
DEFAULT_CONFIG_NAME = "small" |
|
|
|
def _info(self): |
|
|
|
|
|
_URLS['train']=["data/"+self.config.name+"/train.jsonl"] |
|
if self.config.name =='large': |
|
_URLS['train']+= ["data/"+self.config.name+"/train_"+str(x)+".jsonl" for x in range(1,5)] |
|
|
|
features = datasets.Features( |
|
{ |
|
"id": datasets.Value("string"), |
|
"sections": datasets.features.Sequence(datasets.Value("string")), |
|
"sec_text": datasets.features.Sequence(datasets.features.Sequence(datasets.Value("string"))), |
|
"extractive_keyphrases": datasets.features.Sequence(datasets.Value("string")), |
|
"abstractive_keyphrases": datasets.features.Sequence(datasets.Value("string")), |
|
"sec_bio_tags": datasets.features.Sequence(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): |
|
print(os.listdir()) |
|
data_dir = dl_manager.download_and_extract(_URLS) |
|
|
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
|
|
gen_kwargs={ |
|
"filepaths": data_dir['train'], |
|
"split": "train", |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
|
|
gen_kwargs={ |
|
"filepaths": data_dir['test'], |
|
"split": "test" |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.VALIDATION, |
|
|
|
gen_kwargs={ |
|
"filepaths": data_dir['valid'], |
|
"split": "valid", |
|
}, |
|
), |
|
] |
|
|
|
|
|
def _generate_examples(self, filepaths, split): |
|
for filepath in filepaths: |
|
with open(filepath, encoding="utf-8") as f: |
|
for key, row in enumerate(f): |
|
data = json.loads(row) |
|
yield key, { |
|
"id": data['paper_id'], |
|
"sections": data["sections"], |
|
"sec_text": data["sec_text"], |
|
"extractive_keyphrases": data["extractive_keyphrases"], |
|
"abstractive_keyphrases": data["abstractive_keyphrases"], |
|
"sec_bio_tags": data["sec_bio_tags"] |
|
} |
|
|