tensorflow中的lstm的state
考虑 state_is_tuple
Output, new_state = cell(input, state)
state其实是两个 一个 c state,一个m(对应下图的hidden 或者h) 其中m(hidden)其实也就是输出
new_state = (LSTMStateTuple(c, m) if self._state_is_tuple
else array_ops.concat(1, [c, m]))
return m, new_state
def basic_rnn_seq2seq(
encoder_inputs, decoder_inputs, cell, dtype=dtypes.float32, scope=None):
with variable_scope.variable_scope(scope or "basic_rnn_seq2seq"):
_, enc_state = rnn.rnn(cell, encoder_inputs, dtype=dtype)
return rnn_decoder(decoder_inputs, enc_state, cell)
def rnn_decoder(decoder_inputs, initial_state, cell, loop_function=None,
scope=None):
with variable_scope.variable_scope(scope or "rnn_decoder"):
state = initial_state
outputs = []
prev = None
for i, inp in enumerate(decoder_inputs):
if loop_function is not None and prev is not None:
with variable_scope.variable_scope("loop_function", reuse=True):
inp = loop_function(prev, i)
if i > 0:
variable_scope.get_variable_scope().reuse_variables()
output, state = cell(inp, state)
outputs.append(output)
if loop_function is not None:
prev = output
return outputs, state
这里decoder用了encoder的最后一个state 作为输入
然后输出结果是decoder过程最后的state 加上所有ouput的集合(也就是hidden的集合)
注意ouputs[-1]其实数值和state里面的m是一致的
当然有可能后面outputs 用dynamic rnn 会补0
encode_feature, state = melt.rnn.encode(
cell,
inputs,
seq_length,
encode_method=0,
output_method=3)
encode_feature.eval()
array([[[ 4.27834410e-03, 1.45841937e-03, 1.25767402e-02,
5.00775501e-03],
[ 6.24437723e-03, 2.60074623e-03, 2.32168660e-02,
9.47457738e-03],
[ 7.59789022e-03, -5.34060055e-05, 1.64511874e-02,
-5.71310846e-03],
[ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00]]], dtype=float32)
state[1].eval()
array([[ 7.59789022e-03, -5.34060055e-05, 1.64511874e-02,
-5.71310846e-03]], dtype=float32)
tensorflow中的lstm的state相关推荐
- tensorflow中对lstm及双向lstm的理解
双向RNN(LSTM)的实现参考: https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/3_Neural ...
- 从Tensorflow代码中理解LSTM网络
目录 RNN LSTM 参考文档与引子 缩略词 RNN (Recurrent neural network) 循环神经网络 LSTM (Long short-term memory) 长短期记忆人 ...
- TensorFlow中RNN实现的正确打开方式
上周写的文章<完全图解RNN.RNN变体.Seq2Seq.Attention机制>介绍了一下RNN的几种结构,今天就来聊一聊如何在TensorFlow中实现这些结构,这篇文章的主要内容为: ...
- tensorflow实现基于LSTM的文本分类方法
http://blog.csdn.net/u010223750/article/details/53334313?locationNum=7&fps=1 引言 学习一段时间的tensor fl ...
- Tensorflow之RNN,LSTM
Tensorflow之RNN,LSTM #!/usr/bin/env python2 # -*- coding: utf-8 -*- """ tensorflow之RNN ...
- TensorFlow中RNN实现的正确打开方式(转)
上周写的文章<完全图解RNN.RNN变体.Seq2Seq.Attention机制>介绍了一下RNN的几种结构,今天就来聊一聊如何在TensorFlow中实现这些结构,这篇文章的主要内容为: ...
- Tensorflow③ Keras的LSTM和TF的LSTM实现的源码剖析
最近在做可以转成pb模型的RNN/LSTM层的实现细节分析.经过一些分析,发现了在Keras里面常见的keras.layers.LSTM和Tensorflow的tf.contrib.rnn.LSTMC ...
- 在Tensorflow中使用深度学习构建图像标题生成器
by Cole Murray 通过科尔·默里(Cole Murray) 在Tensorflow中使用深度学习构建图像标题生成器 (Building an image caption generator ...
- python 预测任意天后股票数据_在Python中使用LSTM进行股票市场预测
本文概述 在本教程中, 你将看到如何使用称为长短期记忆的时间序列模型. LSTM模型功能强大, 特别是通过设计保留了长期记忆, 这一点将在以后看到.你将在本教程中解决以下主题: 了解为什么你需要能够预 ...
最新文章
- 文计笔记1: 计算机基本原理
- 一入爬虫深似海,反爬技术你知多少?
- Oracle查看死锁 .
- 使用富文本OHAttributedLabel
- IPC 共享内存和 消息队列(发送、接收、移除)以及键值的生成
- 常用的方法论-NPS
- 可以打开mdb文件的小软件
- 佐治亚理工学院 计算投资公开课第五周作业 市场仿真器
- 防蓝光膜真的能阻挡蓝光,减小辐射吗?
- HttpServletResponse类
- Linux查看安装了哪些软件
- css之div兼容性问题
- 基于灰色模型GM的管道腐蚀预测 - 附代码
- 开机连接WiFi显示无Internet连接但能上网且弹出“MSN中国”网页
- 从 Resource Hacker 到 Heaventools PE Explorer 1.99 R6
- 解决docker+openvpn搭建完成后客户端能连接,但是无法访问互联网或其他机器
- 2018秋北京松松兄弟线下聚会干货分享
- android studio基础教程:2.程序在哪写
- 为什么大数据使用相关关系而不是因果分析?
- 计算机不识别u盘咋办,电脑无法识别u盘如何修复,电脑不识别u盘怎么办