LSTM/GRU中output和hidden的区别//其他问题

本文详细解析了RNN的输出结构,包括output、h_n和c_n的含义及应用,阐述了num_layers参数的影响,并对比了LOSS与logP(y|x)在模型训练中的作用与区别。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Outputs: output, (h_n, c_n)

 

  • output (seq_len, batch, hidden_size * num_directions): tensor containing the output features (h_t) from the last layer of the RNN, for each t. If a torch.nn.utils.rnn.PackedSequence has been given as the input, the output will also be a packed sequence.
  • h_n (num_layers * num_directions, batch, hidden_size): tensor containing the hidden state for t=seq_len
  • c_n (num_layers * num_directions, batch, hidden_size): tensor containing the cell state for t=seq_len

 

renamed num_layers (有几层LSTM/GRU叠加)to w.

output comprises all the hidden states in the last layer ("last" depth-wise, not time-wise). 

(h_n, c_n) comprises the hidden states after the last timestep, t = n, so you could potentially feed them into another LSTM.

 

LSTM diagram

加入num_layers=1,那么output和hidden相等。

 

 

LOSS和logP(y|x)的区别:

decoder每一步输出的是单词词典中每一个单词的概率。就是,下一个是什么单词,候选集里每个单词的都有可能。

目标是模型的输出接近真实值,所以

输出序列是依赖参数的,计算出目标输出的所对应的参数表示函数集合。(回忆考研最大似然的定义)

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值