W2 - Creating the mask for masked_accuracy Exercise 5

NER Assignment
Hello, I’m stuck creating the mask in Exercise 5. In the lecture, Jonas asks if we can think of a simple way to mask the padded values. I need a hint of how to do this in Exercise 5. I know that we mask the padded values in the loss function in Exercise 4. But here, I believe, we’re not calculating the loss, just masking the values, so I’m unsure how to perform the task. To be clear, I’m not getting an error in my function; it’s just returning an incorrect value.

My question concerns what goes on the mask = None line. I just need a hint about how to approach this line. Note: I have not included any answers in my image.

Thanks for your help!

There are similar threads in the same course category which might help you resolve your issue.

Things to check in instructions before this cell, use correct axis(-1)

I’ve read through the threads, and I set the axis correctly. My question just concerns how the “create the mask.” For instance, do I need to call a function earlier in the assignment, create a conditional, or potentially call the Masking layer from tensorflow?

It may just be really simple, but the course materials repeatedly say you need to create a mask, but never demonstrate how to do so without just relying on built-in tensorflow functions.

You need to use tf.math.argmax

1 Like

This is just a note for later readers. I figured out this problem, but this moderator’s recommendation does not respond to my question. That is, you don’t need to use the tf.math.argmax function to create the mask; that function is of course for a later line when you’re identifying the predicted value.

If you have the same issue I did, my recommendation is to figure out a way to do y_true !=-1 to create the mask. TF has a built-in function for doing this, but it’s not mentioned in the lectures or the assignment notebook. I eventually found it in the TF documentation. Good luck and feel free to message me if you get stuck!

2 Likes

Thank you for the correction :grinning: @collinj

1 Like