GrammarRL: Effective Grammar-Constrained Decoding via Reinforcement Learning

📄 arXiv: 2609.39869v1 📥 PDF

作者: Gabriele Tuccio, Antonino Furnari, Aldo Gangemi, Misael Mongiovì

分类: cs.AI, cs.CL, cs.LG

发布日期: 2026-09-30


💡 一句话要点

提出GrammarRL以解决语法约束生成中的语义质量问题

🎯 匹配领域: 支柱二:RL算法与架构 (RL & Architecture) 支柱九:具身大模型 (Embodied Foundation Models)

关键词: 语法约束生成 强化学习 自我监督学习 自然语言处理 机器翻译 文本生成 命名实体识别

📋 核心要点

  1. 现有的语法约束生成方法在保证句法有效性的同时,往往会导致语义质量下降,尤其在提示不明确时更为明显。
  2. 论文提出的GrammarRL通过自我监督的奖励机制优化语言模型,使其在遵循语法约束的同时提升语义质量,且不需要标注数据。
  3. 实验结果表明,GrammarRL在多个任务上平均提升9.8分,最高可达22.8 BLEU,且在两个任务上与束搜索表现相当或更优。

📝 摘要(中文)

语法约束生成确保句法有效性,但当模型的优选输出与所施加的语法不一致时,可能会显著降低语义质量。尤其在提示不明确或模型指令跟随能力有限时,这种权衡尤为严重。我们提出GrammarRL,这是一种无标签的强化学习方法,能够在不需要标注数据的情况下使语言模型适应语法约束。GrammarRL利用自我监督的奖励优化模型,包括直接奖励和反向奖励。我们在手语词汇翻译、层次文本分类和命名实体识别等任务上评估GrammarRL,结果显示其在多个任务上均优于受限贪婪解码,且在保持贪婪解码推理成本的同时,部分任务的表现与束搜索相当或更优。

🔬 方法详解

问题定义:本论文旨在解决语法约束生成中语义质量下降的问题,现有方法如束搜索在计算成本和语义质量之间存在权衡,且在提示不明确时表现不佳。

核心思路:GrammarRL通过引入自我监督的奖励机制,优化语言模型在遵循语法约束的同时提升生成内容的语义质量,避免了对标注数据的依赖。

技术框架:GrammarRL的整体架构包括两个主要模块:直接奖励和反向奖励。直接奖励评估生成输出的可能性,反向奖励则评估从生成输出重构输入的能力。优化过程采用Reinforce Leave-One-Out (RLOO)目标,结合束搜索的顶级假设进行正则化。

关键创新:最重要的技术创新在于引入了两种互补的自我监督奖励机制,能够有效提升模型在语法约束下的生成质量,这与传统的基于概率的优化方法有本质区别。

关键设计:在设计中,直接奖励和反向奖励的组合被证明是互补的,单独使用任一奖励可能无法超越未训练的基线,而其组合则能持续改进模型性能。

🖼️ 关键图片

fig_0
img_1
img_2

📊 实验亮点

实验结果显示,GrammarRL在手语词汇翻译、层次文本分类和命名实体识别任务上,平均提升9.8分,最高可达22.8 BLEU,且在两个任务上与束搜索的表现相当或更优,同时保持了贪婪解码的推理成本。

🎯 应用场景

该研究的潜在应用领域包括自然语言处理中的语法约束生成任务,如机器翻译、文本生成和对话系统等。通过提高生成内容的语法和语义质量,GrammarRL能够为实际应用提供更可靠的输出,进而推动相关技术的发展与应用。

📄 摘要(原文)

Grammar-constrained generation guarantees syntactic validity, but can substantially degrade semantic quality when the model's preferred outputs are poorly aligned with the imposed grammar. This trade-off is particularly severe when the prompt is underspecified or the model has limited instruction-following ability. Beam search can partially mitigate these failures by exploring multiple valid sequences, but its computational cost grows with beam width, while sequence-level probability is only an imperfect proxy for semantic quality. We introduce GrammarRL, a label-free reinforcement learning method that adapts language models to grammar constraints without requiring annotated data. GrammarRL optimizes the model using two complementary self-supervised rewards derived from its own likelihoods: a direct reward, measuring how likely the constrained output is given the input, and a reverse reward, measuring how well the input can be reconstructed from the generated output. We optimize these rewards with a Reinforce Leave-One-Out (RLOO) objective over groups of grammar-constrained rollouts, augmented with the top-1 beam-search hypothesis and regularized towards a frozen base model. We evaluate GrammarRL on sign language gloss translation, hierarchical text classification, and named entity recognition using Llama models ranging from 1B to 8B parameters. GrammarRL consistently outperforms constrained greedy decoding, with an average improvement of 9.8 points and gains of up to 22.8 BLEU. It matches or outperforms beam search on two of the three tasks while preserving greedy-decoding inference cost. Ablations further show that the two rewards are complementary: either reward alone can underperform the untrained baseline, whereas their combination consistently improves upon it.