Create new file
Browse files- test_pq.py +45 -0
test_pq.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import datasets
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
_CITATION = """\
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
_DESCRIPTION = """\
|
| 8 |
+
This is a test dataset.
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
_URLS = {
|
| 12 |
+
"train": "https://huggingface.co/datasets/changxin/test_pq/main/another_text.txt", # absolute
|
| 13 |
+
"dev": "some_text.txt", # relative
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
class Test(datasets.GeneratorBasedBuilder):
|
| 18 |
+
"""SQUAD: The Stanford Question Answering Dataset. Version 1.1."""
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def _info(self):
|
| 22 |
+
return datasets.DatasetInfo(
|
| 23 |
+
description=_DESCRIPTION,
|
| 24 |
+
features=datasets.Features(
|
| 25 |
+
{
|
| 26 |
+
"text": datasets.Value("string"),
|
| 27 |
+
}
|
| 28 |
+
),
|
| 29 |
+
supervised_keys=None,
|
| 30 |
+
homepage="https://huggingface.co/datasets/changxin/test_pq",
|
| 31 |
+
citation=_CITATION,
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
def _split_generators(self, dl_manager):
|
| 35 |
+
downloaded_files = dl_manager.download_and_extract(_URLS)
|
| 36 |
+
|
| 37 |
+
return [
|
| 38 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
|
| 39 |
+
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}),
|
| 40 |
+
]
|
| 41 |
+
|
| 42 |
+
def _generate_examples(self, filepath):
|
| 43 |
+
"""This function returns the examples in the raw (text) form."""
|
| 44 |
+
for _id, line in enumerate(open(filepath, encoding="utf-8")):
|
| 45 |
+
yield _id, {"text": line.rstrip()}
|