栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Tensorflow LSTM中的c_state和m_state是什么?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Tensorflow LSTM中的c_state和m_state是什么?

我偶然发现了同样的问题,这就是我的理解方式!简约的LSTM示例:

import tensorflow as tfsample_input = tf.constant([[1,2,3]],dtype=tf.float32)LSTM_CELL_SIZE = 2lstm_cell = tf.nn.rnn_cell.BasicLSTMCell(LSTM_CELL_SIZE, state_is_tuple=True)state = (tf.zeros([1,LSTM_CELL_SIZE]),)*2output, state_new = lstm_cell(sample_input, state)init_op = tf.global_variables_initializer()sess = tf.Session()sess.run(init_op)print sess.run(output)

请注意,

state_is_tuple=True
因此在传递
state
给this时
cell
,它必须采用
tuple
表格形式。
c_state
并且
m_state
可能是“内存状态”和“单元状态”,尽管老实说我不确定,因为这些术语仅在文档中提及。在代码和文件中,关于
LSTM
-字母
h
c
通常用于表示“输出值”和“单元状态”。
http://colah.github.io/posts/2015-08-Understanding-
LSTMs/

这些张量表示单元的组合内部状态,应该一起传递。这样做的旧方法是简单地将它们连接起来,而新方法是使用元组。

旧方法:

lstm_cell = tf.nn.rnn_cell.BasicLSTMCell(LSTM_CELL_SIZE, state_is_tuple=False)state = tf.zeros([1,LSTM_CELL_SIZE*2])output, state_new = lstm_cell(sample_input, state)

新方法:

lstm_cell = tf.nn.rnn_cell.BasicLSTMCell(LSTM_CELL_SIZE, state_is_tuple=True)state = (tf.zeros([1,LSTM_CELL_SIZE]),)*2output, state_new = lstm_cell(sample_input, state)

因此,基本上我们所做的一切,都

state
从长度的1张量更改为长度的
4
2张量
2
。内容保持不变。
[0,0,0,0]
成为
([0,0],[0,0])
。(这应该使其速度更快)



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/516906.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号