ValueError: Shapes (None, 4)和(None, 5)不兼容



这是我的脚本:

from tensorflow.keras.callbacks import EarlyStopping, ModelCheckpoint
model = Sequential()
model.add(Embedding(vocab_size, embedding_dim, input_length=train_padded.shape[1]))
model.add(Conv1D(48, 5, activation='relu', padding='valid'))
model.add(GlobalMaxPooling1D())
model.add(Dropout(0.5))
model.add(Flatten())
model.add(Dropout(0.5))
model.add(Dense(5, activation='softmax'))
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
epochs = 100
batch_size = 32
history = model.fit(train_padded, training_labels, shuffle=True ,
epochs=epochs, batch_size=batch_size, 
validation_split=0.2,
callbacks=[ReduceLROnPlateau(monitor='val_loss', factor=0.2, patience=3, min_lr=0.0001), 
EarlyStopping(monitor='val_loss', mode='min', patience=3, verbose=1),
EarlyStopping(monitor='val_accuracy', mode='max', patience=3, verbose=1)])

有一个错误:ValueError:形状(None, 4)和(None, 5)不兼容

你有什么想法吗?这是原来的笔记本:https://github.com/snymanje/MultiClass-Text-Classification-with-Tensorflow/blob/master/MultiClass_Text_Classification_with_Tensorflow.ipynb当我添加数据库时,我在拟合模型时得到了这个错误。

谢谢

看起来你的标签和你的模型没有联系。

试着改变这一行:

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

相关内容

  • 没有找到相关文章

最新更新