我已经为文本分类建立了这个网络:
model = Sequential()
model.add(Embedding(vocabulary_dim, 150, input_length=max_length))
model.add(LSTM(150, return_sequences=False))
model.add(Dense(1, activation='softmax'))
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
当我拟合模型时:
model.fit(X_train, y_train, validation_data=(X_val, y_val), epochs=5, batch_size=128)
我收到此错误:
ValueError: Error when checking model target: expected dense_9 to have shape (None, 1) but got array with shape (12481, 3)
我想因为y_train和y_val被one-hot编码,形状:
array([[ 1., 0., 0.],
[ 0., 1., 0.],
[ 1., 0., 0.],
.............])
但我不确定这一点。