论文标题
提示是编程:大语言模型的查询语言
Prompting Is Programming: A Query Language for Large Language Models
论文作者
论文摘要
大型语言模型在各种任务上表现出了出色的表现,例如问答和代码生成。在高水平上,给定输入,可以使用语言模型以一种明显的统计方式自动完成序列。基于此,用户提示这些模型使用语言说明或示例,以实现各种下游任务。高级提示方法甚至可能意味着语言模型,用户和外部工具(例如计算器)之间的相互作用。但是,要获得针对特定任务的最新性能或适应语言模型,必须实现复杂的任务和特定于模型的程序,这可能仍然需要临时交互。 基于此,我们介绍了语言模型编程(LMP)的新颖概念。 LMP概括了从纯文本提示到文本提示和脚本的直观组合的语言模型。此外,LMP允许在语言模型输出上指定约束。这可以轻松适应许多任务,同时将语言模型内部设备抽象并提供高级语义。 为了启用LMP,我们实现了LMQL(语言模型查询语言的缩写),该LMP从LMP提示中利用了约束和控制流以生成有效的推理过程,该过程将昂贵的调用数量最小化,以最大程度地减少对基础语言模型的昂贵调用。 我们表明,LMQL可以以直观的方式捕获广泛的最新提示方法,尤其是促进与现有高级API实施的互动流动的互动流。我们的评估表明,在付费使用API的情况下(节省26-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).