Structured learning and inference with neural networks and generative models