aboutsummaryrefslogtreecommitdiff
path: root/nerv/layer/rnn.lua
blob: 806ac589cff464f7e7dc093c3d36649617a635c4 (plain) (blame)
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
local RNNLayer = nerv.class('nerv.RNNLayer', 'nerv.GraphLayer')

function RNNLayer:__init(id, global_conf, layer_conf)
    self.id = id
    self.dim_in = layer_conf.dim_in
    self.dim_out = layer_conf.dim_out
    self.gconf = layer_conf.gconf
    self:check_dim_len(1, 1)

    local din = layer_conf.dim_in[1]
    local dout = layer_conf.dim_out[1]

    local pr = layer_conf.pr
    if pr == nil then
        pr = nerv.ParamRepo()
    end

    local layers = {
        ['nerv.AffineLayer'] = {
            main = {dim_in = {din, dout}, dim_out = {dout}, pr = pr},
        },
        ['nerv.SigmoidLayer'] = {
            sigmoid = {dim_in = {dout}, dim_out = {dout}},
        },
        ['nerv.DuplicateLayer'] = {
            dup = {dim_in = {dout}, dim_out = {dout, dout}},
        }
    }

    local layer_repo = nerv.LayerRepo(layers, pr, global_conf)

    local connections = {
        {'<input>[1]', 'main[1]', 0},
        {'main[1]', 'sigmoid[1]', 0},
        {'sigmoid[1]', 'dup[1]', 0},
        {'dup[1]', 'main[2]', 1},
        {'dup[2]', '<output>[1]', 0},
    }

    self:graph_init(layer_repo, connections)
end