Learning Associative Memories with Gradient Descent