-
Notifications
You must be signed in to change notification settings - Fork 25
/
configs.py
295 lines (262 loc) · 6.89 KB
/
configs.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
"""
Defines Task parameters for notable experiment configurations.
Notes:
* A "task" MUST be specified in the config dictionary.
* Other values are optional and task-specific. They are used to
specify values for parameters in a Task constructor.
* Controller_type, model_type, and struct_type should not be specified
here. They can be set with command-line arguments.
A config can be run with:
python run.py CONFIG_NAME
"""
from formalisms.cfg import *
from stacknn_utils.data_readers import *
from tasks import *
from torch.nn import CrossEntropyLoss
""" Configs for the Final Paper """
# 1) Reverse task.
final_reverse_config = {
"task": ReverseTask,
"epochs": 100,
"early_stopping_steps": 5,
"read_size": 2
}
# 2) XOR/parity evaluation task.
final_parity_config = {
"task": XORTask,
"epochs": 100,
"early_stopping_steps": 5,
"read_size": 6
}
# 3) Delayed XOR/parity evaluation task.
final_delayed_parity_config = {
"task": DelayedXORTask,
"epochs": 100,
"early_stopping_steps": 5,
"read_size": 6
}
# 4) Dyck language modeling task.
final_dyck_config = {
"task": CFGTask,
"epochs": 100,
"early_stopping_steps": 5,
"grammar": dyck_grammar_2,
"to_predict": [u")", u"]"],
"sample_depth": 6,
"max_length": 20,
"read_size": 2,
"criterion": CrossEntropyLoss(reduction="none"),
"test_override": {
"sample_depth": 12,
"max_length": 110,
"sentence_count": 1000
}
}
# 5) Agreement grammar task.
final_agreement_config = {
"task": CFGTask,
"epochs": 100,
"early_stopping_steps": 5,
"grammar": unambig_agreement_grammar,
"to_predict": [u"Auxsing", u"Auxplur"],
"sample_depth": 16,
"read_size": 2,
"criterion": CrossEntropyLoss(reduction="none")
}
# 5b) Agreement grammar task with longer early stopping
final_agreement_config_10 = {
"task": CFGTask,
"epochs": 100,
"early_stopping_steps": 10,
"grammar": unambig_agreement_grammar,
"to_predict": [u"Auxsing", u"Auxplur"],
"sample_depth": 16,
"read_size": 2,
"criterion": CrossEntropyLoss(reduction="none")
}
# 6) Reverse Polish notation formula task.
final_formula_config = {
"task": CFGTransduceTask,
"epochs": 100,
"early_stopping_steps": 5,
"grammar": exp_eval_grammar,
"to_predict": [u"0", u"1"],
"sample_depth": 6,
"read_size": 2,
"max_length": 32,
"criterion": CrossEntropyLoss(reduction="none")
}
# 7) Reverse with deletion task.
final_reverse_deletion_config = {
"task": ReverseDeletionTask,
"epochs": 1,
"early_stopping_steps": 5,
"read_size": 2,
"num_symbols": 4
}
""" Testing Configs """
# 1) Reverse task.
testing_reverse_config = {
"task": ReverseTask,
"epochs": 1,
"early_stopping_steps": 5,
"read_size": 2,
"min_length": 1,
"max_length": 24,
"mean_length": 20,
"std_length": 4.
}
# 2) XOR/parity evaluation task.
testing_parity_config = {
"task": XORTask,
"epochs": 1,
"early_stopping_steps": 5,
"read_size": 6,
"str_length": 24
}
# 3) Delayed XOR/parity evaluation task.
testing_delayed_parity_config = {
"task": DelayedXORTask,
"epochs": 1,
"early_stopping_steps": 5,
"read_size": 6,
"str_length": 24
}
# 4) Dyck language modeling task.
testing_dyck_config = {
"task": CFGTask,
"epochs": 1,
"early_stopping_steps": 5,
"grammar": dyck_grammar_2,
"to_predict": [u")", u"]"],
"sample_depth": 5,
"read_size": 2,
"max_length": 128,
}
# 5) Agreement grammar task.
testing_agreement_config = {
"task": CFGTask,
"epochs": 1,
"early_stopping_steps": 5,
"grammar": unambig_agreement_grammar,
"to_predict": [u"Auxsing", u"Auxplur"],
"sample_depth": 5,
"read_size": 2,
"max_length": 64,
}
# 5b) Agreement grammar task with longer early stopping
testing_agreement_config_10 = {
"task": CFGTask,
"epochs": 1,
"early_stopping_steps": 10,
"grammar": unambig_agreement_grammar,
"to_predict": [u"Auxsing", u"Auxplur"],
"sample_depth": 5,
"read_size": 2,
"max_length": 64,
}
# 6) Reverse Polish notation formula task.
testing_formula_config = {
"task": CFGTransduceTask,
"epochs": 1,
"early_stopping_steps": 5,
"grammar": exp_eval_grammar,
"to_predict": [u"0", u"1"],
"sample_depth": 5,
"read_size": 2,
"max_length": 48,
}
# 7) Reverse with deletion task.
testing_reverse_deletion_config = {
"task": ReverseDeletionTask,
"epochs": 1,
"early_stopping_steps": 5,
"read_size": 2,
"num_symbols": 4,
"min_length": 1,
"max_length": 24,
"mean_length": 20,
"std_length": 4.
}
""" Configs Not Included in the Paper """
old_final_dyck_config = {
"task": CFGTask,
"epochs": 100,
"early_stopping_steps": 5,
"grammar": dyck_grammar,
"to_predict": [u")", u"]"],
"sample_depth": 5,
"read_size": 2
}
# Reverse task formulated as CFG.
reverse_cfg = {
"task": CFGTask,
"grammar": reverse_grammar,
"to_predict": [u"a1", u"b1"],
"sample_depth": 12,
}
# Unambiguous agreement grammar task.
unambig_agreement_config = {
"task": CFGTask,
"grammar": unambig_agreement_grammar,
"to_predict": [u"Auxsing", u"Auxplur"],
"sample_depth": 16,
}
# Buffered parity evaluation with t steps.
parity_config_t = {
"task": XORTask,
"read_size": 6,
"time_function": lambda t: t,
}
# 1) Reverse task that runs really quickly.
quick_reverse_config = {
"task": ReverseTask,
"epochs": 1,
"early_stopping_steps": 5,
"read_size": 2
}
""" Configs for Will's senior thesis. """
# 1) Extreme reverse task.
extreme_reverse_config = {
"task": ReverseTask,
"hidden_size": 8,
"mean_length": 50,
"max_length": 80,
"std_length": 5,
"epochs": 300,
"early_stopping_steps": 5,
"read_size": 2
}
# 2) a^nb^n.
anbn_config = {
"task": OrderedCountingTask,
"length_fns": [lambda n: n, lambda n: n],
"hidden_size": 1,
}
# 3) a^nb^{2n}.
anb2n_config = {
"task": OrderedCountingTask,
"length_fns": [lambda n: n, lambda n: 2 * n],
"hidden_size": 1,
}
"""Tasks using datasets."""
linzen_agreement_config = {
"task": NaturalTask,
"train_path": "data/linzen/rnn_agr_simple/numpred.train",
"test_path": "data/linzen/rnn_agr_simple/numpred.val",
"data_reader": ByLineDatasetReader(linzen_line_consumer),
"num_labels": 2,
"batch_size": 100, # 16,
"embedding_dim": 50,
"read_size": 50,
"hidden_size": 50,
"learning_rate": .01, # .001, # Learning rate from paper/default for Adam.
"l2_weight": 0, # Maybe add this back in to prevent overfitting.
"reg_weight": None,
"verbosity": 1000,
# Whether or not our custom initialization is used for RNNs.
"custom_initialization": False,
# This setting means we want to train a binary sigmoid classifier for the
# "VBZ" label instead of the standard multiclass softmax.
# "binary_label": "VBZ",
}