Keras - 损失和 val_loss 增加
Keras - loss and val_loss increasing
我在 Keras 中使用 LSTM 训练聊天机器人的神经网络。
contextTrain, contextTest, utteranceTrain, utteranceTest = train_test_split(context, utterance, test_size=0.1, random_state=1)
model = Sequential()
model.add(LSTM(input_shape=contextTrain.shape[1:], return_sequences=True, units=300, activation="sigmoid", kernel_initializer="glorot_normal", recurrent_initializer="glorot_normal"))
model.add(LSTM(return_sequences=True, units=300, activation="sigmoid", kernel_initializer="glorot_normal", recurrent_initializer="glorot_normal"))
model.compile(loss="cosine_proximity", optimizer="adam", metrics=["accuracy"])
model.fit(contextTrain, utteranceTrain, epochs=5000, validation_data=(contextTest, utteranceTest), callbacks=[ModelCheckpoint("model{epoch:02d}.h5", monitor='val_acc', save_best_only=true, mode='max')])
上下文和话语是具有形状的 numpy 数组,例如(1000, 10, 300) 或 (10000, 10, 300)。 Input_shape 第一个 LSTM 应该是 (10, 300)。大小为 300 的向量是由 Word2vec 模型创建的词嵌入表示的词。所以在这个例子中输入数据是这些向量中的 10 个。
最大的问题是损失和val_loss在训练过程中几乎都在稳步增加。
Epoch 1/5000
900/900 [==============================] - 18s 20ms/step - loss: -0.5855 - acc: 0.0220 - val_loss: -0.6527 - val_acc: 0.0260
Epoch 2/5000
900/900 [==============================] - 13s 14ms/step - loss: -0.6299 - acc: 0.0239 - val_loss: -0.6673 - val_acc: 0.0240
Epoch 3/5000
900/900 [==============================] - 12s 14ms/step - loss: -0.6387 - acc: 0.0213 - val_loss: -0.6764 - val_acc: 0.0160
Epoch 4/5000
900/900 [==============================] - 12s 13ms/step - loss: -0.6457 - acc: 0.0229 - val_loss: -0.6821 - val_acc: 0.0240
Epoch 5/5000
900/900 [==============================] - 12s 14ms/step - loss: -0.6497 - acc: 0.0274 - val_loss: -0.6873 - val_acc: 0.0230
Epoch 6/5000
900/900 [==============================] - 14s 15ms/step - loss: -0.6507 - acc: 0.0276 - val_loss: -0.6874 - val_acc: 0.0240
Epoch 7/5000
900/900 [==============================] - 15s 16ms/step - loss: -0.6517 - acc: 0.0279 - val_loss: -0.6877 - val_acc: 0.0260
Epoch 8/5000
900/900 [==============================] - 14s 16ms/step - loss: -0.6526 - acc: 0.0272 - val_loss: -0.6875 - val_acc: 0.0230
Epoch 9/5000
900/900 [==============================] - 14s 16ms/step - loss: -0.6530 - acc: 0.0274 - val_loss: -0.6879 - val_acc: 0.0240
Epoch 10/5000
900/900 [==============================] - 14s 15ms/step - loss: -0.6530 - acc: 0.0278 - val_loss: -0.6871 - val_acc: 0.0230
丢失的可能原因是什么val_loss这样变化不减少?是神经网络、训练数据还是其他什么地方出了问题?
如果您需要任何进一步的信息,我会提供。
感谢您的任何回复
我在 Keras 中使用 LSTM 训练聊天机器人的神经网络。
contextTrain, contextTest, utteranceTrain, utteranceTest = train_test_split(context, utterance, test_size=0.1, random_state=1)
model = Sequential()
model.add(LSTM(input_shape=contextTrain.shape[1:], return_sequences=True, units=300, activation="sigmoid", kernel_initializer="glorot_normal", recurrent_initializer="glorot_normal"))
model.add(LSTM(return_sequences=True, units=300, activation="sigmoid", kernel_initializer="glorot_normal", recurrent_initializer="glorot_normal"))
model.compile(loss="cosine_proximity", optimizer="adam", metrics=["accuracy"])
model.fit(contextTrain, utteranceTrain, epochs=5000, validation_data=(contextTest, utteranceTest), callbacks=[ModelCheckpoint("model{epoch:02d}.h5", monitor='val_acc', save_best_only=true, mode='max')])
上下文和话语是具有形状的 numpy 数组,例如(1000, 10, 300) 或 (10000, 10, 300)。 Input_shape 第一个 LSTM 应该是 (10, 300)。大小为 300 的向量是由 Word2vec 模型创建的词嵌入表示的词。所以在这个例子中输入数据是这些向量中的 10 个。
最大的问题是损失和val_loss在训练过程中几乎都在稳步增加。
Epoch 1/5000
900/900 [==============================] - 18s 20ms/step - loss: -0.5855 - acc: 0.0220 - val_loss: -0.6527 - val_acc: 0.0260
Epoch 2/5000
900/900 [==============================] - 13s 14ms/step - loss: -0.6299 - acc: 0.0239 - val_loss: -0.6673 - val_acc: 0.0240
Epoch 3/5000
900/900 [==============================] - 12s 14ms/step - loss: -0.6387 - acc: 0.0213 - val_loss: -0.6764 - val_acc: 0.0160
Epoch 4/5000
900/900 [==============================] - 12s 13ms/step - loss: -0.6457 - acc: 0.0229 - val_loss: -0.6821 - val_acc: 0.0240
Epoch 5/5000
900/900 [==============================] - 12s 14ms/step - loss: -0.6497 - acc: 0.0274 - val_loss: -0.6873 - val_acc: 0.0230
Epoch 6/5000
900/900 [==============================] - 14s 15ms/step - loss: -0.6507 - acc: 0.0276 - val_loss: -0.6874 - val_acc: 0.0240
Epoch 7/5000
900/900 [==============================] - 15s 16ms/step - loss: -0.6517 - acc: 0.0279 - val_loss: -0.6877 - val_acc: 0.0260
Epoch 8/5000
900/900 [==============================] - 14s 16ms/step - loss: -0.6526 - acc: 0.0272 - val_loss: -0.6875 - val_acc: 0.0230
Epoch 9/5000
900/900 [==============================] - 14s 16ms/step - loss: -0.6530 - acc: 0.0274 - val_loss: -0.6879 - val_acc: 0.0240
Epoch 10/5000
900/900 [==============================] - 14s 15ms/step - loss: -0.6530 - acc: 0.0278 - val_loss: -0.6871 - val_acc: 0.0230
丢失的可能原因是什么val_loss这样变化不减少?是神经网络、训练数据还是其他什么地方出了问题?
如果您需要任何进一步的信息,我会提供。
感谢您的任何回复