Grader issue in the last assignment of NLP Specialization

Hi everyone,

I’m working on the last assignment of NLP Specialization. I’m encountering a NameError: name 'tokenizer' is not defined error, even though the tokenizer variable seems to be defined earlier in the code.

I’ve already tried restarting the kernel and running all cells in order, but the error persists. I’ve also double-checked for any typos or redefinitions of the tokenizer variable.

Has anyone else encountered this issue? Any suggestions on how to troubleshoot this?

Thanks in advance for your help!

There are more possibilities:

  1. You might’ve missed an earlier error - there might’ve been another error related to a variable or chain of variables referenced by tokenizer. Or there was an error with the SentencepieceTokenizer module.
  2. The variable ‘tokenizer’ may not be in the scope of the module (eg: function) you’re using it from.

Cross check by clicking Kernel → Restart and clear output, then select the cell of interest and click Cell → Run all above. If there’s an error in the earlier cells your code will stop executing much before the selected cell is reached.

Hi Naveen,

Thanks for your response! I’ve looked into the possibilities you mentioned. However, the functions I implemented are working fine when I run them in the Jupyter notebook.

I also tried copying the definition of the tokenizer variable inside the functions being graded, but that didn’t solve the issue. I checked, and the problem seems to be occurring much earlier in the notebook, before reaching the graded functions. This suggests that the issue isn’t caused by my code, since the only functions we need to complete are the three graded ones.

I also sent you a private message with a .py file containing my three functions for grading. How should I proceed from here?

Thanks again for your help!

No thats not a good practice, I would suggest revert the assignment to its original state from Question Mark on Top Right Corner and then “Get Latest Version”. There might be a possibility of conflict between global and local variables here.

1 Like

earlier when a learner had reported with such error, they had modified the call argument tokenizer to Tokenizer from None but this issue was related course 3 of NLP

So make sure you aren’t modifying anything outside the markers ###START AND END CODE HERE###

Another reason would you must have tokenizer function where it wasn’t required.

Another issue could be one must have used tokenizer function incorrect while tokenizing the question or answer.

Also remember course3 and course 4 after update have only 3 weeks and 3 assignments.

Regards
DP

I tried that as well, following all the steps outlined in one of the topics about issues with the grader itself, but it didn’t work. Even after selecting “Get latest version,” the same error still appeared.

Thanks for your inputs. I checked all that too.

please share screenshots of your grade function codes by personal dm

2 Likes

Hi. Thank you for your fast answer and sorry for the delay.
Well, I just sent you a private message with he code. And here is a print where you can see on the left side a part of the code (not implemented by me) and on the right side the error I mentioned.

“Get latest version” only replaces missing files. It does not automatically overwrite an existing file.

So before you can use “Get latest version”, you have to rename or delete your original ipynb file.

Yes. That’s what I did.

@MarcoGam2410

error is not because of the code cell screenshot you shared here, it is related to the codes you wrote in Grade Function cells. Please DM me screenshots of grade function cells.
see in the below section for exercise 1, under def statement, tokenizer=None is mentioned, so if anyone changes this to tokenizer, you get the tokenizer not defined error.

as I suspected you have the same error, please refer here my previous comment where I have shared a screenshot.

Another mistake in your code is for the line

Add EOS token to the end of the targets
You were only suppose to append the eos to the targets as that step is recalled as eos for the code line EOS token id, but you used the function again which was not required.

Oh. It seemed so intuitive that I didn’t even realised I changed it. Thank you so much !

1 Like

Another grader error: Score Counter Error: Score Counter Feedback Not Found
Visit the discussion forum to see if colleagues are experiencing similar errors or have found solutions. If the error is not resolved within 24 hours, contact Coursera through our Help Center. - In my third graded function

I have a few updates. Now I’m getting this error from the grader: There was an error grading your submission. Details:
in user code:

File "/grader/transformer_utils.py", line 547, in create_padding_mask  *
    seq = 1 - tf.cast(tf.math.equal(decoder_token_ids, 0), tf.float32)

TypeError: Failed to convert elements of <transformer_utils.Transformer object at 0x7f4053ae7ac0> to Tensor. Consider casting elements to a supported type. See https://www.tensorflow.org/api_docs/python/tf/dtypes for supported TF dtypes.

as you already have created a new topic for your new error, I am replying on that created topic to avoid confusion.

Also point to be noted, it seems even after you having not passed test cell you are submitting assignment, having type error on submisson cannot happen until you encountered that error while writing incorrect code for a grade function. So always focus on first making sure your grade function cells are correctly coded before submission. this saves your time and ofcourse makes you better at debugging your codes.

1 Like