ResearchPod Summary
Grammar Constrained Decoding (GCD) ensures that language models (LMs) produce syntactically valid outputs by masking out invalid tokens. However, this rigid masking distorts the model's original probability distribution, often forcing the model toward suboptimal or unnatural sequences. Existing solutions to this problem, such as online sampling, are computationally expensive and significantly increase inference latency. This paper asks: can we restore the LM's true probability distribution during constrained decoding using a lightweight, offline-trained correction that avoids the overhead of iterative resampling?
The authors propose SHIM, a probability controller that acts as a refinement layer on top of existing masking tools. The key insight is that the internal parser and lexer states—already maintained by incremental parsers to perform masking—contain sufficient information to predict future grammatical validity.
SHIM uses these states, along with the candidate next token, as features for a lightweight model (such as a logistic regressor or a small MLP). This model is trained offline to predict a correction factor (gamma) that adjusts the masked logits. By adding this factor to the logits during inference, the system effectively reweights the remaining valid tokens to better align with the base model's original, unconstrained distribution.
This work provides a practical path for deploying LMs in environments requiring strict adherence to formal grammars (e.g., SQL generation, code synthesis, or SMT solvers) without sacrificing the naturalness of the generated text or incurring the high latency costs of existing re-sampling techniques. It effectively reconciles the need for structural compliance with the need for high-quality, probabilistic text generation.
AI-generated third-party summary by ResearchPod. Not official content or an endorsement by the paper authors or affiliated organizations.