torch.nn.LSTM()
参数:input_size,hidden_size,num_layers 为必填参数
- input_size – The number of expected features in the input 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
- 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). Default: False
- 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
input_size: 输入特征维数,即每一行输入元素的个数;
hidden_size: 隐藏层状态的维数,即隐藏层节点的个数,和单层感知器的结构类似。维数值自定义,和输入的维度没有关系;
num_layers: LSTM 堆叠的层数,默认值是1层,如果设置多层,后一层LSTM接收前一个LSTM的计算结果,大小为hidden_size;
bias: 隐层状态是否带bias,默认为true。bias是偏置值,或者偏移值。没有偏置值就是以0为中轴,或以0为起点;
batch_first: 输入输出的第一维是否为 batch_size,默认值 False。Torch 中使dataset,dataloader 向神经网络模型连续输入数据,其中有 batch_size 参数,表示一次输入多少个数据。 在 LSTM 模型中,输入数据必须是一批数据,为区分 LSTM 中批量数据和 dataloader 中的批量数据是否相同意义,LSTM 模型就通过这个参数的设定来区分。 如果是相同意义的,就设置为True,如果不同意义的,设置为False。 torch.LSTM 中 batch_size 维度默认是放在第二维度,故此参数设置可以将 batch_size 放在第一维度。如:input 默认是(4,1,5),中间的 1 是 batch_size,指定batch_first=True后就是(1,4,5)。如果输入数据是二维数据,batch_first 应为True;
dropout: 默认值0,是否在除最后一个 RNN 层外的其他 RNN 层后面加 dropout 层。输入值是 0-1 之间的小数,表示概率。
bidirectional: 是否是双向 RNN,默认false,为 true 则 num_directions=2,否则为1。
参考: