A Bayesian framework for associative memories