当前位置:网站首页>关于Pytorch中双向LSTM的输出表示问题
关于Pytorch中双向LSTM的输出表示问题
2022-06-28 10:53:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
在使用pytorch的双向LSTM的过程中,我的大脑中蒙生出了一个疑问。
双向的lstm的outputs的最后一个状态与hidden,两者之间肯定有所联系,
但具体是什么样子的呢?会不会hidden状态存储的就是outputs的最后一个状态,
这样的话,岂不是会导致hidden并不能表示整个序列的双向信息吗?带着这个疑问,我开始了实验。 具体的实验代码,这里就不放了。直接放实验结果吧。
output_size: torch.Size([14, 32, 100])
hidden_size: torch.Size([2, 32, 50])
output_first: tensor([-0.0690, -0.0778, 0.0967, -0.0504, 0.1404, 0.0873, 0.1073, -0.1513,
-0.1217, 0.0537, 0.0757, 0.0448, -0.0561, -0.0421, -0.0794, -0.0940,
-0.0649, -0.1796, 0.0847, 0.0254, -0.1643, -0.0526, -0.0008, 0.0073,
-0.0754, 0.0036, -0.0565, 0.0092, 0.0123, -0.0529, -0.1597, -0.0077,
-0.0999, -0.0776, -0.0958, 0.0742, -0.0728, 0.0029, -0.0870, 0.0563,
0.0162, -0.0016, 0.0380, -0.0483, -0.0513, -0.0948, 0.1770, 0.0280,
0.0937, 0.0464, -0.0423, -0.1260, 0.0138, -0.0270, -0.2708, 0.0970,
-0.0236, 0.1324, 0.0953, -0.0506, -0.2078, 0.1213, -0.0621, 0.0084,
0.0217, -0.0931, -0.0561, -0.1457, -0.1096, -0.0949, 0.0167, -0.0168,
0.0812, -0.1475, 0.2290, 0.0154, 0.1291, 0.0186, 0.1038, -0.0363,
-0.1291, -0.0569, -0.0428, -0.0890, -0.0827, 0.0394, -0.2272, -0.0080,
0.1731, -0.0880, -0.0652, -0.1453, -0.0914, 0.0498, 0.0831, 0.0824,
0.1725, 0.1072, 0.0176, -0.0160], device='cuda:0',
grad_fn=<SelectBackward>)
output_end: tensor([-0.1091, 0.0208, 0.0523, -0.1922, 0.1080, -0.0460, 0.0918, -0.0320,
0.1930, -0.1266, 0.1744, -0.0021, -0.1772, 0.1128, -0.1105, -0.0486,
-0.1082, 0.0427, -0.2161, -0.0804, -0.1955, -0.0580, 0.1070, 0.0856,
0.0544, 0.1932, 0.0318, -0.1977, -0.1417, -0.1977, -0.0027, -0.1575,
0.0047, -0.0164, 0.1221, 0.0331, -0.1921, 0.0210, 0.0123, 0.1483,
0.0109, 0.0044, -0.1512, -0.1795, 0.0544, 0.1051, -0.2025, -0.1051,
-0.0342, 0.1321, -0.0305, -0.0173, 0.0664, -0.0764, -0.1054, -0.0213,
0.0215, -0.0251, -0.0674, 0.0949, -0.0855, 0.0422, 0.0701, -0.1804,
0.1247, 0.0426, 0.0778, -0.0756, -0.0747, -0.1250, 0.0706, 0.0458,
-0.0114, -0.0088, 0.0573, -0.0144, -0.0143, -0.0633, 0.1355, -0.0049,
0.0091, 0.0533, -0.0889, -0.0338, -0.0654, 0.0491, -0.0809, -0.0311,
0.1278, -0.0765, -0.0682, -0.1066, 0.0538, -0.1175, -0.0171, 0.0496,
0.0258, -0.0646, 0.1396, 0.0468], device='cuda:0',
grad_fn=<SelectBackward>)
hidden tensor([[-0.1091, 0.0208, 0.0523, -0.1922, 0.1080, -0.0460, 0.0918, -0.0320,
0.1930, -0.1266, 0.1744, -0.0021, -0.1772, 0.1128, -0.1105, -0.0486,
-0.1082, 0.0427, -0.2161, -0.0804, -0.1955, -0.0580, 0.1070, 0.0856,
0.0544, 0.1932, 0.0318, -0.1977, -0.1417, -0.1977, -0.0027, -0.1575,
0.0047, -0.0164, 0.1221, 0.0331, -0.1921, 0.0210, 0.0123, 0.1483,
0.0109, 0.0044, -0.1512, -0.1795, 0.0544, 0.1051, -0.2025, -0.1051,
-0.0342, 0.1321],
[-0.0423, -0.1260, 0.0138, -0.0270, -0.2708, 0.0970, -0.0236, 0.1324,
0.0953, -0.0506, -0.2078, 0.1213, -0.0621, 0.0084, 0.0217, -0.0931,
-0.0561, -0.1457, -0.1096, -0.0949, 0.0167, -0.0168, 0.0812, -0.1475,
0.2290, 0.0154, 0.1291, 0.0186, 0.1038, -0.0363, -0.1291, -0.0569,
-0.0428, -0.0890, -0.0827, 0.0394, -0.2272, -0.0080, 0.1731, -0.0880,
-0.0652, -0.1453, -0.0914, 0.0498, 0.0831, 0.0824, 0.1725, 0.1072,
0.0176, -0.0160]], device='cuda:0', grad_fn=<SliceBackward>)上面的实验结果,第一条输出为输出的维度大小,分别是长度,批次和隐藏层大小*2。我们可以看出最后一维的维度值为100,是设置隐藏层大小的两倍。 第二条输出则是我们的隐藏层维度大小,分别是左右两向,批次大小,隐藏层大小。 第三条输出是(第一条数据)从左往右第一个词所对应的表示向量的值,为“序列从左往右第一个隐藏层状态输出”和“序列从右往左最后一个隐藏层状态输出”的拼接。 第四条输出是(第一条数据)从左往右最后一个词所对应的表示向量的值,为“序列从左往右最后一个隐藏层状态输出”和“序列从右往左第一个隐藏层状态输出”的拼接。 第五条输出是隐藏层输出,为“序列从左往右最后一个隐藏层状态输出”和“序列从右往左最后一个隐藏层状态输出”的拼接。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/151100.html原文链接:https://javaforall.cn
边栏推荐
- Basic 02: variable, remember the mobile number of the object
- JS foundation 6
- JS foundation 2
- etf持仓如何影响现货金价?
- DlhSoft Kanban Library for WPF
- 拼接String集合中的字符串_基于Stream
- Makefile简介
- Understanding of FTP protocol
- An idea plug-in that automatically generates unit tests, which improves the development efficiency by more than 70%!
- Ble Bluetooth module nrf518/nrf281/nrf528/nrf284 chip scheme comparison
猜你喜欢

