def rnn_ff(inps, dim, hidden, batSize, prefix, params, names):
Wx = theano.shared(randomMatrix(dim, hidden))
Wh = theano.shared(randomMatrix(hidden, hidden))
bh = theano.shared(numpy.zeros(hidden, dtype=theano.config.floatX))
#model.container['bi_h0'] = theano.shared(numpy.zeros(model.container['nh'], dtype=theano.config.floatX))
# bundle
params += [ Wx, Wh, bh ] #, model.container['bi_h0']
names += [ prefix + '_Wx', prefix + '_Wh', prefix + '_bh' ] #, 'bi_h0'
def recurrence(x_t, h_tm1):
h_t = T.nnet.sigmoid(T.dot(x_t, Wx) + T.dot(h_tm1, Wh) + bh)
return h_t
h, _ = theano.scan(fn=recurrence, \
sequences=inps, outputs_info=[T.alloc(0., batSize, hidden)], n_steps=inps.shape[0])
return h
评论列表
文章目录