Pytorch 中 LSTMCell介绍

LSTM 和 LSTMCell的关系

很显然,LSTMCell是组成LSTM整个序列计算过程的基本组成单元,也就是进行sequence中一个word的计算


LSTMCell

LSTMCell

  • input_size: word embedding dim
  • hidden_size: hidden_dim

Parameters

在这里插入图片描述

examples:

"""
	input_size:10  equals to (embedding_dim in word embedding)
	hidden_dim:20
	batch_size:3
	seq_len:6
	
	LSTMCell:
		input : (batch_size,input_size)
		hx: (batch_size,hidden_dim)
		cx: (batch_size,hidden_dim)
	for循环:对整个序列逐个单词输入,依次计算,当前Cell的(hx,cx)作为下一次计算的隐藏层输入
	注意:这里是在同一个RNN layer
"""

rnn = nn.LSTMCell(10, 20)
input = torch.randn(6, 3, 10)
hx = torch.randn(3, 20)
cx = torch.randn(3, 20)
output = []
for i in range(6):
	hx, cx = rnn(input[i], (hx, cx))
	output.append(hx)
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值