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

当state_is_tuple = True时如何设置TensorFlow RNN状态?

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

当state_is_tuple = True时如何设置TensorFlow RNN状态?

Tensorflow占位符的一个问题是,您只能使用Python列表或Numpy数组来提供它(我认为)。因此,您无法在LSTMStateTuple的元组中保存两次运行之间的状态。

我通过将状态保存在这样的张量中解决了这个问题

initial_state = np.zeros((num_layers, 2, batch_size, state_size))

在LSTM层中有两个组件, 单元状态隐藏状态 ,这就是“
2”的含义。(这篇文章很棒:https :
//arxiv.org/pdf/1506.00019.pdf)

构建图时,您将解压缩并创建元组状态,如下所示:

state_placeholder = tf.placeholder(tf.float32, [num_layers, 2, batch_size, state_size])l = tf.unpack(state_placeholder, axis=0)rnn_tuple_state = tuple(         [tf.nn.rnn_cell.LSTMStateTuple(l[idx][0],l[idx][1])          for idx in range(num_layers)])

然后您以通常的方式获得新状态

cell = tf.nn.rnn_cell.LSTMCell(state_size, state_is_tuple=True)cell = tf.nn.rnn_cell.MultiRNNCell([cell] * num_layers, state_is_tuple=True)outputs, state = tf.nn.dynamic_rnn(cell, series_batch_input, initial_state=rnn_tuple_state)

可能不应该这样……也许他们正在研究解决方案。



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

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

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