C3W3 - Assignment Value Error


I’m currently getting the following error when running the following code:

ValueError Traceback (most recent call last)
4 # Train the model and save the training history
----> 5 history = model.fit(train_pad_trunc_seq, train_labels, epochs=20, validation_data=(val_pad_trunc_seq, val_labels))

/opt/conda/lib/python3.8/site-packages/keras/utils/traceback_utils.py in error_handler(*args, **kwargs)
65 except Exception as e: # pylint: disable=broad-except
66 filtered_tb = _process_traceback_frames(e.traceback)
—> 67 raise e.with_traceback(filtered_tb) from None
68 finally:
69 del filtered_tb

/opt/conda/lib/python3.8/site-packages/keras/engine/data_adapter.py in _check_data_cardinality(data)
1655 for i in tf.nest.flatten(single_data)))
1656 msg += “Make sure all arrays contain the same number of samples.”
→ 1657 raise ValueError(msg)

ValueError: Data cardinality is ambiguous:
x sizes: 144000
y sizes: 16000
Make sure all arrays contain the same number of samples.

The code I’m running is the following:

print(len(train_pad_trunc_seq), len(train_labels),len(val_pad_trunc_seq),len(val_labels))

144000 16000 144000 16000

I mean is clear that data is the same length, does anyone knows how to fix this?

First its not allowed to publish the code here. I think here in your case the x and y matrices should have the same length i.e. for each x example there should be one y label. That what the error I think is telling you.