Create test.py
Browse files
test.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
from typing import List
|
3 |
+
import datasets
|
4 |
+
|
5 |
+
|
6 |
+
logger = datasets.logging.get_logger(__name__)
|
7 |
+
|
8 |
+
|
9 |
+
class Test(datasets.GeneratorBasedBuilder):
|
10 |
+
|
11 |
+
_HOMEPAGE = "https://huggingface.co/datasets/nateraw/test/"
|
12 |
+
_URL = "https://huggingface.co/datasets/nateraw/test/blob/main/"
|
13 |
+
_URLS = {
|
14 |
+
"train": _URL + "train.json",
|
15 |
+
"dev": _URL + "dev.json",
|
16 |
+
}
|
17 |
+
_DESCRIPTION = "A test!"
|
18 |
+
_CITATION = None
|
19 |
+
|
20 |
+
def _info(self):
|
21 |
+
return datasets.DatasetInfo(
|
22 |
+
description=self._DESCRIPTION,
|
23 |
+
features=datasets.Features(
|
24 |
+
{
|
25 |
+
"id": datasets.Value("string"),
|
26 |
+
"text": datasets.Value("string"),
|
27 |
+
}
|
28 |
+
),
|
29 |
+
supervised_keys=None,
|
30 |
+
homepage=self._HOMEPAGE,
|
31 |
+
citation=self._CITATION,
|
32 |
+
)
|
33 |
+
|
34 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
35 |
+
urls_to_download = self._URLS
|
36 |
+
downloaded_files = dl_manager.download_and_extract(urls_to_download)
|
37 |
+
|
38 |
+
return [
|
39 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
|
40 |
+
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}),
|
41 |
+
]
|
42 |
+
|
43 |
+
def _generate_examples(self, filepath):
|
44 |
+
"""This function returns the examples in the raw (text) form."""
|
45 |
+
logger.info("generating examples from = %s", filepath)
|
46 |
+
with open(filepath) as f:
|
47 |
+
content = json.load(f)
|
48 |
+
for example in content['data']:
|
49 |
+
example_id = example.get('id', "").strip()
|
50 |
+
text = example.get('text', "").strip()
|
51 |
+
yield example_id, {
|
52 |
+
"id": example_id,
|
53 |
+
"text": text
|
54 |
+
}
|