UNQ_C7 GRADED FUNCTION: viterbi_backward, 3/4 tests correct

Hi, can I ask for some help to point out my mistake here?

1 Like

Hi @Ynx

It’s hard to predict only from this result, but it looks like you might have hard-coded ‘–s–’ token as being 0 (since 0th tag is “#”). I would check for this first.

@arvyzukai I think I didn’t do any hard coding in my code. Is it possible for you to check my solution? I can give you my lab code ID.

Mentors cannot access notebooks by ID, only staff members can.

You might also want to check # UNQ_C6:
# Go through every word in the corpus starting from word 1

Because it looks like you got other tags correct except the last one. Maybe you stopped early in viterbi_forward

and in # UNQ_C7:

    ## Step 2 ##
    # Find the best POS tags by walking backward through the best_paths
    # From the last word in the corpus to the 0th word in the corpus

check if you start from the last tag to the first

@arvyzukai Thank you for the extra information. I tried changing the codes in UNQ_C7 but to no avail. Also, I looked at UNC_6, particularly your comment but that is already pre-defined and not part of the coding area. I’m quite baffled on where to look.

What information can I offer to clarify my problem?

I was talking about for loops.

I see you could have made a mistake by stopping too early in # UNQ_C6 (if the for loop doesn’t cover the last token).

Or more likely you could have started not from the very last token in # UNQ_C7 (if the for loop does not start from m-1).

The main point I’m suggesting by looking at your results is that you backtracked all the tokens correct except the last one (or first one if looking from the end) which by the looks is 0 (or “#”) and not 6 (or “–s–”)

@arvyzukai I understand your point and I think I did not stop early. Is it okay to send you snippets of my code for better communication?

For the future reader, the mistake was in # UNQ_C7 after this instruction:

            # Store the new best probability for the last word

Check that you provide the same index values (row, column) as in if statement that you are checking.

Same problem here, I am a little lost :frowning:

Wrong values for pred list.
Expected: [‘PRP’, ‘MD’, ‘RB’, ‘VB’, ‘PRP’, ‘RB’, ‘IN’, ‘PRP’, ‘.’, ‘–s–’].
Got: [‘PRP’, ‘MD’, ‘RB’, ‘VB’, ‘PRP’, ‘RB’, ‘IN’, ‘PRP’, ‘.’, ‘#’].
3 Tests passed
1 Tests failed

Please read the previous suggestion. Does it apply to you?

I am also running into the same issue that just the last prediction is not correct. I’ve looked at a number of things including checking if Q5 and Q6 are correct (they seem to be, they also pass through all the unit tests without any issue). For the rest:

  • There isn’t any spot where I’ve hardcoded the ‘–s–’ token in any way
  • The indices match for the # Store the new best probability for the last word section
  • the loop in the # From the last word in the corpus to the 0th word in the corpus does correctly run from the very last word down to the very first

At this point I am very confused by what is causing the issue, is there anything else I need to look into?

For completion, this is the error I get from the unit tests for C7:
Wrong values for pred list.
Expected: [‘PRP’, ‘MD’, ‘RB’, ‘VB’, ‘PRP’, ‘RB’, ‘IN’, ‘PRP’, ‘.’, ‘–s–’].
Got: [‘PRP’, ‘MD’, ‘RB’, ‘VB’, ‘PRP’, ‘RB’, ‘IN’, ‘PRP’, ‘.’, ‘``’].
3 Tests passed
1 Tests failed

1 Like

Some hints for anyone stuck at the backward pass:

  • I kept failing the unit test until I noticed a few small, yet significant indexing bugs in viterbi_backward :slight_smile:
  • For anyone wondering: the instructions in the comments are correct, but not literally. Try thinking through their logic instead of simply copying the values and you will most definitely pass the unit test!
  • Lastly, this is the hardest part of the assignment. Once you get through it you will be done, and have learned some very valuable coding skills :slight_smile:

I believe in you! You can do this!


You need to set z[m - 1] correctly.
It should be the row of highest probability in best_probs which is k.

Hi @Victor_Onink

I got the same “test failed” as you. Did you finde a solution to this problem?
I have checked all the code, line-by-line, and it is starting to drive me nuts…


The last value (z[-1]) is set after the loop for the first part. That’s where the subtle bug was for me.

I have a related problem:

Wrong values for pred list.
Expected: [‘DT’, ‘NN’, ‘POS’, ‘NN’, ‘MD’, ‘VB’, ‘VBN’, ‘IN’, ‘JJ’, ‘NN’].
Got: [‘DT’, ‘NN’, ‘NNS’, ‘NN’, ‘MD’, ‘VB’, ‘VBN’, ‘IN’, ‘JJ’, ‘NN’].
3 Tests passed
1 Tests failed

For me apparently the problem is a POS difference, in this case NNS instead of POS.

Did any of you encounter this?

Thank you in advance.