C2_W2 UNQ_C5 getting math domain error. please help

for i in range(num_tags): # Replace None in this line with the proper range.

    # Initialize best_probs at POS tag 'i', column 0
    # Check the formula in the instructions above
    best_probs[i,0] = best_probs[i,0] = math.log(A[s_idx,i]) + math.log(B[i,vocab[corpus[0]]] )

Hi @Arin_Jain

The error tells that your code is probably taking a log of a number that is less than or equal to zero.

So make sure that the matrix A is greater than zero - make sure that the outputs after UNQ_C3 matches the expected outputs:

Expected Output

A at row 0, col 0: 0.000007040
A at row 3, col 1: 0.1691
View a subset of transition matrix A
              RBS            RP           SYM        TO            UH
RBS  2.217069e-06  2.217069e-06  2.217069e-06  0.008870  2.217069e-06
RP   3.756509e-07  7.516775e-04  3.756509e-07  0.051089  3.756509e-07
SYM  1.722772e-05  1.722772e-05  1.722772e-05  0.000017  1.722772e-05
TO   4.477336e-05  4.472863e-08  4.472863e-08  0.000090  4.477336e-05
UH   1.030439e-05  1.030439e-05  1.030439e-05  0.061837  3.092348e-02

Cheers