File size: 1,855 Bytes
51ef192
 
 
 
 
 
 
 
 
 
 
fdf86dc
51ef192
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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
                }