Help needed on debug strategy on viterby forward unittest

When running w2_unittest.test_viterbi_forward(viterbi_forward, A, B, prep, vocab) I get 2 tests failed:

Wrong values for best_paths.
Expected: [[ 0 11 20 25 20]
[ 0 11 20 25 20]
[ 0 11 20 25 20]
[ 0 11 20 25 20]
[ 0 11 20 25 20]].
Got: [[ 0 13506 22 22251 23562]
[ 0 13506 22 22251 23562]
[ 0 13506 22 22251 23562]
[ 0 13506 22 22251 23562]
[ 0 13506 22 22251 23562]].
Wrong values for best_paths.
Expected: [[20 19 35 11 21]
[20 19 35 11 21]
[20 19 35 11 21]
[20 19 35 11 21]
[35 19 35 11 34]].
Got: [[17077 10498 22320 2431 17163]
[17077 10498 22320 2431 17163]
[17077 10498 22320 2431 17163]
[17077 10498 22320 2431 17163]
[17077 10498 22320 2431 17163]].
4 Tests passed
2 Tests failed

Any suggestions how to tackle debug?

Hi @idjordje

It suggests that you incorrectly populated the best_paths. Make sure that set the correct range for k (range(num_tags)) and that you set correctly the best_path_i (best_path_i = k). These would be the first things to check.

Cheers

The range was right but the best_path_i was wrong … after correction all work.

But I run into similar situation in the next exercise where one of the unit tests failed (w2_unittest.test_viterbi_backward(viterbi_backward, prep, states)). The last item in the pred list is wrong. Any hints?

In general, how does one debug these loops? Single stepping is not practical. Instrumenting with printf produces huge outputs, … any other secret sauce?

-Ivan

Most probably you are using m instead of m-1 for index. Check this thread.

Debugging IPython or Jupyter Notebooks is not very elegant.
Here is my older post for debugging for beginners.

In short, you can call breakpoint() whenever you want to invoke the pdb debugger. Some versions do not support that, in that case you can use a more “hacky” way:
assert False, "breakpoint"

Cheers

I am using m-1 …

Here is the actual error:

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

I see it’s similar to the thread you pointed me to, so I’ll do some more digging