ValueError: Data cardinality is ambiguous: x sizes: 11367 y sizes: 2842 Make sure all arrays contain the same number of samples [closed]

I try to train the dataset from this Kaggle IMDB dataset but got a different shape of the data.

With these code:

# Membuat arsitektur model menggunakan embedding

model = tf.keras.Sequential([
    tf.keras.layers.Embedding(input_dim=80000, output_dim=16),
    tf.keras.layers.LSTM(64),
    tf.keras.layers.Dense(128, activation='relu'),
    tf.keras.layers.Dense(64, activation='relu'),
    tf.keras.layers.Dense(6, activation='softmax')
])

# Compile model
model.compile(loss="categorical_crossentropy",
              optimizer="adam",
              metrics=['accuracy'])

#Melatih model
tweet_train = tf.stack(tweet_train)
label_test = tf.stack(label_test)

num_epochs=30
history = model.fit(
    np.array(tweet_train),
    np.array(label_test),
    epochs=num_epochs,
    validation_data=(padded_test, label_test),
    verbose=2
)

But the output is

“ValueError: Data cardinality is ambiguous:
x sizes: 11367
y sizes: 2842 Make sure all arrays contain the same number of samples”

How can I fix this?

  • You are passing training tweets and testing labels to mode.fit, of course it would not work, pass the correct variables.

    – 

  • Yes, i made a mistake. Thanks for the reply.

    – 

Leave a Comment