torch.nn.LSTM
输出的最后一层ht列表。
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)