Representation learning using generative models