Overview
This work addresses challenges in generating constrained outputs from large language models (LLMs), specifically when these outputs need to conform to predefined structures like JSON schema. Existing Locally Constrained Decoding (LCD) methods, which enforce constraints by masking subsequent tokens, can introduce sampling bias and degrade performance. The research proposes a generic approach for constructing proposal distributions and potential functions suitable for Sequential Monte Carlo (SMC) sampling in scenarios where the sampling is conditioned on a constraint ($p_{\mathrm{lm}}( \cdot \mid \mathrm{constraint})$).
Research Context
Large language models frequently generate text that must adhere to specific constraints, such as the structure defined by a JSON schema. Prior methods, like locally constrained decoding, enforce these constraints by a myopic masking process on next tokens. This masking, while ensuring constraint adherence, can lead to biased sampling within the generative process and a reduction in overall performance. Recent efforts have utilized Sequential Monte Carlo (SMC) methods to address these biases. However, the design of effective proposal distributions or potential functions for SMC sampling, particularly for constrained generation, has remained an active area of investigation.
Approach
The proposed methodology centers on constructing proposals and potentials for SMC sampling conditioned on a given constraint. The approach involves two primary steps:
-
Tensorization of Finite Automata: Constraints specified as finite automata are tensorized. This tensorized representation is designed for efficient execution on Graphics Processing Units (GPUs). This efficiency is then leveraged to construct Globally Constrained Decoding (GCD) proposals.
-
Circuit Multiplication for Probabilistic GCD (P-GCD) Proposals: The research identifies that tensorized finite automata possess a circuit structure analogous to hidden Markov models. By applying circuit multiplication, the method obtains Probabilistic GCD (P-GCD) proposals. These P-GCD proposals integrate both logical constraint information and probabilistic data regarding the target distributions.
Findings
The efficacy of both GCD and P-GCD proposals was evaluated relative to LCD proposals within an identical SMC sampling framework. The evaluation was conducted across three distinct tasks:
- Function calling
- Keyword-based generation
- SQL generation
Experimental results indicated that the (P-)GCD proposals achieved faster convergence to the target distribution. Furthermore, this faster convergence was observed with a significantly reduced number of particles when compared to traditional LCD proposals.
Why This Matters
The ability to generate constrained text from large language models without introducing sampling bias is crucial for applications requiring high fidelity to structured formats or specific content requirements. Biased sampling can lead to suboptimal or incorrect outputs, diminishing the utility of LLMs in controlled environments. The proposed method aims to mitigate these known biases in locally constrained decoding, potentially improving the reliability and quality of LLM generations across various structured data tasks.