fastposter v2.8.4 发布 电商海报生成器

Markdown -- basic usage syntax

MySQL (I)

数据库系列:有什么办法对数据库的业务表进行无缝升级

MySQL(一)

MySQL general binary installation method

Oracle 日期格式化异常:无效数字

Summary of characteristics of five wireless transmission protocols of Internet of things

Ble Bluetooth module nrf518/nrf281/nrf528/nrf284 chip scheme comparison

DlhSoft Kanban Library for WPF
随机推荐
MySQL general binary installation method
[practice] appium settings app is not running after 5000ms
Ruoyi integrated building block report (NICE)
DataEase安装升级
MytipartFile与File的相互转换
Word、PDF、TXT文件实现全文内容检索需要用什么方法?
Six fusion positioning technologies in wireless communication application of Internet of things
MySQL(一)
JS基础5
Fastposter v2.8.4 release e-commerce poster generator
【SemiDrive源码分析】【X9芯片启动流程】32 - DisPlay模块分析 - RTOS侧
Hystrix 部署
etf持仓如何影响现货金价?
毕业季 新的开始
【实战】1364- 实现一个完美的移动端瀑布流组件(附源码)
知道 Redis RDB 这些细节,可以少踩很多坑
MySQL (III)
Realization of a springboard machine
Datetime and logging module
【monkey】monkey测试入门