LSTM中的cell state 和 hidden state

TensorFlow中使用tf.contrib.rnn.BasicLSTMCell()的方法来搭建LSTM网络,其中有一项参数为state_is_tuple,官方建议设置为True,这个参数的实际就是使LSTM的state以tuple的形式输出,shape为batch size和num_step,也就是min batch的大小和LSTM展开的步数,而state分为c与h,c为cell state,即memory的state,h为hidden state,也就是lstm的最终输出。

LSTM单元根据输入的序列长度进行展开,当前时刻得到的state又作为参数传入下一时刻。代码如下:
 

        with tf.variable_scope("LSTM_layer"):
            for time_step in range(num_step):
                if time_step>0: 
                    tf.get_variable_scope().reuse_variables()
                    (cell_output, state)=cell(inputs[:,time_step,:],state)
                    out_put.append(cell_output)

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值