Recap

input dim, hidden dim

  1. from tensorflow.keras import layers
  2. # $xw_{xh} + hw_{nn}$,3次
  3. cell = layers.SimpleRNNCell(3)
  4. cell.build(input_shape=(None, 4))
  5. cell.trainable_variables
  1. [<tf.Variable 'kernel:0' shape=(4, 3) dtype=float32, numpy=
  2. array([[-0.5311725 , 0.7757399 , -0.19041312],
  3. [ 0.90420175, -0.14276218, 0.1546886 ],
  4. [ 0.81770146, -0.46731013, -0.05373603],
  5. [ 0.49086082, 0.10275221, 0.10146773]], dtype=float32)>,
  6. <tf.Variable 'recurrent_kernel:0' shape=(3, 3) dtype=float32, numpy=
  7. array([[ 0.7557267 , -0.58395827, 0.2964283 ],
  8. [-0.64145935, -0.56886935, 0.5147014 ],
  9. [-0.13193521, -0.5791204 , -0.8044953 ]], dtype=float32)>,
  10. <tf.Variable 'bias:0' shape=(3,) dtype=float32, numpy=array([0., 0., 0.], dtype=float32)>]

SimpleRNNCell

  • \(out,h_1 = call(x,h_0)\)

    • x: [b,seq len,word vec]

    • \(h_0/h_1: [b,h dim]\)

    • out: [b,h dim]

Single layer RNN Cell

  1. import tensorflow as tf
  2. x = tf.random.normal([4, 80, 100])
  3. ht0 = x[:, 0, :]
  4. cell = tf.keras.layers.SimpleRNNCell(64)
  5. out, ht1 = cell(ht0, [tf.zeros([4, 64])])
  6. out.shape, ht1[0].shape
  1. []
  2. (TensorShape([4, 64]), TensorShape([4, 64]))
  1. id(out), id(ht1[0]) # same id
  1. (4877125168, 4877125168)

Multi-Layers RNN

  1. x = tf.random.normal([4, 80, 100])
  2. ht0 = x[:, 0, :]
  3. cell = tf.keras.layers.SimpleRNNCell(64)
  4. cell2 = tf.keras.layers.SimpleRNNCell(64)
  5. state0 = [tf.zeros([4, 64])]
  6. state1 = [tf.zeros([4, 64])]
  7. out0, state0 = cell(ht0, state0)
  8. out2, state2 = cell2(out, state2)
  9. out2.shape, state2[0].shape
  1. (TensorShape([4, 64]), TensorShape([4, 64]))

RNN Layer

  1. self.run = keras.Sequential([
  2. layers.SimpleRNN(units,dropout=0.5,return_sequences=Ture,unroll=True),
  3. layers.SimpleRNN(units,dropout=0.5,unroll=True)
  4. ])
  5. x=self.rnn(x)

RNNCell使用的更多相关文章

  1. PyTorch官方中文文档:torch.nn

    torch.nn Parameters class torch.nn.Parameter() 艾伯特(http://www.aibbt.com/)国内第一家人工智能门户,微信公众号:aibbtcom ...

  2. TensorFlow 常用函数汇总

    本文介绍了tensorflow的常用函数,源自网上整理. TensorFlow 将图形定义转换成分布式执行的操作, 以充分利用可用的计算资源(如 CPU 或 GPU.一般你不需要显式指定使用 CPU ...

  3. TensorFlow 常用函数与方法

    摘要:本文主要对tf的一些常用概念与方法进行描述. tf函数 TensorFlow 将图形定义转换成分布式执行的操作, 以充分利用可用的计算资源(如 CPU 或 GPU.一般你不需要显式指定使用 CP ...

  4. pytorch, LSTM介绍

    本文中的RNN泛指LSTM,GRU等等 CNN中和RNN中batchSize的默认位置是不同的. CNN中:batchsize的位置是position 0. RNN中:batchsize的位置是pos ...

  5. 新版seqseq接口说明

    attention_mechanism = tf.contrib.seq2seq.BahdanauAttention(num_units=FLAGS.rnn_hidden_size, memory = ...

  6. 学习笔记CB014:TensorFlow seq2seq模型步步进阶

    神经网络.<Make Your Own Neural Network>,用非常通俗易懂描述讲解人工神经网络原理用代码实现,试验效果非常好. 循环神经网络和LSTM.Christopher ...

  7. LSTM编程所用函数

    1.Round函数返回一个数值,该数值是按照指定的小数位数进行四舍五入运算的结果.可是当保留位跟着的即使是5,有可能进位,也有可能舍去,机会各50% 2.python基础 (1)@property 特 ...

  8. tensorflow学习之(十一)RNN+LSTM神经网络的构造

    #RNN 循环神经网络 import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data tf.se ...

  9. 深度学习框架PyTorch一书的学习-第四章-神经网络工具箱nn

    参考https://github.com/chenyuntc/pytorch-book/tree/v1.0 希望大家直接到上面的网址去查看代码,下面是本人的笔记 本章介绍的nn模块是构建与autogr ...

随机推荐

  1. Quartz.NET一个开源的作业调度框架

    Quartz.NET是一个开源的作业调度框架,非常适合在平时的工作中,定时轮询数据库同步,定时邮件通知,定时处理数据等. Quartz.NET允许开发人员根据时间间隔(或天)来调度作业.它实现了作业和 ...

  2. 【react native】rn踩坑实践——从输入框“们”开始

    因为团队技术栈变更为react native,所以开始写起了rn的代码,虽然rn与react份数同源,但是由于有很多native有关的交互和变动,实际使用还是碰到蛮多问题的,于是便有了这个系列,本来第 ...

  3. Java键盘输入的方法

    转载:http://blog.csdn.net/u012249177/article/details/49586383 java输入的方法: import java.io.BufferedReader ...

  4. _bzoj1012 [JSOI2008]最大数maxnumber【Fenwick Tree】

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1012 裸的树状数组. #include <cstdio> #include &l ...

  5. 贪心 UVALive 6834 Shopping

    题目传送门 /* 题意:有n个商店排成一条直线,有一些商店有先后顺序,问从0出发走到n+1最少的步数 贪心:对于区间被覆盖的点只进行一次计算,还有那些要往回走的区间步数*2,再加上原来最少要走n+1步 ...

  6. git介绍及安装

    git介绍 git是一个开源的分布式版本控制系统,用于敏捷高效的处理任何或大或小的项目.git是linus Torvalds为了帮助管理Linux内核开发的一个开放源码的版本控制软件. Git 与常用 ...

  7. OSW

    OSWatcher 工具 下载文档 :Metalink Doc ID 301137.1 Oswatcher 主要用于监控主机资源,如CPU,内存,网络以及私有网络等.其中私有网络需要单独配置. 需要说 ...

  8. Elixir安装

    参考:https://laravel.com/docs/5.2/elixir 1. 安装node 去这里下载 2.可以用淘宝的cnpm加速! npm install -g cnpm --registr ...

  9. 增大PHP允许上传的文件大小;解决POST Content-Length exceeds the limit

    在php.ini中: upload_max_filesize = 1000M ;1GB post_max_size = 1000M 然后重启apache 参考链接

  10. Activiti工作流和shiro权限管理关系图