tf.nn.rnn_cell.MultiRNNCell

时间:2021-07-29 22:20:08

Class tf.contrib.rnn.MultiRNNCell  新版

Class tf.nn.rnn_cell.MultiRNNCell

构建多隐层神经网络

__init__(cells, state_is_tuple=True)

cells:rnn cell 的list

state_is_tuple:true,状态Ct和ht就是分开记录,放在一个tuple中,接受和返回的states是n-tuples,其中n=len(cells),False,states是concatenated沿着列轴.后者即将弃用。

BasicLSTMCell 单隐层

tf.nn.rnn_cell.MultiRNNCell

BasicLSTMCell 多隐层

tf.nn.rnn_cell.MultiRNNCell

代码示例

# encoding:utf-8
import tensorflow as tf batch_size=10
depth=128 inputs=tf.Variable(tf.random_normal([batch_size,depth])) previous_state0=(tf.random_normal([batch_size,100]),tf.random_normal([batch_size,100]))
previous_state1=(tf.random_normal([batch_size,200]),tf.random_normal([batch_size,200]))
previous_state2=(tf.random_normal([batch_size,300]),tf.random_normal([batch_size,300])) num_units=[100,200,300]
print(inputs) cells=[tf.nn.rnn_cell.BasicLSTMCell(num_unit) for num_unit in num_units]
mul_cells=tf.nn.rnn_cell.MultiRNNCell(cells) outputs,states=mul_cells(inputs,(previous_state0,previous_state1,previous_state2)) print(outputs.shape) #(10, 300)
print(states[0]) #第一层LSTM
print(states[1]) #第二层LSTM
print(states[2]) ##第三层LSTM
print(states[0].h.shape) #第一层LSTM的h状态,(10, 100)
print(states[0].c.shape) #第一层LSTM的c状态,(10, 100)
print(states[1].h.shape) #第二层LSTM的h状态,(10, 200)

输出

(10, 300)
LSTMStateTuple(c=<tf.Tensor 'multi_rnn_cell/cell_0/basic_lstm_cell/Add_1:0' shape=(10, 100) dtype=float32>, h=<tf.Tensor 'multi_rnn_cell/cell_0/basic_lstm_cell/Mul_2:0' shape=(10, 100) dtype=float32>)
LSTMStateTuple(c=<tf.Tensor 'multi_rnn_cell/cell_1/basic_lstm_cell/Add_1:0' shape=(10, 200) dtype=float32>, h=<tf.Tensor 'multi_rnn_cell/cell_1/basic_lstm_cell/Mul_2:0' shape=(10, 200) dtype=float32>)
LSTMStateTuple(c=<tf.Tensor 'multi_rnn_cell/cell_2/basic_lstm_cell/Add_1:0' shape=(10, 300) dtype=float32>, h=<tf.Tensor 'multi_rnn_cell/cell_2/basic_lstm_cell/Mul_2:0' shape=(10, 300) dtype=float32>)
(10, 100)
(10, 100)
(10, 200)

