File size: 4,552 Bytes
8063cb1 3369fdd e261789 8063cb1 451d7e0 856dc5e 8063cb1 c1c0938 13b5cac 8063cb1 f7043a8 8063cb1 856dc5e 8063cb1 3369fdd 8063cb1 3369fdd 8063cb1 3369fdd |
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 |
import csv
import json
import os
import datasets
from typing import List, Any
# _SPLIT = ['train', 'test', 'valid']
_CITATION = """\
TBA
"""
_DESCRIPTION = """\
This new dataset is designed to solve kp NLP task and is crafted with a lot of care.
"""
_HOMEPAGE = ""
# TODO: Add the licence for the dataset here if you can find it
_LICENSE = ""
# TODO: Add link to the official dataset URLs here
_URLS = {
"test": ["data/test.jsonl"],
"train": ["train.jsonl"],
"valid": ["data/valid.jsonl"],
}
# TODO: Name of the dataset usually match the script name with CamelCase instead of snake_case
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):
#print(os.listdir())
#_URLS['train']=[os.path.join('data/'+self.config.name,filename) for filename in os.listdir('data/'+self.config.name+"/") if filename.startswith('train') and filename.endswith('.jsonl')]
_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(
# This is the description that will appear on the datasets page.
description=_DESCRIPTION,
# This defines the different columns of the dataset and their types
features=features,
homepage=_HOMEPAGE,
# License for the dataset if available
license=_LICENSE,
# Citation for the dataset
citation=_CITATION,
)
def _split_generators(self, dl_manager):
data_dir = dl_manager.download_and_extract(_URLS)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
# These kwargs will be passed to _generate_examples
gen_kwargs={
"filepaths": data_dir['train'],
"split": "train",
},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
# These kwargs will be passed to _generate_examples
gen_kwargs={
"filepaths": data_dir['test'],
"split": "test"
},
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
# These kwargs will be passed to _generate_examples
gen_kwargs={
"filepaths": data_dir['valid'],
"split": "valid",
},
),
]
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
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"]
}
|