Flexible and Efficient Grammar-Constrained Decoding

要約

大規模な言語モデル(LLM)は、コードスニペットやフォーマットされたデータなど、正確な構文ルールに従う構造化された出力を生成するように求められることがよくあります。
文法制約のデコード(GCD)は、指定されたコンテキストフリーグラマー(CFG)に属さない出力につながるトークンをマスキングすることにより、LLM出力がそのようなルールと一致することを保証できます。
健全性を保証するために、GCDアルゴリズムは、特定のLLMサブワードトークネイザーが、特定のコンテキストフリーの文法で使用されているトークンとどのように整合し、この情報に基づいてトークンマスクを計算することができるかを計算する必要があります。
効率的にそうすることは挑戦的であり、既存のGCDアルゴリズムは一般的な文法を前処理するのに数十分かかります。
新しいGCDアルゴリズムと、オンラインマスク計算の最先端の効率を維持しながら、既存のアプローチよりも17.71倍のオフラインの前処理を提供する実装を提示します。

要約(オリジナル)

Large Language Models (LLMs) are often asked to generate structured outputs that obey precise syntactic rules, such as code snippets or formatted data. Grammar-constrained decoding (GCD) can guarantee that LLM outputs matches such rules by masking out tokens that will provably lead to outputs that do not belong to a specified context-free grammar (CFG). To guarantee soundness, GCD algorithms have to compute how a given LLM subword tokenizer can align with the tokens used by a given context-free grammar and compute token masks based on this information. Doing so efficiently is challenging and existing GCD algorithms require tens of minutes to preprocess common grammars. We present a new GCD algorithm together with an implementation that offers 17.71x faster offline preprocessing than existing approaches while preserving state-of-the-art efficiency in online mask computation.

arxiv情報

著者 Kanghee Park,Timothy Zhou,Loris D’Antoni
発行日 2025-02-07 17:35:17+00:00
arxivサイト arxiv_id(pdf)

提供元, 利用サービス

arxiv.jp, Google

カテゴリー: cs.AI, cs.CL パーマリンク