我正在尝试训练我的Sequential模型,但出现了一些问题:
aspect_categories_model = Sequential()
aspect_categories_model.add(Dense(512, input_shape=(6000,), activation='relu'))
aspect_categories_model.add(Dense(5, activation='softmax'))
aspect_categories_model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])当尝试使用:aspect_categories_model.fit(aspect_tokenized, dummy_category, epochs=5, verbose=1).预测值时,我得到了一个值错误:
ValueError: Shapes (None, 6) and (None, 5) are incompatible虚拟人的代码是:
from sklearn.preprocessing import LabelEncoder
from keras.utils import to_categorical
label_encoder = LabelEncoder()
integer_category = label_encoder.fit_transform(dataset.aspect_category)
dummy_category = to_categorical(integer_category)标签是5。
发布于 2020-09-08 23:12:59
dummy_category的形状为(batch_size, 6),模型的输出形状为(batch_size, 5)。
尝试更改最后一层中的神经元数量。
aspect_categories_model.add(Dense(6, activation='softmax'))如果你只有5个类别用于预测,那么你在计算dummy_category变量时就犯了一些错误。
https://stackoverflow.com/questions/63796421
复制相似问题