Learning in hidden Markov models with bounded memory