-
Notifications
You must be signed in to change notification settings - Fork 145
/
config.py
112 lines (94 loc) · 4.34 KB
/
config.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
import numpy as np
class BabiConfig(object):
"""
Configuration for bAbI
"""
def __init__(self, train_story, train_questions, dictionary):
self.dictionary = dictionary
self.batch_size = 32
self.nhops = 3
self.nepochs = 100
self.lrate_decay_step = 25 # reduce learning rate by half every 25 epochs
# Use 10% of training data for validation
nb_questions = train_questions.shape[1]
nb_train_questions = int(nb_questions * 0.9)
self.train_range = np.array(range(nb_train_questions))
self.val_range = np.array(range(nb_train_questions, nb_questions))
self.enable_time = True # add time embeddings
self.use_bow = False # use Bag-of-Words instead of Position-Encoding
self.linear_start = True
self.share_type = 1 # 1: adjacent, 2: layer-wise weight tying
self.randomize_time = 0.1 # amount of noise injected into time index
self.add_proj = False # add linear layer between internal states
self.add_nonlin = False # add non-linearity to internal states
if self.linear_start:
self.ls_nepochs = 20
self.ls_lrate_decay_step = 21
self.ls_init_lrate = 0.01 / 2
# Training configuration
self.train_config = {
"init_lrate" : 0.01,
"max_grad_norm": 40,
"in_dim" : 20,
"out_dim" : 20,
"sz" : min(50, train_story.shape[1]), # number of sentences
"voc_sz" : len(self.dictionary),
"bsz" : self.batch_size,
"max_words" : len(train_story),
"weight" : None
}
if self.linear_start:
self.train_config["init_lrate"] = 0.01 / 2
if self.enable_time:
self.train_config.update({
"voc_sz" : self.train_config["voc_sz"] + self.train_config["sz"],
"max_words": self.train_config["max_words"] + 1 # Add 1 for time words
})
class BabiConfigJoint(object):
"""
Joint configuration for bAbI
"""
def __init__(self, train_story, train_questions, dictionary):
# TODO: Inherit from BabiConfig
self.dictionary = dictionary
self.batch_size = 32
self.nhops = 3
self.nepochs = 60
self.lrate_decay_step = 15 # reduce learning rate by half every 25 epochs # XXX:
# Use 10% of training data for validation # XXX
nb_questions = train_questions.shape[1]
nb_train_questions = int(nb_questions * 0.9)
# Randomly split to training and validation sets
rp = np.random.permutation(nb_questions)
self.train_range = rp[:nb_train_questions]
self.val_range = rp[nb_train_questions:]
self.enable_time = True # add time embeddings
self.use_bow = False # use Bag-of-Words instead of Position-Encoding
self.linear_start = True
self.share_type = 1 # 1: adjacent, 2: layer-wise weight tying
self.randomize_time = 0.1 # amount of noise injected into time index
self.add_proj = False # add linear layer between internal states
self.add_nonlin = False # add non-linearity to internal states
if self.linear_start:
self.ls_nepochs = 30 # XXX:
self.ls_lrate_decay_step = 31 # XXX:
self.ls_init_lrate = 0.01 / 2
# Training configuration
self.train_config = {
"init_lrate" : 0.01,
"max_grad_norm": 40,
"in_dim" : 50, # XXX:
"out_dim" : 50, # XXX:
"sz" : min(50, train_story.shape[1]),
"voc_sz" : len(self.dictionary),
"bsz" : self.batch_size,
"max_words" : len(train_story),
"weight" : None
}
if self.linear_start:
self.train_config["init_lrate"] = 0.01 / 2
if self.enable_time:
self.train_config.update({
"voc_sz" : self.train_config["voc_sz"] + self.train_config["sz"],
"max_words": self.train_config["max_words"] + 1 # Add 1 for time words
})