Efficient Structured Prediction with Latent Variables for General Graphical Models