Upload load_config.py
Browse files- load_config.py +77 -0
load_config.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import csv
|
| 2 |
+
|
| 3 |
+
import datasets
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
_CITATION = """\
|
| 7 |
+
@article{hendryckstest2021,
|
| 8 |
+
title={Measuring Massive Multitask Language Understanding},
|
| 9 |
+
author={Dan Hendrycks and Collin Burns and Steven Basart and Andy Zou and Mantas Mazeika and Dawn Song and Jacob Steinhardt},
|
| 10 |
+
journal={Proceedings of the International Conference on Learning Representations (ICLR)},
|
| 11 |
+
year={2021}
|
| 12 |
+
}
|
| 13 |
+
"""
|
| 14 |
+
|
| 15 |
+
_DESCRIPTION = """\
|
| 16 |
+
Psycholinguistics word datasets
|
| 17 |
+
"""
|
| 18 |
+
|
| 19 |
+
_HOMEPAGE = "To Add"
|
| 20 |
+
|
| 21 |
+
_URL = "data.tar"
|
| 22 |
+
|
| 23 |
+
_SUBJECTS = [
|
| 24 |
+
"SimCat-TASLP2018"
|
| 25 |
+
]
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
class MyDatasets(datasets.GeneratorBasedBuilder):
|
| 29 |
+
"""Psycholinguistics word datasets"""
|
| 30 |
+
|
| 31 |
+
BUILDER_CONFIGS = [
|
| 32 |
+
datasets.BuilderConfig(
|
| 33 |
+
name=sub, version=datasets.Version("1.0.0"), description=f"Psycholinguistics Volcabulary Datasets {sub}"
|
| 34 |
+
)
|
| 35 |
+
for sub in _SUBJECTS
|
| 36 |
+
]
|
| 37 |
+
|
| 38 |
+
def _info(self):
|
| 39 |
+
features = datasets.Features(
|
| 40 |
+
{
|
| 41 |
+
"Word": datasets.Value("string"),
|
| 42 |
+
"Category": datasets.Value("string"),
|
| 43 |
+
}
|
| 44 |
+
)
|
| 45 |
+
return datasets.DatasetInfo(
|
| 46 |
+
description=_DESCRIPTION,
|
| 47 |
+
features=features,
|
| 48 |
+
homepage=_HOMEPAGE,
|
| 49 |
+
citation=_CITATION,
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
def _split_generators(self, dl_manager):
|
| 53 |
+
"""Returns SplitGenerators."""
|
| 54 |
+
archive = dl_manager.download(_URL)
|
| 55 |
+
return [
|
| 56 |
+
datasets.SplitGenerator(
|
| 57 |
+
name=datasets.Split.TEST,
|
| 58 |
+
# 传递给 _generate_examples 方法的参数
|
| 59 |
+
gen_kwargs={"iter_archive": dl_manager.iter_archive(archive), "split": "test"},
|
| 60 |
+
),
|
| 61 |
+
]
|
| 62 |
+
|
| 63 |
+
def _generate_examples(self, iter_archive, split):
|
| 64 |
+
"""Yields examples as (key, example) tuples."""
|
| 65 |
+
n_yielded_files = 0
|
| 66 |
+
for id_file, (path, file) in enumerate(iter_archive):
|
| 67 |
+
# For example, we iterate through the data folder and find a file with the path "data/test"
|
| 68 |
+
if f"data/{split}/" in path:
|
| 69 |
+
# For example, SimCat-TASLP2018_test.csv
|
| 70 |
+
if f"{self.config.name}_{split}.csv" in path:
|
| 71 |
+
n_yielded_files += 1
|
| 72 |
+
lines = (line.decode("utf-8") for line in file)
|
| 73 |
+
reader = csv.reader(lines)
|
| 74 |
+
for id_line, data in enumerate(reader):
|
| 75 |
+
yield f"{id_file}_{id_line}", {"Word": data[0], "Category": data[1]}
|
| 76 |
+
if n_yielded_files == 8:
|
| 77 |
+
break
|