4

In PyTorch there is a LSTM module which in addition to input sequence, hidden states, and cell states accepts a num_layers argument which specifies how many layers will our LSTM have.

There is however another module LSTMCell which has just input size and number of hidden states as parameters, there is no num_layers since this is a single cell in a multi-layered LSTM.

My question is what is the proper way to connect together the LSTMCell modules to achieve a same effect as a multi layered LSTM with num_layers > 1

4

2 回答 2

2

LSTMCell 是 LSTM 网络的基本构建块。您应该使用 LSTM 模块(在内部使用 LSTMCell)。如果你想自己做,最好的方法是阅读源代码(https://github.com/pytorch/pytorch/blob/master/torch/nn/modules/rnn.py)。

基本上你想为每一层使用一个 LSTMCell,你应该小心如何从输入到输出,逐层考虑隐藏状态。我也有卷积 LSTM 的基本实现,但想法是一样的。你可以在这里查看: https ://github.com/rogertrullo/pytorch_convlstm/

于 2018-01-08T09:57:56.663 回答
1

如果我理解正确,l-1 层 lstm 单元的隐藏输出是 l 层 lstm 单元的输入。

于 2018-01-03T15:08:57.687 回答