|
import json |
|
from typing import List |
|
import datasets |
|
|
|
|
|
logger = datasets.logging.get_logger(__name__) |
|
|
|
|
|
class Test(datasets.GeneratorBasedBuilder): |
|
|
|
_HOMEPAGE = "https://huggingface.co/datasets/nateraw/test/" |
|
_URL = "https://huggingface.co/datasets/nateraw/test/raw/main/" |
|
_URLS = { |
|
"train": _URL + "train.json", |
|
"dev": _URL + "dev.json", |
|
} |
|
_DESCRIPTION = "A test!" |
|
_CITATION = None |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
description=self._DESCRIPTION, |
|
features=datasets.Features( |
|
{ |
|
"id": datasets.Value("string"), |
|
"text": datasets.Value("string"), |
|
} |
|
), |
|
supervised_keys=None, |
|
homepage=self._HOMEPAGE, |
|
citation=self._CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]: |
|
urls_to_download = self._URLS |
|
downloaded_files = dl_manager.download_and_extract(urls_to_download) |
|
|
|
return [ |
|
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}), |
|
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}), |
|
] |
|
|
|
def _generate_examples(self, filepath): |
|
"""This function returns the examples in the raw (text) form.""" |
|
logger.info("generating examples from = %s", filepath) |
|
with open(filepath) as f: |
|
content = json.load(f) |
|
for example in content['data']: |
|
example_id = example.get('id', "").strip() |
|
text = example.get('text', "").strip() |
|
yield example_id, { |
|
"id": example_id, |
|
"text": text |
|
} |
|
|