pytorch RNN层api的几个参数说明
classtorch.nn.
RNN
(*args, **kwargs)
input_size – The number of expected features in the input x
hidden_size – The number of features in the hidden state h
num_layers – Number of recurrent layers. E.g., setting num_layers=2
would mean stacking two RNNs together to form a stacked RNN, with the second RNN taking in outputs of the first RNN and computing the final results. Default: 1
nonlinearity – The non-linearity to use. Can be either ‘tanh’ or ‘relu’. Default: ‘tanh’
bias – If False
, then the layer does not use bias weights b_ih and b_hh. Default: True
batch_first – If
True
, then the input and output tensors are provided as (batch, seq, feature)
dropout – If non-zero, introduces a Dropout layer on the outputs of each RNN layer except the last layer, with dropout probability equal to dropout
. Default: 0
bidirectional – If True
, becomes a bidirectional RNN. Default: False
有个参数一直理解错误,导致了认知困难
首先,RNN这里的序列长度,是动态的,不写在参数里的,具体会由输入的input参数而定
而num_layers并不是RNN的序列长度,而是堆叠层数,由上一层每个时间节点的输出作为下一层每个时间节点的输入
RNN的对象接受的参数,input维度是(seq_len, batch_size, input_dim),h0维度是(num_layers * directions, batch_size, hidden_dim)
其中,input的seq_len决定了序列的长度,h0是提供给每层RNN的初始输入,所有num_layers要和RNN的num_layers对得上
返回两个值,一个output,一个hn
hn的维度是(num_layers * directions, batch_size, hidden_dim),是RNN的右侧输出,如果是双向的话,就还有一个左侧输出
output的维度是(seq_len, batch_size, hidden_dim * directions),是RNN的上侧输出
最新文章
- mui事件绑定和可以用的js dom操作方法
- MySQL 升级
- SAS 画折线图PROC GPLOT
- rpc框架之 thrift 学习 2 - 基本概念
- Java 反射的应用
- CTSC2016游记
- [转]centos 下 autoconf版本升级
- [Linux] Linux下谁在消耗我们的cache
- 自然语言处理——NLTK中文语料库语料库
- 怎样用AIDL Service 传递复杂数据
- iOS 改变UILabel部分颜色
- C# 合并DLL, 合并DLL进入EXE 【转】
- NameNode元数据的管理机制(三)
- .mtl文件格式解析
- [linux服务器][bash]让切换目录更方便
- C语言 大小端 字节对齐
- 嵌入式linux——时钟(三)
- day5模块学习--re正则模块
- c++ STL容器初探
- linux sar详解
热门文章
- 使用junit测试springMVC项目提示ServletContext找不到定义错误
- Hadoop的存储架构介绍
- SWUST OJ Euclid's Game(0099)
- Ionic3学习笔记(八)使iOS端、Android端 Navbar 透明化
- 【转】PHP中被忽略的性能优化利器:生成器.md
- web端手机方向传感器闲谈
- windows7 64位系统下无法运行ipython
- numpy学习总结
- Centos7.X 搭建Prometheus+node_exporter+Grafana实时监控平台
- TCP/IP协议概要--01