Upload tasktemplates.py
Browse files- tasktemplates.py +30 -14
tasktemplates.py
CHANGED
@@ -85,20 +85,36 @@ class TaskTemplates(datasets.GeneratorBasedBuilder):
|
|
85 |
)
|
86 |
|
87 |
def _split_generators(self, dl_manager):
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
)
|
93 |
-
]
|
94 |
|
95 |
-
|
96 |
-
with open(data_url, 'r') as f:
|
97 |
-
data = yaml.safe_load(f)
|
98 |
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
)
|
86 |
|
87 |
def _split_generators(self, dl_manager):
|
88 |
+
urls_to_download = {
|
89 |
+
'train': []
|
90 |
+
}
|
91 |
+
for dataset in _DATASETS:
|
92 |
+
urls_to_download['train'].append(
|
93 |
+
f"{_PREFIX}{dataset}/templates.yaml")
|
94 |
+
|
95 |
+
downloaded_files = dl_manager.download_and_extract(urls_to_download)
|
96 |
+
splits = []
|
97 |
+
|
98 |
+
if "train" in downloaded_files:
|
99 |
+
splits.append(
|
100 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={
|
101 |
+
'filepath': downloaded_files["train"]})
|
102 |
)
|
|
|
103 |
|
104 |
+
return splits
|
|
|
|
|
105 |
|
106 |
+
def _generate_examples(self, filepath):
|
107 |
+
id = 0
|
108 |
+
for path in filepath:
|
109 |
+
with open(path, 'r') as file:
|
110 |
+
template = yaml.load(file, Loader=yaml.FullLoader)
|
111 |
+
for _, task_templates in template['templates'].items():
|
112 |
+
for task_template in task_templates:
|
113 |
+
yield id, {
|
114 |
+
"name": task_template['name'],
|
115 |
+
"input": task_template['input'],
|
116 |
+
"target": task_template['target'],
|
117 |
+
"languages": task_template['metadata']['languages'],
|
118 |
+
"metrics": task_template['metadata']['metrics']
|
119 |
+
}
|
120 |
+
id += 1
|