C3W2_Assignment - masked_accuracy - truth value of an array with more than one element is ambiguous

Notebook tests for masked_accuracy passed.

But the grader is giving this error:

There was an error grading your submission. Details:
The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

I am stuck, please help.

I am having real problems in the Notebook.

When I resubmit, I often get this an error on all four functions that were previously OK.

image

I am not a mentor for this course, so we may have to wait for Arvydas or Deepti to give a real answer, but there are a few generic things to try. The most important is to make sure the state of your notebook is in sync. Try these steps:

Kernel → Restart and Clear Output
Save
Submit to the grader

There are a couple of points about that:

  1. The grader doesn’t need to see your output, it only calls your functions.
  2. In some of the courses here, clicking “Submit” does not do an autosave, so the grader may be seeing an older version of your code if you have made changes and not saved.

Getting the same error on all functions usually means a structural problem in your notebook file.

When I do the kernel stuff, didn’t change results (all cells were showing same error).

When I copy my version with four good functions, add the fifth function (and pass tests), and then resubmit, the first four functions pass grader and the fifth tests give me the previously mentioned error:

image

There is error in your code recall.

Kindly refer the below link to verify your codes for masked_accuracy grade cell

But you might still encounter error as your first grade cell has an error.

Send the screenshot of codes via personal DM

Regards
DP

Hi @januttall

As mentioned by @paulinpaloalto you do need to restart and clear output, save and resubmit for the error related to get_sentence_vectorizer grade cell as your code for this cell is correct but the next cell contain mention of [:1000] which might have got somehow got error, so the best way to resolve this issue would be to get a fresh copy and re-do the assignment.

But your codes needs correction for other grade cell, I will explain you as per grade cell name.

  1. for GRADED FUNCTION: label_vectorizer
    You have mentioned the below code for element id as empty list
    Use the dictionaty tag_map passed as an argument to the label_vectorizer function
    # to make the correspondence between tags and numbers.
    element_ids = [ ]

HOW TO CORRECT:
The tag_map is a dictionary that maps the tags that you could have to numbers. Run the cell below to see the possible classes you will be predicting. So Use the tag_maps.get function to the token with the corresponding value of -1 under the for token loop

  1. for masked accuracy grade cell, your codes are incorrect for
    A. Create the mask, i.e., the values that will be ignored
    FOR THIS YOU HAVE WRITTEN CORRECT CODE BUT MARKED IT # USING tf.not_equal was correct and using != is incorrect.

B. Multiply the acc tensor with the masks
you do not require tf.cast to get the matches_true_pred, the first code line was enough.

C. INCORRECT CODES FOR Compute masked accuracy (quotient between the total matches and the total valid values, i.e., the amount of non-masked values)
YOU DO not REQUIRE TO USE tf.cast.
as you applied separately tf.reduce_sum which was correct you did not require to use corresponding padding value of -1.
Instruction only mentions you to check quotient between matches_true_pred to mask. Here tupling the numerator to denominator also need to be done.

With being said all this, I feel there must have been some editing in your assignment which caused the issue with your first grade cell, so I highly recommend you get a fresh copy and then re-do these corrections before submit the assignment.

HOW TO GET A FRESH COPY: Check below link

Let me know if the issue still persist.
P.S. Sorry for the delayed response as I was busy in work.

Regards
DP

Thanks for getting back to me with so much detail.

I am working through it right not.

I get this message when first entering notebook. Should I be doing something?

I did all the cleaning operations that you mentioned, redid the code (pass the first five tests in the notebook), and failed all the grader tests:
image

You made comments about two of the functions that I did not fully understand. Here is what I have now. Are they incorrect still?

!images removed by moderator, against code of conduct and community guidelines

hi @januttall

please don’t post codes here.

and the correction done by you are still incorrect. please read the comments one by one.

Also for grade one cell issue, I told you delete the copy of assignment you are working or re-do the whole assignment again.

You can refer the same copy to write codes where you passed for other grade cell and do the corrections as mentions for grade cell 2 for label vectorizer and masked accuracy.

for masked accuracy, your last code line is still incorrect as I told you to not add any value labels of -1 to the masked_true_pred or mask. Also I told you to separately tuple the numerator and denominator.

Please use edit option to remove the codes screenshot from public post.

P.S. make sure before you get a fresh copy, you are suppose to click File ==> Open and then select all the files then click the delete option(dustbin emicon). You will get a 404 error. At this time click on the right top corner :question:, click reboot. then click again :question:, click Get the latest Version, then click Update Lab.

at this time, you will have a fresh copy.

Regards
DP

Hi @januttall

That Message information is related Coursera jupyter notebook update and you can either leave it or update it. that is not related to your assignment codes.

Regards
DP

Hi @januttall

Lets resolve your issue one by one as you seem to not understand the corrections when mentioned as whole.

First kindly confirm me did you delete all the files before getting a fresh copy of the assignment?

Regards
DP

I deleted everything, which required going down several layers in the folder structure because the delete would not remove a non-empty directory.

Now get a fresh copy by follow the comment tag mentioned here.

Confirm once done. Also kindly tag my name when you respond as I am not getting notification of your response.

I did all of that, from 404 error to Update Lab.

(Deepti, don’t know how to tag your name from Reply, don’t see any place to do so.)

To tag a person you just add “@” and their ID. Like this @Deepti_Prasad. As soon as you type the first few characters, you’ll get a selection list for possible IDs.

Deepti, what I’ve been noticing lately is that the email notifications of replies on threads you are “Watching” are incredibly slow to arrive. It usually takes at least single digit hours, so that makes it not very useful. But I get the message counts on my avatar in the upper right and those seem to be basically instantaneous.

so now you have a fresh copy in hand right? thank you paul, when you use @ you get mention of all the people commenting on your thread, just select the one you want to respond in case my name is tough to spell out.

@januttall

hi @paulinpaloalto

I am getting immediate notification mail to my email id for post I have commented but as I have not allowed any notification on my mobile, I miss out sometime especially when my name is not tagged.

I don’t like to use more phone, so I keep my notifications off other than for deep learning.AI

@Deepti_Prasad Ah, that makes sense. I almost never use my phone for doing anything related to DLAI or Coursera. It’s just too annoying typing with my thumbs on the tiny screen. :laughing:

@paulinpaloalto

I use rarely phone to response for code related issue, but can’t stay long in front of laptop in case there is no response from the learner. So I check DLAI mobile app which is helpful in reducing my screen time as when required :slight_smile:

@januttall I am back on screen waiting for your response, lets finish your issue before I sign off.

Regards
DP

1 Like