【发布时间】:2017-01-11 04:19:57
【问题描述】:
下面是我使用 Keras 构建的 RNN:
def RNN_keras(feat_num, timestep_num=100):
model = Sequential()
model.add(BatchNormalization(input_shape=(timestep_num, feat_num)))
model.add(LSTM(input_shape=(timestep_num, feat_num), output_dim=512, activation='relu', return_sequences=True))
model.add(BatchNormalization())
model.add(LSTM(output_dim=128, activation='relu', return_sequences=True))
model.add(BatchNormalization())
model.add(TimeDistributed(Dense(output_dim=1, activation='linear'))) # sequence labeling
rmsprop = RMSprop(lr=0.00001, rho=0.9, epsilon=1e-08)
model.compile(loss='mean_squared_error',
optimizer=rmsprop,
metrics=['mean_squared_error'])
return model
输出如下:
61267 in the training set
6808 in the test set
Building training input vectors ...
888 unique feature names
The length of each vector will be 888
Using TensorFlow backend.
Build model...
****** Iterating over each batch of the training data ******
# Each batch has 1280 examples
# The training data are shuffled at the beginning of each epoch.
Epoch 1/3 : Batch 1/48 | loss = 607.043823 | root_mean_squared_error = 24.638334
Epoch 1/3 : Batch 2/48 | loss = 14479824582732.208323 | root_mean_squared_error = 3805236.468701
Epoch 1/3 : Batch 3/48 | loss = nan | root_mean_squared_error = nan
Epoch 1/3 : Batch 4/48 | loss = nan | root_mean_squared_error = nan
Epoch 1/3 : Batch 5/48 | loss = nan | root_mean_squared_error = nan
......
第二批损失很高,然后变成了nan。真实结果 y 不包含非常大的值。最大y小于400。
另一方面,我检查预测输出 y_hat。 RNN 返回一些非常高的预测,这会导致无穷大。
但是,我仍然对如何改进我的模型感到困惑。
【问题讨论】:
-
你是否尝试过切换到交叉熵损失
-
您是否尝试使用
tanh或sigmoid而不是relu以避免较大的值? -
@Julius 这是一个回归问题。交叉熵损失也适用吗?
-
@S.Mohsensh 我试过 tanh。问题仍然存在。我只是尝试在输出层用 relu 替换线性。它有效,但损失不会随着时间的推移而减少。所有 epoch 都有相同的损失。
标签: optimization neural-network deep-learning keras recurrent-neural-network