Viterbi_forward (# UNQ_C6): int() argument must be a string, a bytes-like object or a number, not 'NoneType'

Grade cell codes removed. Posting correct or incorrect codes is against community guidelines

---> 68             best_paths[j,i] = best_path_i
     69 
     70         ### END CODE HERE ###

TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

I checked several related topics, but still stuck with this one. What am I doing wrong?

Rather than posting codes, kindly post screenshot of the complete error you have encountered.

Also as the code in question are from loop statements, posting a screenshot of error is better choice then copy pasting the error.

Please follow code of conduct which tells you sharing or posting any part of graded assignment link, grade cell codes is considered violation of code of conduct. Please refer FAQ section for better understanding on how to use discourse community.

please DM screenshot of viterbi forward code cell by personal DM. Click on my name and then message.

Looking at the error it looks like best_path_i is assigned to None. If this was the default value assigned to the variable, you’ll find comments with instructions to correct it. Please set the correct value and rerun the code.

Hi @petrovvl

Errors

  1. For each unique POS tag that the current word can be, the current wouldn’t be ( 1, num_tags) but num tags

  2. Same mistake done for code line
    For each POS tag that the previous word can be

  3. [quote=“petrovvl, post:1, topic:737864”]

#Calculate the probability = None
# best probs of POS tag k, previous word i-1 + 
# log(prob of transition from POS k to POS j) + 
# log(prob that emission of POS j is word i)

[/quote]

For this instruction your code is correct but perhaps there is a mistake when the pos tags were not mentioned as a proper list when you use j it is not a list, but [j] this will include all the each unique POS tag.

  1. For code line
    check if this path’s probability is greater than
    the best probability up to and before this point

First you only need to mention the path conditional probability for probability to check is > best_path_i without mentioning the position of previous POS Tag or Previous POS tag.

  1. Lastly

The below instruction

#keep track of the POS tag of the previous word
# that is part of the best path.  
# Save the index (integer) associated with 
# that previous word's POS tag

wanted you to recall the best_path_i according to the previous word’s POS tag which comes from the instruction

For each POS tag that the previous word can be

So you must used k as post tag, so you were suppose to use k for the best_path_i as that was POS tag of the previous word.

Regards
DP

It worked. Thank you!

1 Like