-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathicl_dataset_loading.py
168 lines (133 loc) · 7.48 KB
/
icl_dataset_loading.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import datasets
import pickle
def get_dataset(args):
if args.dataset == "ag_news":
train_dataset = datasets.load_dataset("ag_news")["train"]
test_dataset = datasets.load_dataset("ag_news")["test"]
options = ["World", "Sports", "Business", "Sci/Tech"]
template = "Article: {text}\nTopic: {answer}"
# add options to each example
train_dataset = train_dataset.map(lambda example: {**example, "options": options})
test_dataset = test_dataset.map(lambda example: {**example, "options": options})
input_keys = ["text"]
recalibrate_every = False
balanced_sampling = False
elif args.dataset == "glue/sst2" or args.dataset == "sst2":
train_dataset = datasets.load_dataset("glue", "sst2")["train"]
test_dataset = datasets.load_dataset("glue", "sst2")["validation"]
options = ["negative", "positive"]
template = "Sentence: {sentence}\nSentiment: {answer}"
# add options to each example
train_dataset = train_dataset.map(lambda example: {**example, "options": options})
test_dataset = test_dataset.map(lambda example: {**example, "options": options})
input_keys = ["sentence"]
recalibrate_every = False
balanced_sampling = True
elif args.dataset == "super_glue/boolq" or args.dataset == "boolq":
train_dataset = datasets.load_dataset("super_glue", "boolq")["train"]
test_dataset = datasets.load_dataset("super_glue", "boolq")["validation"]
options = ["incorrect", "correct"]
template = "{passage}\nquestion: {question}?\nanswer: {answer}"
# add options to each example
train_dataset = train_dataset.map(lambda example: {**example, "options": options})
test_dataset = test_dataset.map(lambda example: {**example, "options": options})
input_keys = ["passage"]
recalibrate_every = True
balanced_sampling = False
elif args.dataset == "super_glue/wic" or args.dataset == "wic":
train_dataset = datasets.load_dataset("super_glue", "wic")["train"]
test_dataset = datasets.load_dataset("super_glue", "wic")["validation"]
options = ["no", "yes"]
template = "{sentence1}\n{sentence2}\nquestion: Is the word '{word}' used the same way in the two sentences above?\nanswer: {answer}"
# add options to each example
train_dataset = train_dataset.map(lambda example: {**example, "options": options})
test_dataset = test_dataset.map(lambda example: {**example, "options": options})
input_keys = ["sentence1", "sentence2"]
recalibrate_every = True
balanced_sampling = False
elif args.dataset == "super_glue/wsc" or args.dataset == "wsc":
train_dataset = datasets.load_dataset("super_glue", "wsc")["train"]
test_dataset = datasets.load_dataset("super_glue", "wsc")["validation"]
options = ["no", "yes"]
template = "Question: In the sentence \"{text}\", does the pronoun '{span2_text}' refer to {span1_text}?\nAnswer: {answer}"
# add options to each example
train_dataset = train_dataset.map(lambda example: {**example, "options": options})
test_dataset = test_dataset.map(lambda example: {**example, "options": options})
input_keys = ["text"]
recalibrate_every = True
balanced_sampling = False
elif args.dataset == "super_glue/rte" or args.dataset == "rte":
train_dataset = datasets.load_dataset("super_glue", "rte")["train"]
test_dataset = datasets.load_dataset("super_glue", "rte")["validation"]
options = ["True", "False"]
template = "{premise}\nquestion: {hypothesis} True or False?\nanswer: {answer}"
# add options to each example
train_dataset = train_dataset.map(lambda example: {**example, "options": options})
test_dataset = test_dataset.map(lambda example: {**example, "options": options})
input_keys = ["hypothesis"]
recalibrate_every = True
balanced_sampling = False
elif args.dataset == "super_glue/cb" or args.dataset == "cb":
train_dataset = datasets.load_dataset("super_glue", "cb")["train"]
test_dataset = datasets.load_dataset("super_glue", "cb")["validation"]
options = ["true", "false", "neither"]
template = "{premise}\nquestion: {hypothesis}. true, false or neither?\nanswer: {answer}"
# add options to each example
train_dataset = train_dataset.map(lambda example: {**example, "options": options})
test_dataset = test_dataset.map(lambda example: {**example, "options": options})
input_keys = ["premise"]
recalibrate_every = True
balanced_sampling = True
elif args.dataset == "super_glue/copa" or args.dataset == "copa":
train_dataset = datasets.load_dataset("super_glue", "copa")["validation"]
test_dataset = datasets.load_dataset("super_glue", "copa")["train"]
template = "Context: {premise}\nAnswer: {answer}"
# add options to each example
train_dataset = train_dataset.map(lambda example: {**example, "options": [example["choice1"], example["choice2"]]})
test_dataset = test_dataset.map(lambda example: {**example, "options": [example["choice1"], example["choice2"]]})
input_keys = ["premise"]
recalibrate_every = True
balanced_sampling = True
elif args.dataset == "super_glue/multirc" or args.dataset == "multirc":
train_dataset = datasets.load_dataset("super_glue", "multirc")["train"]
test_dataset = datasets.load_dataset("super_glue", "multirc")["validation"]
options = ["incorrect", "correct"]
template = "Context: {paragraph}\n{question}\n{answer}\nanswer: {answer}"
# add options to each example
train_dataset = train_dataset.map(lambda example: {**example, "options": options})
test_dataset = test_dataset.map(lambda example: {**example, "options": options})
input_keys = ["paragraph"]
recalibrate_every = True
balanced_sampling = True
elif args.dataset == "subj":
train_dataset = datasets.load_dataset("SetFit/subj")["train"]
test_dataset = datasets.load_dataset("SetFit/subj")["test"]
options = ["objective", "subjective"]
template = "input: {text}\ntype: {answer}"
# add options to each example
train_dataset = train_dataset.map(lambda example: {**example, "options": options})
test_dataset = test_dataset.map(lambda example: {**example, "options": options})
input_keys = ["text"]
recalibrate_every = False
balanced_sampling = True
elif args.dataset == "mr":
train_dataset = datasets.load_dataset("rotten_tomatoes")["train"]
test_dataset = datasets.load_dataset("rotten_tomatoes")["test"]
options = ["negative", "positive"]
template = "Review: {text}\nSentiment: {answer}"
# add options to each example
train_dataset = train_dataset.map(lambda example: {**example, "options": options})
test_dataset = test_dataset.map(lambda example: {**example, "options": options})
input_keys = ["text"]
recalibrate_every = False
balanced_sampling = True
else:
raise NotImplementedError
return {
"train": train_dataset,
"test": test_dataset,
"template": template,
"input_keys": input_keys,
"recalibrate_every": recalibrate_every,
"balanced_sampling": balanced_sampling
}