I'm trying to classify IMDB movie reviews with binary classification using Keras. The following is the code I used.
from keras import models
from keras import layers
model = models.Sequential()
model.add(layers.Dense(16,activation="relu",input_shape=(10000,)))
model.add(layers.Dense(16,activation="relu"))
model.add(layers.Dense(1,activation="sigmoid"))
model.compile(optimizer="rmsprop",loss="binary_crossentropy", metrics=["acc"])
history = model.fit(partial_x_train,partial_y_train, epochs=20, batch_size=512, validation_data = (x_val, y_val))
shapes of each input tensors are as follows.
print(partial_x_train.shape) --> (15000, 10000)
print(partial_y_train.shape)--> (15000, 10000)
print(x_val.shape) --> (10000, 10000)
print(y_val.shape) --> (10000, 10000)
But on executing the above program, I get the following error.
ValueError: in user code:
ValueError: logits and labels must have the same shape ((None, 1) vs (None, 10000))
I searched through a lot of SO questions, but couldn't understand what I have done wrong. Can someone help me to avoid this error and make the model compiled?
As stated
ValueError
, you're trying to compute the loss of between shape((None, 1)
vs(None, 10000))
. It would be clear if you posted or refer the training set of IMDB. Try with in-built IMDB data set fromkeras
.According to your model