Update data.py
Browse files
data.py
CHANGED
|
@@ -1,52 +1,31 @@
|
|
| 1 |
import datasets
|
| 2 |
import tasksource
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
"""
|
| 9 |
-
result = {}
|
| 10 |
-
for kv in query.split(","):
|
| 11 |
-
parts = kv.split("=")
|
| 12 |
-
if parts[1].isdigit():
|
| 13 |
-
result[parts[0]] = int(parts[1])
|
| 14 |
-
elif parts[1].replace(".", "", 1).isdigit():
|
| 15 |
-
result[parts[0]] = float(parts[1])
|
| 16 |
-
|
| 17 |
-
result[parts[0]] = parts[1]
|
| 18 |
-
|
| 19 |
-
return result
|
| 20 |
|
| 21 |
|
| 22 |
class Dataset(datasets.GeneratorBasedBuilder):
|
| 23 |
|
| 24 |
builder_configs = {}
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
if not hasattr(self, "_generators") or self._generators is None:
|
| 30 |
-
recipe = fetch(self.config.name)
|
| 31 |
-
if recipe is None:
|
| 32 |
-
args = parse(self.config.name)
|
| 33 |
-
if "type" not in args:
|
| 34 |
-
args["type"] = "common_recipe"
|
| 35 |
-
recipe = Artifact.from_dict(args)
|
| 36 |
-
self._generators = recipe()
|
| 37 |
-
return self._generators
|
| 38 |
-
|
| 39 |
def _info(self):
|
| 40 |
return datasets.DatasetInfo()
|
| 41 |
|
| 42 |
def _split_generators(self, _):
|
| 43 |
-
return ["train
|
| 44 |
|
| 45 |
def _generate_examples(self, split_name):
|
| 46 |
-
|
| 47 |
-
for
|
| 48 |
-
|
|
|
|
| 49 |
|
| 50 |
def _download_and_prepare(self, dl_manager, verification_mode, **prepare_splits_kwargs):
|
| 51 |
result = super()._download_and_prepare(dl_manager, "no_checks", **prepare_splits_kwargs)
|
| 52 |
-
return result
|
|
|
|
| 1 |
import datasets
|
| 2 |
import tasksource
|
| 3 |
|
| 4 |
+
class DotDict(dict):
|
| 5 |
+
__getattr__ = dict.get
|
| 6 |
+
__setattr__ = dict.__setitem__
|
| 7 |
+
__delattr__ = dict.__delitem__
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
|
| 10 |
class Dataset(datasets.GeneratorBasedBuilder):
|
| 11 |
|
| 12 |
builder_configs = {}
|
| 13 |
+
def __init__(self,*args,**kwargs):
|
| 14 |
+
self.BUILDER_CONFIG_CLASS.__post_init__=lambda x:x
|
| 15 |
+
return super().__init__(*args,**kwargs)
|
| 16 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
def _info(self):
|
| 18 |
return datasets.DatasetInfo()
|
| 19 |
|
| 20 |
def _split_generators(self, _):
|
| 21 |
+
return [datasets.SplitGenerator(name=name, gen_kwargs={"split_name": name}) for name in ['train','validation','test']]
|
| 22 |
|
| 23 |
def _generate_examples(self, split_name):
|
| 24 |
+
i=0
|
| 25 |
+
for x in tasksource.load_task(self.config.name)[split_name]:
|
| 26 |
+
i+=1
|
| 27 |
+
yield i,x
|
| 28 |
|
| 29 |
def _download_and_prepare(self, dl_manager, verification_mode, **prepare_splits_kwargs):
|
| 30 |
result = super()._download_and_prepare(dl_manager, "no_checks", **prepare_splits_kwargs)
|
| 31 |
+
return result
|