Training for HMM.