arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2403.01632cs.LGcs.FLcs.PLcs.SE
收藏

SynCode:基于语法增强的LLM生成

SynCode: LLM Generation with Grammar Augmentation

University of Illinois Urbana-Champaign(伊利诺伊大学厄巴纳-香槟分校);VMware Research(威睿研究院)

Shubham Ugare, Tarun Suresh, Hangoo Kang, Sasa Misailovic, Gagandeep Singh

AI总结:

SynCode框架通过DFA掩码存储实现基于CFG的语法解码,消除JSON语法错误并减少96.07%的Python/Go语法错误,提升LLM生成精度。

摘要:

大型语言模型(LLM)被广泛应用于复杂的AI应用中。这些应用强调LLM的输出需要遵循特定格式,以便与系统中的其他组件集成。通常,格式规则(例如JSON、YAML或编程语言代码等数据序列化格式)以上下文无关文法(CFG)表示。由于LLM的幻觉和不可靠性,指导LLM遵循指定语法成为一个日益重要的挑战。我们提出了SynCode,一个用于LLM高效且通用的语法解码的新框架,以解决这一挑战。SynCode确保相对于形式语言的CFG的健全性和完整性,有效保留有效令牌同时过滤掉无效令牌。SynCode使用离线构建的高效查找表——DFA掩码存储,该存储源自语言语法的DFA,以实现高效生成。SynCode无缝集成任何由CFG定义的语言,实验聚焦于生成JSON、Python和Go输出证明了这一点。我们评估SynCode在JSON生成中的有效性的实验表明,SynCode消除了所有语法错误,并显著优于最先进的基线。此外,我们的结果强调了SynCode如何显著减少生成的Python和Go代码中96.07%的语法错误,展示了其在增强LLM生成语法精度方面的重大影响。我们的代码可在https://github.com/uiuc-focal-lab/syncode获取。

英文摘要:

LLMs are widely used in complex AI applications. These applications underscore the need for LLM outputs to adhere to a specific format, for their integration with other components in the systems. Typically the format rules e.g., for data serialization formats such as JSON, YAML, or Code in Programming Language are expressed as context-free grammar (CFG). Due to the hallucinations and unreliability of LLMs, instructing LLMs to adhere to specified syntax becomes an increasingly important challenge. We present SynCode, a novel framework for efficient and general syntactical decoding with LLMs, to address this challenge. SynCode ensures soundness and completeness with respect to the CFG of a formal language, effectively retaining valid tokens while filtering out invalid ones. SynCode uses an offline-constructed, efficient lookup table, the DFA mask store, derived from the DFA of the language's grammar for efficient generation. SynCode seamlessly integrates with any language defined by CFG, as evidenced by experiments focusing on generating JSON, Python, and Go outputs. Our experiments evaluating the effectiveness of SynCode for JSON generation demonstrate that SynCode eliminates all syntax errors and significantly outperforms state-of-the-art baselines. Furthermore, our results underscore how SynCode significantly reduces 96.07% of syntax errors in generated Python and Go code, showcasing its substantial impact on enhancing syntactical precision in LLM generation. Our code is available at https://github.com/uiuc-focal-lab/syncode

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