是否可以在Keras的LSTM网络的输入层应用辍学?
如果这是我的模特:
model = Sequential()
model.add(LSTM(10, input_shape=(look_back, input_length), return_sequences=False))
model.add(Dense(1))
目标是达到以下效果:
model = Sequential()
model.add(Dropout(0.5))
model.add(LSTM(10, input_shape=(look_back, input_length), return_sequences=False))
model.add(Dense(1))
答案 0 :(得分:2)
您可以使用Keras Functional API,其中您的模型将写为:
inputs = Input(shape=(input_shape), dtype='int32')
x = Dropout(0.5)(inputs)
x = LSTM(10,return_sequences=False)(x)
定义输出层,例如:
predictions = Dense(10, activation='softmax')(x)
然后构建模型:
model = Model(inputs=inputs, outputs=predictions)