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

Hi Elemento!

I have put the correct range for the for loop still I am getting the same error.
Should I DM my lab code to you?
Thanks!!

1 Like

Hey @hc_lau and @Aaditya1,
Please DM me your implementation for the function, so that we can try to figure out the issue.

P.S. - Apologies @hc_lau for the delayed response. Since you didn’t mention my tag or replied to my comment, hence, I wasn’t notified of your reply. For future reference, it’'s always better to tag the name of the person to whom you are replying.

Cheers,
Elemento

Hey Elemento,

Thanks for your response!! I was able to solve the issue on my own after some brainstorming. Thinking and writing the code from fresh perspective helped.

1 Like

Hey @Aaditya1,
We are glad that you were able to solve your issue on your own, after all, there is nothing better than that. Thanks for letting us know that your issue has been resolved.

Cheers,
Elemento

1 Like

Hi @Elemento
I have the same issue as this: do you have any other ideas that could cause this?

1 Like

@Elemento Oh well, I just changed the tags id in pred[m-1] =states[tag id]and pred[i-1]=states[tag id] to the corresponding z-value. And it works. I feel weird because I thought z-value and the tag id are the same thing. isn’t it? or am I missing something important here? Ah, took me a while :smiling_face_with_tear: but I am still confused. :dotted_line_face:

1 Like

Hey @Fei_Li,
I am a little unclear as to what you have changed. Additionally, I don’t see any variable tag id in the implementation. Can you please elaborate a little bit more on this?

Cheers,
Elemento

Hi Mentor @Elemento yea it’s not clearly stated, sorry about that. But I think I have understood it. Please ignore the following part if you are not interested. But I will post it here so that maybe in the future when someone encounters the same they can take a look :partying_face::

When we loop through all the tags for the last word, we find the kth row giving us the largest probability. So, we save this k in z[m-1], i.e. z[m-1] = k, like the example, z[2] = 28, tag id is 28 for the last word. Then we store this tag for id 28 in pred[m-1] using states, i.e. pred[m-1] = states[z[m-1]].

However, if we overlook the fact that k is a variable which is used for looping, and may or may contain the index for the row with the best probability, we tend to use pred[m-1] = states[k], instead of pred[m-1] = states[z[m-1]].

In simple words, the thing to note here is that k changes in every iteration, however z[m-1] only changes when we encounter the row with the best probability yet observed.

image

3 Likes

Hey @Fei_Li,
I have modified your answer a little bit to make it more convenient for the learners. Let me know if it’s okay with you, otherwise, I will be more than happy to revert it back to the original version.

Cheers,
Elemento

Hey @Elemento,
I have the same issue:

I double-checked pretty much every suggestion in the thread, I checked each line of the EX7 code at least 3 times. I spent ~2 hours sitting and checking out all of my variables and loops… Can I share my function with you so you will point me to the mistake, please?

1 Like

Hey @leggard,
The issue in your implementation lies in Step-2, more particularly, where you have defined the range for the for loop. Check this reply out, and I am sure you will be able to figure out the error by yourself.

Cheers,
Elemento

Thanks! I played with that second loop for a while and tried the correct solution once. Still, there had to be another issue that was failing the test and I didn’t realize that it wasn’t connected with the loop and so I proceeded to change it in the wrong direction :smiley:

1 Like

I’m running into the same error and believe I have checked out all the suggestions. Can I share my function with you to get some advice. Thanks.

1 Like

I encountered a similar issue & spend couple of hours to debug. In my case, The problem turned out to be that there were two for loops, and we needed to use the index of the first loop in the second loop. The variable for the index was not available in the second loop. To fix this, we stored the value of the index in a variable within the first loop, and then used that variable to access the corresponding tag value in the second loop.

1 Like

Hey @shassanchi,
Thanks a lot for sharing your insights.

And @carolsexton, please do let us know if your issue has been resolved yet or not. If I may recall correctly, I believe that you were able to figure out the issues in your implementation.

Cheers,
Elemento

Thank you for checking. Yes, your hint allowed me to fix the problem and was much appreciated.

Best,
Carol

1 Like

OMG This was it!! you are the champ!

1 Like

Hey @Elemento Could you please help check my implementation? I got similar error. Thanks a lot!

1 Like

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

Can you please confirm if you have already gone through the above suggested fixes or not? If not, then I would urge you to go through them, and see if your issue gets resolved.

P.S. - Only staff members have access to your Lab IDs, and not the mentors. So, please don’t post it unless and until someone explicitly asks you for it.

Cheers,
Elemento

Hey I am having the same issue, @Mubsi can you help me spot my mistake ?

1 Like