-
Notifications
You must be signed in to change notification settings - Fork 9
/
init.lua
58 lines (53 loc) · 1.42 KB
/
init.lua
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
require('torch')
require('nn')
require('nngraph')
require('optim')
require('xlua')
require('sys')
require('lfs')
advnn = {}
stats = {}
printf = utils.printf
utils = {}
torch.setnumthreads(16)
include('util/read_data.lua')
include('util/Tree.lua')
include('util/Vocab.lua')
include('util/stats.lua')
include('util/nlptools.lua')
include('layers/CRowAddTable.lua')
include('models/LSTM.lua')
include('models/GRU.lua')
include('models/TreeGRU.lua')
include('models/TreeLSTM.lua')
include('models/ChildSumTreeLSTM.lua')
include('models/ChildSumTreeGRU.lua')
include('models/AttTreeGRU.lua')
include('models/AttTreeLSTM.lua')
include('train/Tester.lua')
include('train/Trainer.lua')
-- global paths (modify if desired)
utils.data_dir = 'data'
utils.models_dir = 'trained_models'
utils.predictions_dir = 'predictions'
-- share module parameters
function share_params(cell, src)
if torch.type(cell) == 'nn.gModule' then
for i = 1, #cell.forwardnodes do
local node = cell.forwardnodes[i]
if node.data.module then
node.data.module:share(src.forwardnodes[i].data.module,
'weight', 'bias', 'gradWeight', 'gradBias')
end
end
elseif torch.isTypeOf(cell, 'nn.Module') then
cell:share(src, 'weight', 'bias', 'gradWeight', 'gradBias')
else
error('parameters cannot be shared for this input')
end
end
function header(s)
print(string.rep('-', 80))
print(s)
print(string.rep('-', 80))
end