ivykopal commited on
Commit
7f11275
·
verified ·
1 Parent(s): 2f52420

Upload tasktemplates.py

Browse files
Files changed (1) hide show
  1. 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
- return [
89
- datasets.SplitGenerator(
90
- name=datasets.Split.TRAIN,
91
- gen_kwargs={"data_url": self.config.data_url}
 
 
 
 
 
 
 
 
 
 
92
  )
93
- ]
94
 
95
- def _generate_examples(self, data_url):
96
- with open(data_url, 'r') as f:
97
- data = yaml.safe_load(f)
98
 
99
- for task, templates in data.items():
100
- for template in templates:
101
- yield task, {
102
- "task": task,
103
- "templates": template
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