Upload tasktemplates.py
Browse files- tasktemplates.py +104 -0
tasktemplates.py
ADDED
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# download templates from the github repository
|
2 |
+
import yaml
|
3 |
+
import datasets
|
4 |
+
|
5 |
+
|
6 |
+
_PREFIX = 'https://raw.githubusercontent.com/ivanvykopal/tasktemplates/master/src/templates/'
|
7 |
+
|
8 |
+
_DATASETS = [
|
9 |
+
'aeslc',
|
10 |
+
'anli',
|
11 |
+
'billsum',
|
12 |
+
'boolq',
|
13 |
+
'c4',
|
14 |
+
'cb',
|
15 |
+
'cnn_dailymail',
|
16 |
+
'cola',
|
17 |
+
'common_gen',
|
18 |
+
'copa',
|
19 |
+
'cosmos_qa',
|
20 |
+
'cxc',
|
21 |
+
'doc_nli',
|
22 |
+
'drop',
|
23 |
+
'gigaword',
|
24 |
+
'hellaswag',
|
25 |
+
'hotpot_qa',
|
26 |
+
'mnli',
|
27 |
+
'mrpc',
|
28 |
+
'mrqa',
|
29 |
+
'multirc',
|
30 |
+
'multi_news',
|
31 |
+
'multi_nli',
|
32 |
+
'newsqa',
|
33 |
+
'newsroom',
|
34 |
+
'nq_open',
|
35 |
+
'piqa',
|
36 |
+
'qnli',
|
37 |
+
'qqp',
|
38 |
+
'race',
|
39 |
+
'record',
|
40 |
+
'rte',
|
41 |
+
'samsum',
|
42 |
+
'search_qa',
|
43 |
+
'snli',
|
44 |
+
'social_i_qa',
|
45 |
+
'squad',
|
46 |
+
'sst2',
|
47 |
+
'stsb',
|
48 |
+
'wic',
|
49 |
+
'wiki_auto',
|
50 |
+
'wiki_lingua',
|
51 |
+
'winogrande',
|
52 |
+
'wnli',
|
53 |
+
'wsc',
|
54 |
+
'xsum'
|
55 |
+
]
|
56 |
+
|
57 |
+
|
58 |
+
class TaskTemplatesConfig(datasets.BuilderConfig):
|
59 |
+
def __init__(self, data_url, **kwargs):
|
60 |
+
super(TaskTemplatesConfig, self).__init__(**kwargs)
|
61 |
+
|
62 |
+
self.data_url = data_url
|
63 |
+
|
64 |
+
|
65 |
+
class TaskTemplates(datasets.GeneratorBasedBuilder):
|
66 |
+
VERSION = datasets.Version("1.0.0")
|
67 |
+
BUILDER_CONFIGS = [
|
68 |
+
TaskTemplatesConfig(
|
69 |
+
name=dataset,
|
70 |
+
version=datasets.Version("1.0.0"),
|
71 |
+
data_url=f"{_PREFIX}{dataset}/templates.yaml"
|
72 |
+
) for dataset in _DATASETS
|
73 |
+
]
|
74 |
+
BUILDER_CONFIG_CLASS = TaskTemplatesConfig
|
75 |
+
|
76 |
+
def _info(self):
|
77 |
+
return datasets.DatasetInfo(
|
78 |
+
description="Task templates for various NLP tasks",
|
79 |
+
features=datasets.Features(
|
80 |
+
{
|
81 |
+
"task": datasets.Value("string"),
|
82 |
+
"templates": datasets.Sequence(datasets.Value("string"))
|
83 |
+
}
|
84 |
+
),
|
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 |
+
}
|