Grader Error: "name 'text_vectorization' is not defined" in Week 3 Programming Assignment

Hi,

I’m encountering a persistent error when submitting the Week 3 programming assignment (Question Duplicates) in the NLP Sequence Models course. The grader returns the following error message:

There was an error grading your submission. Details:
name 'text_vectorization' is not defined

Context:

  • I’ve implemented the Siamese, TripletLoss, train_model, classify, and predict functions as per the assignment instructions.

  • The text_vectorization layer is defined and adapted correctly using tf.keras.layers.TextVectorization, and it’s passed to Siamese and train_model. The Siamese model includes text_vectorization as a layer, so classify and predict pass raw string inputs as expected.

  • I noticed a similar issue reported in this thread: Error in grading. Details: name ‘text_vectorization’ is not defined C3W3, but no clear solution was provided.

Steps Taken to Resolve:

  1. Ensured text_vectorization is defined and adapted to the training data (Q1_train and Q2_train) before calling any functions.

  2. Added text_vectorizer as an optional parameter (text_vectorizer=None) to classify and predict to match potential grader expectations, even though the model handles tokenization internally.

  3. Reset the notebook using the “Refresh your workspace” option to restore the original state and avoid issues from modified cells.

  4. Ran all cells in order (Kernel > Restart & Run All) to ensure proper execution.

  5. Tested classify and predict locally with sample data, confirming they work without errors when passing text_vectorization.

  6. Checked the w3_unittest tests, which call classify and predict without explicitly passing text_vectorizer, but my functions handle this with the optional parameter.

Issue:
Despite these efforts, the grader still reports “name ‘text_vectorization’ is not defined”. I suspect this might be due to:

  • A grader bug, as others have reported similar issues.

  • A locked grader cell referencing text_vectorization directly, expecting it to be defined differently.

  • A mismatch with the pre-trained model (model/trained_model.keras) used in classify and predict.

Request:
Has anyone resolved this error or found a workaround? Could it be a grader issue, as suggested in the linked thread? Any guidance from mentors or learners on ensuring text_vectorization is recognized by the grader would be greatly appreciated. I’ve also submitted a bug report to Coursera’s Learner Help Center but wanted to check here for community insights.

Thank you!

Hi @stiansd17

First, double-check that your implementation and definitions of all functions are correct and match the assignment instructions (keep in mind that passing test cases does not guarantee passing the grader as well). Then, ensure that text_vectorization is defined (globally), so the grader can access it directly.

Hope it helps! Feel free to ask if you need further assistance.