Dropout 训练参数

Dropout Training Parameter

我想在 LSTM 层中使用 dropout 进行训练和测试。根据这篇文章:

https://towardsdatascience.com/learning-note-dropout-in-recurrent-networks-part-2-f209222481f8

model = Sequential()
model.add(LSTM(X_len, return_sequences = True, input_shape=(X_len, 1)))
model.add(Dropout(rate=0.2, training=True))
model.add(LSTM(X_len))
model.add(Dropout(rate=0.2, training=True))
model.add(Dense(Y_len))

我得到的错误是:

TypeError: ('Keyword argument not understood:', 'training')

知道如何解决这个问题吗?

使用功能格式

inp = Input(shape=(X_len, 1))
x = LSTM(X_len, return_sequences = True)(inp)
x = Dropout(rate=0.2)(x, training=True)
x = LSTM(X_len)(x)
x = Dropout(rate=0.2)(x, training=True)
out = Dense(Y_len)(x)

model = Model(inp, out)
model.compile('adam', 'mse')
model.summary()