Hidden Markov and Maximum Entropy models, Viterbi algorithms and EM training