I passed the predict model but the subsequent example for a different sentence fails

Can I get a hint on how to correct this, I have followed all the instructions as per assignment. @arvyzukai

I passed the predict test cell too but when it came to applying on another sentence it fails because of index error.

So I did correct with applying range and len(), yet I am getting the same mistake. Can anyone point on the mistake.

My assignment’s submission grader output

Thank you in advance

Regards
DP

Hi @Deepti_Prasad

Your mistake is that you loop over range(len(outputs)) which would be just 0,1,2,…,n.

outputs in this case contains the tag indices, so you don’t need the range(len()).

Cheers

are you stating I need to use only outputs??

Yes, outputs contain predicted tag indices, like 35, 2, 21, … etc.

You could also make your implementation work but with labels[outputs[tag_idx]] (instead of labels[tag_idx]) but that would not be a good practice.

Thank you solved.

1 Like

Why this would not be a good practice?

Let’s take an example to illustrate.

Let’s pretend we have a list a_list = [15, 2, 18, 2]

If we want to get each value of this list (for example, for printing), in Python we would need only:

for item_in_list in a_list:
    print(item_in_list)

We could also achieve that with:

for i in range(len(a_list)):
    print(a_list[i])

But that unnecessary creates an iterator for the index (0,1,2,3) which we don’t really need.

2 Likes