在LSTM网络中对输入层应用dropout (Keras)

在Keras中,是否可以对LSTM网络的输入层应用dropout?

如果我的模型是这样的:

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))

回答:

你可以使用Keras函数式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)

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注