博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
torch.nn.LSTM()函数维度详解
阅读量:4563 次
发布时间:2019-06-08

本文共 1051 字,大约阅读时间需要 3 分钟。

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
版权声明:本文为博主原创文章,转载请附上博文链接!

转载于:https://www.cnblogs.com/jfdwd/p/11187387.html

你可能感兴趣的文章
Centos7,PHP7安装swoole
查看>>
02_ListActive中响应事件 并LogCat输出
查看>>
doubleclick adx note
查看>>
Celery框架
查看>>
[c#]asp.net开发微信公众平台(4)关注事件、用户记录、回复文本消息
查看>>
[转载,感觉写的非常详细]DUBBO配置方式详解
查看>>
linux Valgrind使用说明-内存泄漏
查看>>
Android在Eclipse上的环境配置
查看>>
面向对象(五)
查看>>
android平台下使用点九PNG技术
查看>>
Python学习3,列表
查看>>
最长回文子串
查看>>
JAVA基础-JDBC(一)
查看>>
js中for和while运行速度比较
查看>>
简单理解什么是递归(阶乘演示)
查看>>
http协议
查看>>
js倒计时,页面刷新时,不会从头计时
查看>>
洛谷1156垃圾陷阱
查看>>
python ==》 递归
查看>>
简单网络请求封装
查看>>