Constrained decoding with weighted automata