Need help understanding this Python Viterbi algorithm

You are looking at a list comprehension.

The expanded version looks something like this:

all_probs = []

for j in range(max(0, i - max_word_length), i):
    all_probs.append((probs[j] * word_prob(text[j:i]), j))

prob_k, k = max(all_probs)

I hope that helps explain it. If it doesn’t, feel free to edit your question and point to statements that you don’t understand.

Leave a Comment