import json import gzip import datasets import os _CITATION = """\ """ _DESCRIPTION = """\ """ _HOMEPAGE = "" _LICENSE = "" # TODO: Add link to the official dataset URLs here _FILES = { '0': ['part_0_0.jsonl.gz', 'part_0_1.jsonl.gz', 'part_0_2.jsonl.gz'], '1': ['part_1_0.jsonl.gz', 'part_1_1.jsonl.gz', 'part_1_2.jsonl.gz'], '2': ['part_2_0.jsonl.gz', 'part_2_1.jsonl.gz', 'part_2_2.jsonl.gz'], '3': ['part_3_0.jsonl.gz', 'part_3_1.jsonl.gz', 'part_3_2.jsonl.gz'], '4': ['part_4_0.jsonl.gz', 'part_4_1.jsonl.gz', 'part_4_2.jsonl.gz'], '5': ['part_5_0.jsonl.gz', 'part_5_1.jsonl.gz', 'part_5_2.jsonl.gz'], '6': ['part_6_0.jsonl.gz', 'part_6_1.jsonl.gz'], '7': ['part_7_0.jsonl.gz', 'part_7_1.jsonl.gz', 'part_7_2.jsonl.gz'], '8': ['part_8_0.jsonl.gz', 'part_8_1.jsonl.gz'], '9': ['part_9_0.jsonl.gz', 'part_9_1.jsonl.gz'], '10': ['part_10_0.jsonl.gz', 'part_10_1.jsonl.gz'], '11': ['part_11_0.jsonl.gz', 'part_11_1.jsonl.gz'], '12': ['part_12_0.jsonl.gz', 'part_12_1.jsonl.gz'], '13': ['part_13_0.jsonl.gz', 'part_13_1.jsonl.gz'], '14': ['part_14_0.jsonl.gz', 'part_14_1.jsonl.gz'] } _URLS = { "all_data": "data/all_data" } # TODO: Name of the dataset usually match the script name with CamelCase instead of snake_case class OAGKx(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): _URLS['all_data']=['data/' + filename for part in _FILES for filename in _FILES[part]] if self.config.name == "extraction": # This is the name of the configuration selected in BUILDER_CONFIGS above 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( { "text": datasets.features.Sequence(datasets.Value("string")), "bio_tags": 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) print(data_dir["all_data"]) return [ datasets.SplitGenerator( name="all_data", # These kwargs will be passed to _generate_examples gen_kwargs={ "filepaths": data_dir["all_data"], "split": "all_data", }, ), ] # 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) if self.config.name == "extraction": # Yields examples as (key, example) tuples 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"] }