Sequential Labeling with Latent Variables: An Exact Inference Algorithm and its Efficient Approximation