tf.nn.rnn_cell.MultiRNNCell的更多相关文章

  1. tf&period;nn&period;dynamic&lowbar;rnn

    tf.nn.dynamic_rnn(cell,inputs,sequence_length=None, initial_state=None,dtype=None, parallel_iteratio ...

  2. tensorflow笔记6:tf&period;nn&period;dynamic&lowbar;rnn 和 bidirectional&lowbar;dynamic&lowbar;rnn:的输出,output和state,以及如何作为decoder 的输入

    一.tf.nn.dynamic_rnn :函数使用和输出 官网:https://www.tensorflow.org/api_docs/python/tf/nn/dynamic_rnn 使用说明: A ...

  3. 深度学习原理与框架-递归神经网络-RNN网络基本框架&lpar;代码&quest;&rpar; 1&period;rnn&period;LSTMCell&lpar;生成单层LSTM&rpar; 2&period;rnn&period;DropoutWrapper&lpar;对rnn进行dropout操作&rpar; 3&period;tf&period;contrib&period;rnn&period;MultiRNNCell&lpar;堆叠多层LSTM&rpar; 4&period;mlstm&lowbar;cell&period;zero&lowbar;state&lpar;state初始化&rpar; 5&period;mlstm&lowbar;cell&lpar;进行LSTM求解&rpar;

    问题:LSTM的输出值output和state是否是一样的 1. rnn.LSTMCell(num_hidden, reuse=tf.get_variable_scope().reuse)  # 构建 ...

  4. tf&period;contrib&period;rnn&period;static&lowbar;rnn与tf&period;nn&period;dynamic&lowbar;rnn区别

    tf.contrib.rnn.static_rnn与tf.nn.dynamic_rnn区别 https://blog.csdn.net/u014365862/article/details/78238 ...

  5. TF-卷积函数 tf&period;nn&period;conv2d 介绍

    转自 http://www.cnblogs.com/welhzh/p/6607581.html 下面是这位博主自己的翻译加上测试心得 tf.nn.conv2d是TensorFlow里面实现卷积的函数, ...

  6. tf&period;nn&period;embedding&lowbar;lookup TensorFlow embedding&lowbar;lookup 函数最简单实例

    tf.nn.embedding_lookup TensorFlow embedding_lookup 函数最简单实例 #!/usr/bin/env python # -*- coding: utf-8 ...

  7. tf&period;nn&period;conv2d 和 tf&period;nn&period;max&lowbar;pool 中 padding 分别为 &&num;39&semi;VALID&&num;39&semi; 和 &&num;39&semi;SAME&&num;39&semi; 的直觉上的经验和测试代码

    这个地方一开始是迷糊的,写代码做比较分析,总结出直觉上的经验. 某人若想看精准的解释,移步这个网址(http://blog.csdn.net/fireflychh/article/details/73 ...

  8. 【TensorFlow基础】tf&period;add 和 tf&period;nn&period;bias&lowbar;add 的区别

    1. tf.add(x,  y, name) Args: x: A `Tensor`. Must be one of the following types: `bfloat16`, `half`, ...

  9. tf&period;nn&period;conv2d。卷积函数

    tf.nn.conv2d是TensorFlow里面实现卷积的函数,参考文档对它的介绍并不是很详细,实际上这是搭建卷积神经网络比较核心的一个方法,非常重要 tf.nn.conv2d(input, fil ...

随机推荐

  1. mysql 笔记

    mysql配置主从复制的时候,不能将server-id设置成非数字,这样会导致mysqld启动失败. mysql重启的时候,自动会释放锁(这个锁应该是位于内存的) 执行sql脚本:source /ho ...

  2. 【leetcode】Single Number &lpar;Medium&rpar; &star;

    题目: Given an array of integers, every element appears twice except for one. Find that single one. No ...

  3. VS2013和VS2008项目的互通

    VS2013和VS2008项目的互通,大家可能都查到了百度经验里面的一个帖子: http://jingyan.baidu.com/article/f54ae2fc3c3adc1e92b849de.ht ...

  4. label语句和break continue的使用&lpar;高程第三章&rpar;

    break&&outermost var num = 0; outermost: for(var i=0;i<10;i++){ for(var j=0;j<10;j++){ ...

  5. iOS开发学习--纯代码 UIScrollView 无限循环的实现——代码类封装

    一个简单的利用UIScrollView 实现的无线滚动banner,下面的代码实现,因为封装问题,对两个及一下的view 支持出了一点问题(view是传参进来的,不可以生成两份),但是原理是正确的,智 ...

  6. 【C&plus;&plus;&sol;函数】实验2

    1.实验内容 函数声明和函数定义: 形参和实参: 主调函数把实参的值传送给被调函数的形参从而实现主调函数向被调函数的数据传送. 形参:形式参数,表示主调函数与被调函数之间的联系.标识了在形参出现的位置 ...

  7. 小程序的POST接收不到参数

    这个文档上没有详细说明 在用POST的时候 header要这样写... method:"POST", header: { "Content-Type": &qu ...

  8. 呼叫转接ECT

    ECT(Explicit Call Transfer,呼叫转接)是一种较为特殊的补充业务.签约ECT业务的用户A先呼叫用户B,在与用户B建立通话后,用户A通过终端发起保持用户B呼叫的请求,此时用户B会 ...

  9. github&plus;hexo搭建博客

    引言     之前用阿里云弹性web托管采用wordpress搭建的个人博客,经过我使用一段时间之后发现存在很多问题: 网站的响应速度非常慢,估计打开主页需要3-4s的时间,我经过搜索发现很多人都有这 ...

  10. JavaScript------字符串与HTML格式相互转换

    转载: http://blog.sina.com.cn/s/blog_4cb0b0fc0100aoo1.html 代码:: 1.将字符转换成Html function encodeHtml(str){ ...