torch.nn.LSTM()函数维度详解
1
2
3
4
5
6
7
8
9
10
11
12
lstm=nn.LSTM(input_size, hidden_size, num_layers)
x seq_len, batch, input_size
h0 num_layers× \times×num_directions, batch, hidden_size
c0 num_layers× \times×num_directions, batch, hidden_size
output seq_len, batch, num_directions× \times×hidden_size
hn num_layers× \times×num_directions, batch, hidden_size
cn num_layers× \times×num_directions, batch, hidden_size
举个例子:
对句子进行LSTM操作
假设有100个句子(sequence),每个句子里有7个词,batch_size=64,embedding_size=300
此时,各个参数为:
input_size=embedding_size=300
batch=batch_size=64
seq_len=7
另外设置hidden_size=100, num_layers=1
import torch
import torch.nn as nn
lstm = nn.LSTM(300, 100, 1)
x = torch.randn(7, 64, 300)
h0 = torch.randn(1, 64, 100)
c0 = torch.randn(1, 64, 100)
output, (hn, cn)=lstm(x, (h0, c0))
>>
output.shape torch.Size([7, 64, 100])
hn.shape torch.Size([1, 64, 100])
cn.shape torch.Size([1, 64, 100])
---------------------
作者:huxuedan01
来源:CSDN
原文:https://blog.csdn.net/m0_37586991/article/details/88561746
版权声明:本文为博主原创文章,转载请附上博文链接!
torch.nn.LSTM()函数维度详解的更多相关文章
- WScript.Shell对象的 run()和exec()函数使用详解
WScript.Shell对象的 run()和exec()函数使用详解 http://blog.sina.com.cn/s/blog_6e14a2050102v47g.html vbScript ...
- 关于torch.nn.LSTM()的输入和输出
主角torch.nn.LSTM() 初始化时要传入的参数 | Args: | input_size: The number of expected features in the input `x` ...
- 自写函数VB6 STUFF函数 和 VB.net 2010 STUFF函数 详解
'*************************************************************************'**模 块 名:自写函数VB6 STUFF函数 和 ...
- SQL Server数据库ROW_NUMBER()函数使用详解
SQL Server数据库ROW_NUMBER()函数使用详解 摘自:http://database.51cto.com/art/201108/283399.htm SQL Server数据库ROW_ ...
- PHP函数篇详解十进制、二进制、八进制和十六进制转换函数说明
PHP函数篇详解十进制.二进制.八进制和十六进制转换函数说明 作者: 字体:[增加 减小] 类型:转载 中文字符编码研究系列第一期,PHP函数篇详解十进制.二进制.八进制和十六进制互相转换函数说明 ...
- PHP date函数参数详解
PHP date函数参数详解 作者: 字体:[增加 减小] 类型:转载 time()在PHP中是得到一个数字,这个数字表示从1970-01-01到现在共走了多少秒,很奇怪吧 不过这样方便计 ...
- SQL中CONVERT()函数用法详解
SQL中CONVERT函数格式: CONVERT(data_type,expression[,style]) 参数说明: expression 是任何有效的 Microsoft® SQL Server ...
- php中setcookie函数用法详解(转)
php中setcookie函数用法详解: php手册中对setcookie函数讲解的不是很清楚,下面是我做的一些整理,欢迎提出意见. 语法: bool set ...
- eval()函数用法详解
eval()函数用法详解:此函数可能使用的频率并不是太高,但是在某些情况下具有很大的作用,下面就介绍一下eval()函数的用法.语法结构: eval(str) 此函数可以接受一个字符串str作为参数, ...
随机推荐
- 从0开始学习 GitHub 系列之「01.初识 GitHub
转载:http://blog.csdn.net/googdev/article/details/52787516 1. 写在前面 我一直认为 GitHub 是程序员必备技能,程序员应该没有不知道 Gi ...
- Codeforces Beta Round #77 (Div. 2 Only) A. Football【字符串/判断是否存在连续7个0或7个1】
A. Football time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...
- iOS - CAReplicatorLayer 的运用
http://www.cocoachina.com/ios/20151230/14822.html 序 CAReplicatorLayer可以复制自己子层的layer,并且复制的出来的layer和原来 ...
- 泛型List 扩展 比较类
List<string> outputList = resultList.Distinct(new Compare<string>((x, y) => (null != ...
- Android LruCache源码简介
package android.util; import java.util.LinkedHashMap; import java.util.Map; /** * A cache that holds ...
- Servlet FilterConfig
FilterConfig的对象由Web容器创建.这个对象可用于获取web.xml文件中Filter的配置信息 文件:index.html <!DOCTYPE html> <html& ...
- poj2391 最大流+拆点
题意:F块草坪,上面有n头牛,可以容纳m个牛遮雨.将草坪一份为2,成为二部图. 对于此题,和poj2112很像,只是2112很明显的二部图.这道题就开始敲,但是建图遇到问题,草坪的2个值怎么处理,于是 ...
- LeetCode120 Triangle
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...
- Spring中配置DataSource数据源的几种选择
从JNDI获得DataSource. 从第三方的连接池获得DataSource. 使用DriverManagerDataSource获得DataSource. 一.从JNDI获得DataSource ...
- 冒泡排序 Day07
package com.sxt.arraytest2; /* * 冒泡排序 * 思想:两两交换 一路大的向右 */ import java.util.Arrays; public class Bubb ...