The rise of large language models (LLMs) has introduced a new type of programming: natural language programming. By writing prompts that direct LLMs to perform natural language processing, code generation, reasoning, etc., users are writing code in natural language -- natural language code -- for the LLM to execute. An emerging area of research enables interoperability between natural language code and formal languages such as Python. We present a novel programming abstraction, shared program state, that removes the manual work required to enable interoperability between natural language code and program state. With shared program state, programmers can write natural code that directly writes program variables, computes with program objects, and implements control flow in the program. We present a schema for specifying natural function interfaces that extend programming systems to support natural code and leverage this schema to specify shared program state as a natural function interface. We implement shared program state in the Nightjar programming system. Nightjar enables programmers to write Python programs that contain natural code that shares the Python program state. We show that Nightjar programs achieve comparable or higher task accuracy than manually written implementations (+4-19%), while decreasing the lines of code by 39.6% on average. The tradeoff to using Nightjar is that it may incur runtime overhead (0.4-4.3x runtime of manual implementations).
翻译:大型语言模型(LLMs)的兴起催生了一种新型编程范式:自然语言编程。通过编写提示词来指导LLMs执行自然语言处理、代码生成、推理等任务,用户实际上是在用自然语言编写代码——即自然语言代码——供LLM执行。一个新兴的研究领域致力于实现自然语言代码与Python等形式化语言之间的互操作性。本文提出了一种新颖的编程抽象——共享程序状态,它消除了实现自然语言代码与程序状态互操作性所需的人工操作。借助共享程序状态,程序员可以编写能直接写入程序变量、与程序对象进行计算并实现程序控制流的自然代码。我们提出了一种用于规范自然函数接口的架构,该架构可扩展编程系统以支持自然代码,并利用此架构将共享程序状态定义为一种自然函数接口。我们在Nightjar编程系统中实现了共享程序状态。Nightjar使程序员能够编写包含自然代码的Python程序,这些自然代码可与Python程序状态共享数据。实验表明,Nightjar程序在任务准确率上达到或优于手动编写的实现(提升4-19%),同时平均减少39.6%的代码行数。使用Nightjar的代价是可能产生运行时开销(手动实现运行时间的0.4-4.3倍)。