Keras LSTM 中的多层隐藏层

Multiple Layer hidden layer in LSTM in Keras

x = Input(shape=(timesteps, input_dim,))

# LSTM encoding
h = LSTM(2048)(x)

这是我从网上下载的文件中的几行代码。我认为 h 适用于具有 2048 个单元的单层 LSTM 层。它如何使它成为多层,即 2 个隐藏层。

只需添加另一层(我们称之为 g)!但是由于我们要传递到另一个 LSTM 层,我们将不得不向第一层添加 return_sequences 关键字参数,以便我们可以获得正确的输入形状到第二层。

x = Input(shape=(timesteps, input_dim,))

# LSTM encoding
h = LSTM(2048, return_sequences=true)(x)
g = LSTM(10)(h)