Exact inference on linear chain CRF