adding some training code to build HMM