引导大型语言模型生成计算机可解析内容
Guiding Large Language Models to Generate Computer-Parsable Content
AI总结:
提出一种基于协程和上下文无关文法约束解码的方法,无需微调即可引导LLMs生成符合形式语言的结构化内容,显著提升准确率并降低错误率,增强LLM生成内容对计算机程序的可用性。
摘要:
我们提出一种无需微调即可引导大型语言模型(LLMs)生成遵循特定约定的结构化内容的方法。通过基于协程的内容生成约束,利用预先约定的上下文无关文法(CFG),在解码过程中引导LLMs生成符合形式语言的输出。这增强了生成目标数据结构、类型或指令的稳定性和一致性,降低了应用开发的复杂性。实验表明,GPT-2和Gemma在DSL长度分别超过36和282个token时,错误率超过95%。我们引入了YieldLang——一个基于协程的DSL生成框架,并在包括JSON和Mermaid流程图生成在内的多种任务上用LLMs进行了评估。与基准相比,我们的方法将准确率提高了1.09到11.6倍,且LLMs仅需约16.5%的样本即可有效生成JSON。这提升了LLM生成内容对计算机程序的可用性。
英文摘要:
We propose a method to guide Large Language Models (LLMs) in generating structured content adhering to specific conventions without fine-tuning. By utilizing coroutine-based content generation constraints through a pre-agreed context-free grammar (CFG), LLMs are directed during decoding to produce formal language compliant outputs. This enhances stability and consistency in generating target data structures, types, or instructions, reducing application development complexities. Experimentally, error rates of GPT-2 and Gemma exceed 95% for DSLs longer than 36 and 282 tokens, respectively. We introduce YieldLang, a coroutine-based DSL generation framework, and evaluate it with LLMs on various tasks including JSON and Mermaid flowchart generation. Compared to benchmarks, our approach improves accuracy by 1.09 to 11.6 times, with LLMs requiring only about 16.5% of the samples to generate JSON effectively. This enhances usability of LLM-generated content for computer programs.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。