[论文解读] Prompting Is Programming: A Query Language for Large Language Models
本文提出了语言模型编程(LMP)和LMQL,一种高级查询语言,通过引入脚本、约束和控制流,扩展自然语言提示,以实现高效、准确且成本低廉的语言模型推理。LMQL通过运行时的逐标记验证和优化解码,将模型调用和计算量减少高达85%,同时在下游任务上保持或提升准确性。
Large language models have demonstrated outstanding performance on a wide range of tasks such as question answering and code generation. On a high level, given an input, a language model can be used to automatically complete the sequence in a statistically-likely way. Based on this, users prompt these models with language instructions or examples, to implement a variety of downstream tasks. Advanced prompting methods can even imply interaction between the language model, a user, and external tools such as calculators. However, to obtain state-of-the-art performance or adapt language models for specific tasks, complex task- and model-specific programs have to be implemented, which may still require ad-hoc interaction. Based on this, we present the novel idea of Language Model Programming (LMP). LMP generalizes language model prompting from pure text prompts to an intuitive combination of text prompting and scripting. Additionally, LMP allows constraints to be specified over the language model output. This enables easy adaption to many tasks while abstracting language model internals and providing high-level semantics. To enable LMP, we implement LMQL(short for Language Model Query Language), which leverages the constraints and control flow from an LMP prompt to generate an efficient inference procedure that minimizes the number of expensive calls to the underlying language model. We show that LMQL can capture a wide range of state-of-the-art prompting methods in an intuitive way, especially facilitating interactive flows that are challenging to implement with existing high-level APIs. Our evaluation shows that we retain or increase the accuracy on several downstream tasks, while also significantly reducing the required amount of computation or cost in the case of pay-to-use APIs (26-85% cost savings).
研究动机与目标
- 解决现有提示方法效率低下且复杂的问题,这些方法需要手动进行模型特定的实现,计算成本高。
- 在无需深入了解分词、解码或模型内部机制的前提下,实现直观、高级别的语言模型编程。
- 减少交互式和受限提示工作流中昂贵的语言模型调用次数。
- 为不同模型和API提供可移植、约束感知且高效的语言模型交互接口。
- 证明受限的、脚本驱动的提示方法可在显著降低计算和经济成本的同时,实现最先进性能。
提出的方法
- 提出语言模型编程(LMP)范式,将自然语言提示与轻量级脚本和输出约束统一起来。
- 引入LMQL,一种领域特定语言,允许用户使用类似Python的控制流、变量赋值和列表推导式编写提示。
- 在解码过程中进行逐标记验证和约束检查,避免回溯,减少模型调用次数。
- 使用查询优化引擎,通过分析LMQL程序中的约束和控制流,生成高效的推理流程。
- 通过可扩展的操作符支持外部验证器(如语法检查器、代码执行器)的集成,实现语义和语法验证。
- 通过将LMQL程序转换为优化的推理管道,执行LMQL程序,最大限度减少昂贵的模型调用。
实验结果
研究问题
- RQ1能否设计一种高级查询语言,将大语言模型的自然语言提示与脚本和约束统一起来?
- RQ2此类语言是否能在保持或提升准确性的同时,减少模型调用次数和计算成本?
- RQ3与现有API相比,提示中集成控制流和约束如何提升效率和可用性?
- RQ4LMQL在简洁高效地表达复杂、前沿的提示技术(如思维链或自一致性)方面,其表达能力如何?
- RQ5在按使用量计费的API环境中,LMQL能否在不牺牲模型性能的前提下实现显著的成本节约?
主要发现
- 与基线提示方法相比,LMQL将模型调用次数减少了高达85%,显著降低了推理成本。
- 该框架在多个下游任务上实现或提升准确性,约束有时还能增强输出质量。
- LMQL程序比等效的Python实现缩短多达10倍,提升了开发人员生产力。
- 使用运行时的逐标记验证消除了分块解码和回溯的需求,提高了效率。
- 在按使用量计费的API环境中,LMQL将可计费的标记数减少了高达80%,带来显著的成本节约。
- LMQL支持复杂、交互式的提示流程(如迭代推理、受限生成),这些流程在现有高级API中难以实现。
更好的研究,从现在开始
从阅读论文到最终审阅,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。