implementing the viterbi algorithm for named entity recognition