Course 2 Week 2 Assignment Viterbi Backward - 3 Tests passed 1 Test failed

Hi @Parva_Shah1,

Since it is the same issue, please go through the thread to find the solution everyone has discussed.

Best,
Mubsi

1 Like

Hey @Elemento Could you please help check my implementation ? I got similar error of 3 Tests Passed and 1 Failed.

I’ve seen the earlier thread and suggestions provided by you. Strange thing is, that the same logic when implemented outside the function (see Cell # 48 in my implementation) gives the right POS Tag values (used for comparison in Unit test). Not sure if the defined function is tweaked somehow while being tested.

Thanks a lot!

1 Like

Hello all! I’m having an issue getting a correct solution to pass all the viterbi_backward tests. I’m stuck passing 3 of 4. I must have the same bug as Andrea_Mucchietto and Laks_P. My error message is also:

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

I don’t think I have a loop termination issue (e.g. going negative and overwriting values) since my output is good from back-to-front until that POS->NNS mismatch in index 2.

It seems to point toward having calculated the best_paths/best_probs incorrectly, though those unit tests do all pass for earlier exercises. I considered that I might have needed to switch my comparison operators from simple > to >= but that didn’t make a difference.

Any advice on how I might be going off the rails in the middle of the sequence would be greatly appreciated!

[update] i reviewed the test case and I see that the test data isn’t coming out of my own functions calculating best probs/best paths (i.e. best_probs_trained.pkl & best_paths_trained.pkl), so I feel silly for wasting time going back and playing with > vs >=.

Digging into the test data, I see that best_paths[:, 2] holds:

array([20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
       20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
       20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20])

best_probs[:, 2] holds:

array([-34.08246498, -35.04774303, -31.98004656, -31.54577612,
       -31.458494  , -30.82774125, -36.06882128, -30.66814834,
       -30.82974049, -31.16166213, -33.49470398, -34.17479848,
       -33.68041085, -33.2715104 , -30.76329772, -33.62498805,
       -32.79264432, -35.45972557, -40.66384478, -31.09744119,
       -31.76796869, -27.01365762, -35.08029118, -24.51283921,
       -34.94760623, -14.86111162, -24.08622617, -35.12156603,
       -32.21095186, -31.30422632, -33.43032757, -33.25711527,
       -32.68292023, -31.11430048, -41.36716968, -34.62317307,
       -31.22161841, -32.35286973, -32.30871278, -32.85015674,
       -16.96666101, -31.08994954, -31.64407204, -31.74370627,
       -31.58127038, -32.77663331])

and…

np.argmax(best_probs[:, 2]) == 25
states[25] == "POS"

So, it appears that the right probability is not selected in my code…

1 Like

@Mubsi Hi, could you help me check where my problem is for exercise 7? Now I manually updated the result which made it pass the test. But I do want to know where my logic is false… Thank you!!

1 Like

@Mubsi is it possible that there is a defect in a test case? Manually sanity checking the first 5 columns of the test data shows:

states[np.argmax(best_probs[:, 4])]
'MD'
states[np.argmax(best_probs[:, 3])]
'NN'
states[np.argmax(best_probs[:, 2])]
'POS'
states[np.argmax(best_probs[:, 1])]
'NN'
states[np.argmax(best_probs[:, 0])]
'DT'

and, for reference, the indices of the rows w/best probability are:

np.argmax(best_probs[:, 4])
19
np.argmax(best_probs[:, 3])
20
np.argmax(best_probs[:, 2])
25
np.argmax(best_probs[:, 1])
20
np.argmax(best_probs[:, 0])
11

I think from this, I’m sure best_probs matches the expected answer.

Expectation:

  • the 4th column puts best_paths[pos_tag_for_word_i, i] into z[i-1], z[3] is 20 / NN
  • the 3rd column puts best_paths[pos_tag_for_word_i, i]into z[i-1], z[2] is 25 / POS
  • the 2nd column puts best_paths[pos_tag_for_word_i, i]into z[i-1], z[1] is 20 / NN
  • the 1st column puts best_paths[pos_tag_for_word_i, i]into z[i-1], z[0] is 11 / DT

Unfortunately, i see is the 2th column of z getting set to 23 from best_paths[20, 3].

  • pos_tag_for_word_i gets set to 25 (as expected) from best_paths[20, 3]
  • BUT best_paths[pos_tag_for_word_i, i] is 23, NOT 20 as expected based on the manual argmax checks

Just digging deeper into the 3th column of best_paths shows that the only values there are 40, 25, and 23:

best_paths[:, 3]
array([25, 25, 25, 25, 25, 25, 40, 25, 40, 25, 25, 40, 40, 25, 40, 25, 25,
       25, 25, 25, 25, 25, 25, 25, 40, 23, 40, 40, 40, 40, 25, 40, 25, 40,
       40, 40, 25, 25, 40, 25, 25, 40, 40, 25, 40, 25])
set(best_paths[:, 3])
{40, 25, 23}

This looks to me like it’s impossible to get an output of states[25] for preds[2] given this input.

Can you confirm that the test case is correct?

[Update 2]
Well, it wasn’t the test case. I finally figured out that I was actually misinterpreting where pos_tag_for_word_i should come from. For anyone else that sees the same “almost right” answer with POS/NNS mismatch… pos_tag_for_word_i = best_paths[z[i], i] is not the solution

1 Like

Hey @Parva_Shah1, @gauravleo and @Elainex,
Welcome, and we are glad that you could become a part of our community :partying_face:

First of all, please don’t share your Lab IDs, unless someone explicitly asks you for it. Second, please go through the suggested fixes above. And finally, if you have already done it, and still your issue persists, then please post your error stacks here, so that we can try to pin-point the issue.

@ankona, thanks a lot for sharing your insights with the community.

Cheers,
Elemento

Im having similar error where the starting tag is not completed. Im getting # instead of --s–. Could anyone help me?

ID is ajqnogepzgup

1 Like

Hi @Santiago_Elewaut,

Do you still need help with this ?

Best,
Mubsi

1 Like

Hi, Pls help me. I’m also unable to figure out what wrong am I doing in ex-7 pred[m-1] or for loop range…

1 Like

Hai @Mubsi
Can you please have look into my lab.
Unable to find out the exact error.
Please help me.
Lab id - yoyoukzosxhs

Thanks and regards,
Laxmidhar Routa

1 Like

Hi @Laxmidhar_Routa,

The assignment notebook you are using is an older version of the assignment, which you probably got from the internet.

Please make sure you are using the latest assignment version. You can get the latest version by following the instructions under the heading Refreshing your Workspace.

Get the latest version and attempt your assignment again. Don’t copy/paste your solution. Let me know if the issue still remains.

Best,
Mubsi

1 Like

Hi @Mubsi ,

I have the same mistake of my peers and I stucked.

Can you help me?
My lab code is wfyavpwbpjlp.

Thanks
Alexander

1 Like

Hello classmate.

I had the same problem like you. The problem was caused by the for loop range in the step 2.

Consider following case:

z = ['a', 'b', 'c', 'd']
z[-1] = 'z'
print(z)

As you guess the result is ['a', 'b', 'c', 'z']
Think about what is the last index value of pred[i - 1]?

I hope this will be a little help for you.

Regards,

1 Like

Hello @sugaprho ,
I’ve just solved my problem.
And it is not a little help, but a huge one.
I’ve passed all my weekend testing codes and, sometimes, what is obvius, we can’t see.
Thanks for your huge help.

Alexander Oliveira

2 Likes