-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathcreate_hparam_set.py
40 lines (35 loc) · 1.67 KB
/
create_hparam_set.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
import yaml
def create_hparam_yml(TRAIN_BATCH_SIZE, TRAIN_EPOCHS, LEARNING_RATE, WEIGHT_DECAY, NUM_ATTENTION_HEADS, NUM_HIDDEN_LAYERS, save_to="hparams.yml"):
# Hyperparameters
hparams = {}
set_no = 0
for batch_size in TRAIN_BATCH_SIZE:
for num_epoch in TRAIN_EPOCHS:
for lr in LEARNING_RATE:
for wd in WEIGHT_DECAY:
for num_heads in NUM_ATTENTION_HEADS:
for num_layers in NUM_HIDDEN_LAYERS:
hparams["set_" + str(set_no)] = {
"TRAIN_BATCH_SIZE": batch_size,
"VALID_BATCH_SIZE": 8,
"TRAIN_EPOCHS": num_epoch,
"LEARNING_RATE": lr,
"WEIGHT_DECAY": wd,
"MAX_LEN": 128,
"VOCAB_SIZE": 800,
"MAX_POSITION_EMBEDDINGS": 514,
"NUM_ATTENTION_HEADS": num_heads,
"NUM_HIDDEN_LAYERS": num_layers,
"TYPE_VOCAB_SIZE": 1,
"HIDDEN_SIZE": 768,
}
set_no += 1
set_no += 1
set_no += 1
set_no += 1
set_no += 1
set_no += 1
# Write to yaml file
with open(save_to, "w") as f:
yaml.dump(hparams, f)
create_hparam_yml(TRAIN_BATCH_SIZE=[16, 32, 64], TRAIN_EPOCHS=[5, 10], LEARNING_RATE=[1e-5], WEIGHT_DECAY=[0.001], NUM_ATTENTION_HEADS=[4, 8], NUM_HIDDEN_LAYERS=[8, 12])