这是我的模型以及我如何拟合和训练它。我正在使用 GRU 模型进行 NLP 生成。它开始运行良好,但在第 15 个时期左右,一切都发生了变化。我还不知道该归因于什么。
# Define a simple sequential model
def create_model():
model = Sequential()
model.add(tf.keras.layers.GRU(256, input_shape=(train_X.shape[1], train_X.shape[2]), return_sequences=True))
model.add(Dropout(0.5))
model.add(tf.keras.layers.GRU(512, return_sequences=True))
model.add(Dropout(0.5))
model.add(tf.keras.layers.GRU(700))
model.add(Dropout(0.5))
model.add(Dense(train_Y.shape[1], activation='softmax'))
model.compile(optimizer='adam',
loss='categorical_crossentropy',
metrics=[tf.metrics.CategoricalCrossentropy(), 'accuracy'])
return model
# Create a basic model instance
model = create_model()
# Display the model's architecture
model.summary()
这里是模型代码的拟合和保存:
checkpoint_path = "/content/gdrive/My Drive/NLP/training_4/cp.ckpt"
#checkpoint_dir = os.path.dirname(checkpoint_path)
# Create a callback that saves the model's weights
cp_callback = tf.keras.callbacks.ModelCheckpoint(filepath=checkpoint_path,
save_weights_only=True,
save_best_only = True,
verbose=1)
# Train the model with the new callback
history = model.fit(train_X,
train_Y,
epochs=50,
batch_size = 50,
validation_data=(X_valid, Y_valid),
callbacks=[cp_callback]) # Pass callback to training
This is the plotted training and validation loss 显然我还不能显示图片,因为我需要获得声望点数。
我该怎么做才能纠正这个问题?