如何以编程方式添加多个LSTM单元格

时间:2017-07-20 19:58:07

标签: tensorflow neural-network lstm recurrent-neural-network

所以,这是我现有代码的一部分:

def lstm(i,o, state):
    input_gate = tf.sigmoid(tf.matmul(i, w_ii) + tf.matmul(o,w_io) + b_i)
    output_gate = tf.sigmoid(tf.matmul(i, w_oi) + tf.matmul(o,w_oo) + b_o)
    forget_gate = tf.sigmoid(tf.matmul(i, w_fi) + tf.matmul(o,w_fo) + b_f)
    memory_cell = tf.sigmoid(tf.matmul(i, w_ci) + tf.matmul(o,w_co) + b_c)

    state = forget_gate * state + input_gate * memory_cell

    output = output_gate * tf.tanh(state)
    return output, state

output = tf.zeros([batch_size, hidden_nodes])
state = tf.zeros([batch_size, hidden_nodes])

for i in range(len_section):
    output, state = lstm(data[:,i,:],output, state)

我已经开始运行,这是一个不错的开始,但我希望模仿另一个使用3个LSTM单元的模型。我不太确定我知道如何编码。

会是这样的:

for i in range(len_section):
    output, state = lstm(data[:,i,:],output, state)
    output, state = lstm(data[:,i,:],output, state)
    output, state = lstm(data[:,i,:],output, state)

非常感谢任何反馈

0 个答案:

没有答案