torch.nn.LSTM

torch.nn.LSTM

输出的最后一层ht列表。

c_t-1
h_t-1
x_t
LSTM
c_t
h_t
torch.nn.LSTM(self, input_size, hidden_size, num_layers=1, bias=True, batch_first=False, dropout=0.0, bidirectional=False, proj_size=0, device=None, dtype=None)
Parameters
  • input_size – The number of expected features in the input x。x最后输入大小
  • hidden_size – The number of features in the hidden state h。就是输出大小
  • num_layers – Number of recurrent layers. E.g., setting num_layers=2 would mean stacking two LSTMs together to form a stacked LSTM, with the second LSTM taking in outputs of the first LSTM and computing the final results. Default: 1。也就是多个模型,但是多个模型的输出是stack的,也就是不拼接的。
  • bias – If False, then the layer does not use bias weights b_ih and b_hh. Default: True
  • batch_first – If True, then the input and output tensors are provided as (batch, seq, feature) instead of (seq, batch, feature). Note that this does not apply to hidden or cell states. See the Inputs/Outputs sections below for details. Default: False。如果设置定位True,输入也要改变,输出也会改变。
  • dropout – If non-zero, introduces a Dropout layer on the outputs of each LSTM layer except the last layer, with dropout probability equal to dropout. Default: 0
  • bidirectional – If True, becomes a bidirectional LSTM. Default: False。这个是会拼接的,如果选择那么输出会
  • proj_size – If > 0, will use LSTM with projections of corresponding size. Default: 0。
Inputs: input, (h_0, c_0)
  • input :

    • 单个输入:(sequence_length, input_size)
    • batch输入:(sequence_length, batch_size, input_size) ,batch_first=True: (batch_size, sequence_length, input_size)
  • h_0:默认是0,

    • 单个输入:(D * num_layers, hidden_size) ,如果是双向D=2
    • batch_输入: (D * num_layers, batch_size, hidden_size)
  • c_0:默认是0

    • 单个输入:(D * num_layers, hidden_size) ,如果是双向D=2
    • batch_输入: (D * num_layers, batch_size, hidden_size)
Output:output, (h_n, c_n)
  • output: 输出的最后一层的隐藏态。

    • 单句输出:(sequence_length, hidden_size)
    • batch输出:(sequence_length, batch_size, D*hidden_size) ,batch_first=True: (batch_size, sequence_length, D*hidden_size)
  • h_0:默认是0, 所有层所有链最后的隐藏态。

    • 单个输出:(D * num_layers, hidden_size) ,如果是双向D=2
    • batch_输出: (D * num_layers, batch_size, hidden_size)
  • c_0:默认是0,所有层所有链最后的细胞态。

    • 单个输入:(D * num_layers, hidden_size) ,如果是双向D=2
    • batch_输入: (D * num_layers, batch_size, hidden_size)
  • 19
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值