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的上侧输出
pytorch RNN层api的几个参数说明的更多相关文章
- 自己动手实现深度学习框架-7 RNN层--GRU, LSTM
目标 这个阶段会给cute-dl添加循环层,使之能够支持RNN--循环神经网络. 具体目标包括: 添加激活函数sigmoid, tanh. 添加GRU(Gate Recurrent U ...
- Zigbee协议栈OSAL层API函数【转载】
OSAL层提供了很多的API来对整个的协议栈进行管理.主要有下面的几类:信息管理.任务同步.时间管理.中断管理.任务管理.内存管理.电源管理以及非易失存储管理.看到这些管理是不是感 ...
- 【转载】 Caffe BN+Scale层和Pytorch BN层的对比
原文地址: https://blog.csdn.net/elysion122/article/details/79628587 ------------------------------------ ...
- [PyTorch] rnn,lstm,gru中输入输出维度
本文中的RNN泛指LSTM,GRU等等 CNN中和RNN中batchSize的默认位置是不同的. CNN中:batchsize的位置是position 0. RNN中:batchsize的位置是pos ...
- Android 访问Android Wear数据层Api——同步Data Items
Data Items它被用来同步手机和wear数据接口,一个Date Items通常包含以下几个部分: Payload 字节数组.无论你需要设置数据类型,我们同意对象序列化和反序列化,大小不能超过10 ...
- pytorch rnn 2
import torch import torch.nn as nn import numpy as np import torch.optim as optim class RNN(nn.Modul ...
- pytorch rnn
温习一下,写着玩. import torch import torch.nn as nn import numpy as np import torch.optim as optim class RN ...
- pytorch --Rnn语言模型(LSTM,BiLSTM) -- 《Recurrent neural network based language model》
论文通过实现RNN来完成了文本分类. 论文地址:88888888 模型结构图: 原理自行参考论文,code and comment: # -*- coding: utf-8 -*- # @time : ...
- Pytorch基础——使用 RNN 生成简单序列
一.介绍 内容 使用 RNN 进行序列预测 今天我们就从一个基本的使用 RNN 生成简单序列的例子中,来窥探神经网络生成符号序列的秘密. 我们首先让神经网络模型学习形如 0^n 1^n 形式的上下文无 ...
随机推荐
- java操作telnet远程登录
import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import jav ...
- 关于Docker清理
在Docker的日常使用中,我们或许偶尔遇到下面这些情况: 12345678 $ docker-compose ps[27142] INTERNAL ERROR: cannot create temp ...
- IP地址0.0.0.0表示什么
参考RFC文档: 0.0.0.0/8 - Addresses in this block refer to source hosts on "this"network. Addre ...
- JavaScript学习之内存
初学JavaScript时,看红皮书了解了JS基本类型和引用类型在内存中的位置,结果看了简书里的一篇文章,发现对这块的了解还是有些缺陷. 基本类型 JavaScript中的基本类型有五种:Undefi ...
- [JS奇怪的世界]No.55 危險小叮嚀:陣列與for in
前言 前面已經瞭解了使用內建函數建構子的某些危險地方,但其實陣列與for in,也是有一些危險的地方. 陣列與for in 在前面幾個章節有講過陣列就是物件,所以我們一樣可以使用 for in來做處理 ...
- Allenmind's Blog
听说,Sass和Compass更配哟.来看看Compass的基本用法! 目录 Compass和Sass 安装Compass 项目初始化 编译 Compass的模块 Compass的Helper函数 一 ...
- C++程序设计--运算符重载
目录 1, 运算符重载2, 赋值运算符的重载3, 流插入运算符重载4,自加/自减运算符的重载 运算符重载 作用:对抽象数据类型也能够直接使用C++提供的运算符.使得程序更简洁.代码更容易理解. 运算符 ...
- Flink命令行提交job (源码分析)
这篇文章主要介绍从命令行到任务在Driver端运行的过程 通过flink run 命令提交jar包运行程序 以yarn 模式提交任务命令类似于: flink run -m yarn-cluster X ...
- Python使用input方法输入字母显示NameError
如图,每次用input方法,输入数字正常,但是输入字母就会报错. 到网上查找资料之后,明白了原来在python2.7中应该用raw_input. 修改之后,代码就正常了.
- 常用阻塞队列 BlockingQueue 有哪些?
为什么要使用阻塞队列 之前,介绍了一下 ThreadPoolExecutor 的各参数的含义(并发编程之线程池ThreadPoolExecutor),其中有一个 BlockingQueue,它是一个阻 ...