使用theano的LSTM实现

时间:2014-11-24 13:47:28

标签: neural-network theano deep-learning lstm

我正在使用theano扫描功能来实现LSTM(长期短期内存),但我得到了错误

ValueError: Please provide None as outputs_info for any output that does not feed back into scan (i.e. it behaves like a map) 

我像这样使用扫描

p_c = T.matrix()
p_hidden_inputs = T.matrix()
out, updates = scan(step_fprop,
                sequences=model_inputs,
                outputs_info= [p_c, p_hidden_inputs],
                non_sequences=
                [
                Wxi, Whi, Wci, bi,
                Wxf, Whf, Wcf, bf,
                Wxc, Whc, bc,
                Wxo, Who, Wco, bo
                ],
                n_steps=n_steps,
                )

和step_fprop的定义如下:

def step_fprop(inputs, p_c, p_hidden_inputs,
           Wxi, Whi, Wci, bi,
           Wxf, Whf, Wcf, bf,
           Wxc, Whc, bc,
           Wxo, Who, Wco, bo
           ):
"""
Construct the forward propagation
:return:
:rtype:
"""
# input gate
ig = T.nnet.sigmoid(T.dot(inputs, Wxi) +
                    T.dot(p_hidden_inputs, Whi) +
                    T.dot(p_c, Wci) +
                    bi)

# forget gate
fg = T.nnet.sigmoid(T.dot(inputs, Wxf) +
                    T.dot(p_hidden_inputs, Whf) +
                    T.dot(p_c, Wcf) +
                    bf)

# cell
cc= fg * p_c + ig * T.tanh(T.dot(inputs, Wxc) +
                                T.dot(p_hidden_inputs, Whc ) +
                                bc)

#output gate
og = T.nnet.sigmoid(T.dot(inputs, Wxo) +
                    T.dot(p_hidden_inputs,Who)  +
                    T.dot(p_c, Wco) +
                    bo)

#hidden state
hh = og * T.tanh(cc)

return hh

任何人都知道我为什么会遇到这种错误。

1 个答案:

答案 0 :(得分:2)

outputs_info期望在return函数的step_fprop中传递的每个变量的值。您的代码似乎只返回隐藏状态hh,但ouputs_info需要两个值,其初始状态由p_cp_hidden_inputs定义

看起来你在step_fprop函数中需要return [_whatever_previous_lstm_state, hh]