考虑 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的更多相关文章

  1. 在TensorFlow中基于lstm构建分词系统笔记

    在TensorFlow中基于lstm构建分词系统笔记(一) https://www.jianshu.com/p/ccb805b9f014 前言 我打算基于lstm构建一个分词系统,通过这个例子来学习下 ...

  2. 以lstm+ctc对汉字识别为例对tensorflow 中的lstm,ctc loss的调试

    #-*-coding:utf8-*- __author = "buyizhiyou" __date = "2017-11-21" ''' 单步调试,结合汉字的识 ...

  3. tensorflow实现基于LSTM的文本分类方法

    tensorflow实现基于LSTM的文本分类方法 作者:u010223750 引言 学习一段时间的tensor flow之后,想找个项目试试手,然后想起了之前在看Theano教程中的一个文本分类的实 ...

  4. 第二十二节,TensorFlow中RNN实现一些其它知识补充

    一 初始化RNN 上一节中介绍了 通过cell类构建RNN的函数,其中有一个参数initial_state,即cell初始状态参数,TensorFlow中封装了对其初始化的方法. 1.初始化为0 对于 ...

  5. 一文详解如何用 TensorFlow 实现基于 LSTM 的文本分类(附源码)

    雷锋网按:本文作者陆池,原文载于作者个人博客,雷锋网已获授权. 引言 学习一段时间的tensor flow之后,想找个项目试试手,然后想起了之前在看Theano教程中的一个文本分类的实例,这个星期就用 ...

  6. TensorFlow中实现RNN,彻底弄懂time_step

    这篇博客不是一篇讲解原理的博客,这篇博客主要讲解tnesorlfow的RNN代码结构,通过代码来学习RNN,以及讲解time_steps,如果这篇博客没有让你明白time_steps,欢迎博客下面评论 ...

  7. Python中利用LSTM模型进行时间序列预测分析

    时间序列模型 时间序列预测分析就是利用过去一段时间内某事件时间的特征来预测未来一段时间内该事件的特征.这是一类相对比较复杂的预测建模问题,和回归分析模型的预测不同,时间序列模型是依赖于事件发生的先后顺 ...

  8. TensorFlow中的变量和常量

    1.TensorFlow中的变量和常量介绍 TensorFlow中的变量: import tensorflow as tf state = tf.Variable(0,name='counter') ...

  9. TensorFlow中数据读取之tfrecords

    关于Tensorflow读取数据,官网给出了三种方法: 供给数据(Feeding): 在TensorFlow程序运行的每一步, 让Python代码来供给数据. 从文件读取数据: 在TensorFlow ...

随机推荐

  1. python api

    import requests #查询手机好归属地API def phone(tel): url = 'http://op.juhe.cn/onebox/phone/query' appkey = ' ...

  2. Oracle 删除重复数据只留一条

    查询及删除重复记录的SQL语句   1.查找表中多余的重复记录,重复记录是根据单个字段(Id)来判断   select * from 表 where Id in (select Id from 表 g ...

  3. bootstrap中popover.js(弹出框)使用总结+案例

    bootstrap中popover.js(弹出框)使用总结+案例 *转载请注明出处: 作者:willingtolove: http://www.cnblogs.com/willingtolove/p/ ...

  4. temp

    netstat -tlnap lsof -i :40735 ps -ef|grep 10259 iftop iptraf nethogs gidxylxhqp http://blog.csdn.net ...

  5. Sentiment Analysis resources

    Wikipedia: Sentiment analysis (also known as opinion mining) refers to the use of natural language p ...

  6. db2、Oracle存储过程引号用法

      在存储过程中,单引号有两个作用,一是字符串是由单引号引用,二是转义.单引号的使用是就近配对,即就近原则.而在单引号充当转义角色时相对不好理解     1.从第二个单引号开始被视为转义符,如果第二个 ...

  7. 基于thinkphp的数组分页

    function array_page($array,$rows){ import("ORG.Util.Page"); //导入分页类 $count=count($array); ...

  8. Discoverer 11.1.1.3.0以Oracle Application用户登录的必要配置

    客户这边要使用Discoverer来出报表, 就从OTN上下载安装了11.1.1.3.0版本的, 安装很简单, 一路Next, 使用的EBS版本是12.1.1.3, 结果发现用Oracle Appli ...

  9. c#生成二维码

            String link ="www.baidu.com";//这里一般是一个链接 封装后的方法,直接调用就可以了  public void CreateQRCode ...

  10. 李炎恢《PHP第二季视频教程》之总结

    课时 <面向对象工具[1]>. 语法: __autoload.  __call.__tostring.__clone 1.   autoload 自动引用类.不用包含类,call屏蔽调用类 ...