C3W4 assignment: failed pad_seqs unit test

Unit test output:
All tests passed for n_gram_seqs!

Details of failed tests for pad_seqs

Failed test case: There was an error grading this function. Details shown in ‘got’ value below:.
Expected:
no exceptions,
but got:
operands could not be broadcast together with shapes (5,6) (5,5) .

All tests passed for features_and_labels!

All tests passed for create_model!

My output:

array([[ 0, 0, 0, 0, 34, 417],
[ 0, 0, 0, 34, 417, 877],
[ 0, 0, 34, 417, 877, 166],
[ 0, 34, 417, 877, 166, 213],
[ 34, 417, 877, 166, 213, 517]], dtype=int32)

Expected output:

array([[ 0, 0, 0, 34, 417],
[ 0, 0, 34, 417, 877],
[ 0, 34, 417, 877, 166],
[ 34, 417, 877, 166, 213],
[417, 877, 166, 213, 517]], dtype=int32)

Note that in the expected case, the first element (34) is missing from the last list, i.e., the padding removes the first element, for the last sequence. In my output, the last sequence still has 34 as the first element.

My output for features_and_labels() is also different, in the same way (although my implementation of features_and_labels() passed the unit test):

My output:
labels have shape: (5, 3211)

features look like this:

array([[ 0, 0, 0, 0, 34],
[ 0, 0, 0, 34, 417],
[ 0, 0, 34, 417, 877],
[ 0, 34, 417, 877, 166],
[ 34, 417, 877, 166, 213]], dtype=int32)

Expected Output:
labels have shape: (5, 3211)

features look like this:

array([[ 0, 0, 0, 34],
[ 0, 0, 34, 417],
[ 0, 34, 417, 877],
[ 34, 417, 877, 166],
[417, 877, 166, 213]], dtype=int32)
Note again that the expected output is missing 34 on the last line, but I still have it.

I’d appreciate help with this. Thank you!

Thanks for bringing this up.
Your implementation is correct. The staff have been notified to fix the exercise. While waiting for a fix, I recommend you move forward by using the maxlen function parameter instead of calculating it.

Do remove code from your post. It’s okay to leave stacktrace around in public posts.

Hi Ambresh,

Thank you very much for your help, and for the prompt response!
Understood, thank you for the explanation and suggestion.
Sorry about the code - I removed it, together with the statement of what it was.

Thank you again, really appreciate your help! I’ve seen you’ve been super helpful for so many others on these forums as well - many thanks!

Notebook has been updated, thanks for flagging!