NLP Spec. C4W1 unit test 'w1_unittest' seems faulty when used locally

Heads-up: the provided w1_unittest module used in the NLP Specialization C4W1 assignment seems faulty when used locally as opposed to when used in the online Coursera lab.

As a result, you can have a C4W1 assignment that runs fine in the Coursera cloud, but fails some or all of the unit tests when used on your local computer. Of course, in this situation, it means you have downloaded a zip file from the notebook environment that includes the provided utility functions and unit test modules. I should note I am working on Apple Silicon (an M3 Max), but I don’t think this caused the issue, as I eventually resolved it.

What was the remedy? You can simply delete or skip the unit tests (in a local environment) and have your notebook run to completion, if it is correct–or you can modify the unit test (as I did) until the tests run without errors when called from a notebook.

I think the problem I experienced was caused by variables being defined in the notebook environment which were never passed to the unit test functions.

The changes I had to make boiled down to a few things that affected multiple areas of the unit test. These were the primary issues:

You have to define these variables somewhere near the beginning of the w1_unittest module:

VOCAB_SIZE = 12000
UNITS = 256

Adjust the test_encoder (t.msg = "Incorrect third dimension of encoder output").

Adjust test_cross_attention (dummy_encoder_output = np.random.rand(64, 14, UNITS))

Adjust the test_decoder (t.msg = "Incorrect third dimension of decoder output").

Adjust the test_translator (t.msg = "Incorrect third dimension of translator output").

These changes (and there may have been a few others) enabled the unit tests to run with the specified vocabulary size and unit size, avoiding index out-of-bound errors and ensuring consistent tensor dimensions.

I think the instructors or mentors should upload a version of the unit test that works offline (assuming others are also experiencing this issue). In the end, I was able to get all the unit tests to complete without errors in my local environment.

I hope this helps!


Thanks for the information! :raised_hands:

1 Like

@lucas.coutinho, if there are issues in the structure of the notebook (i.e relies on global variables?), it might be worthwhile to clear these up.

(I don’t have access to the repo for this course, so I could not check if an issue has already been submitted.)

1 Like