验证和准确性损失为0.00

时间:2020-07-10 10:10:09

标签: python

这是我的代码

len(labels), len(reviews)

(4423,4423)

x_train.shape, y_test.shape

(((2211,5,256),(2211,2))

batch_size = 500
no_epochs = 100
from keras.models import Sequential
from keras.layers import Conv1D, Dropout, Dense, Flatten, LSTM, MaxPooling1D, Bidirectional
from keras.optimizers import Adam
from keras.callbacks import EarlyStopping, TensorBoard


model = Sequential()

model.add(Conv1D(32, kernel_size=3, activation='relu', padding='same',
                 input_shape=(max_no_tokens, vector_size)))
model.add(Conv1D(32, kernel_size=3, activation='relu', padding='same'))
model.add(Conv1D(32, kernel_size=3, activation='relu', padding='same'))
model.add(MaxPooling1D(pool_size=3))

model.add(Bidirectional(LSTM(512, dropout=0.2, recurrent_dropout=0.3)))

model.add(Dense(512, activation='sigmoid'))
model.add(Dropout(0.2))
model.add(Dense(512, activation='sigmoid'))
model.add(Dropout(0.25))
model.add(Dense(512, activation='sigmoid'))
model.add(Dropout(0.25))

model.add(Dense(2, activation='softmax'))

model.compile(loss='categorical_crossentropy', optimizer=Adam(lr=0.0001, decay=1e-6), metrics=['accuracy'])

tensorboard = TensorBoard(log_dir='logs/', histogram_freq=0, write_graph=True, write_images=True)

model.summary()
model.fit(x_train, y_train, batch_size=batch_size, shuffle=True, epochs=no_epochs,
         validation_data=(x_test, y_test), callbacks=[tensorboard, EarlyStopping(min_delta=0.0001, patience=3)])

我的输出看起来像这样:

Train on 2211 samples, validate on 2211 samples
Epoch 1/100
2211/2211 [==============================] - 4s 2ms/step - loss: 0.0000e+00 - accuracy: 0.9887 - val_loss: 0.0000e+00 - val_accuracy: 1.0000
Epoch 2/100
2211/2211 [==============================] - 2s 751us/step - loss: 0.0000e+00 - accuracy: 0.8580 - val_loss: 0.0000e+00 - val_accuracy: 1.0000
Epoch 3/100
2211/2211 [==============================] - 2s 780us/step - loss: 0.0000e+00 - accuracy: 0.6332 - val_loss: 0.0000e+00 - val_accuracy: 0.0000e+00
Epoch 4/100
2211/2211 [==============================] - 2s 804us/step - loss: 0.0000e+00 - accuracy: 0.4265 - val_loss: 0.0000e+00 - val_accuracy: 0.0000e+00
<keras.callbacks.callbacks.History at 0x7fc287d60828>

当我在数据集上运行上述代码时,我将获得0.0%的验证损失和验证准确度,我将在不同的数据集上尝试使用不同的转换和测试百分比,但我仍然得到0的准确度,这是我做错的任何一个请引导我。 我的数据集看起来像这样,有4423条评论。我正在附上数据集的图片。 enter image description here

0 个答案:

没有答案