[论文解读] Code as Policies: Language Model Programs for Embodied Control
本文表明,能写代码的LLM能够从自然语言命令生成机器人策略代码,以控制感知-动作循环,从而在多机器人上实现无额外训练的反应式和基于航点的策略,借助分层代码生成。
Large language models (LLMs) trained on code completion have been shown to be capable of synthesizing simple Python programs from docstrings [1]. We find that these code-writing LLMs can be re-purposed to write robot policy code, given natural language commands. Specifically, policy code can express functions or feedback loops that process perception outputs (e.g.,from object detectors [2], [3]) and parameterize control primitive APIs. When provided as input several example language commands (formatted as comments) followed by corresponding policy code (via few-shot prompting), LLMs can take in new commands and autonomously re-compose API calls to generate new policy code respectively. By chaining classic logic structures and referencing third-party libraries (e.g., NumPy, Shapely) to perform arithmetic, LLMs used in this way can write robot policies that (i) exhibit spatial-geometric reasoning, (ii) generalize to new instructions, and (iii) prescribe precise values (e.g., velocities) to ambiguous descriptions ("faster") depending on context (i.e., behavioral commonsense). This paper presents code as policies: a robot-centric formulation of language model generated programs (LMPs) that can represent reactive policies (e.g., impedance controllers), as well as waypoint-based policies (vision-based pick and place, trajectory-based control), demonstrated across multiple real robot platforms. Central to our approach is prompting hierarchical code-gen (recursively defining undefined functions), which can write more complex code and also improves state-of-the-art to solve 39.8% of problems on the HumanEval [1] benchmark. Code and videos are available at https://code-as-policies.github.io
研究动机与目标
- 将语言与现实世界的感知-动作循环结合的动机,旨在减少数据收集和训练需求。
- 展示能写代码的LLM能够从自然语言指令生成可执行的机器人策略。
- 提出分层代码生成以组合复杂策略并提升泛化能力。
- 展示 CaP 在多种机器人和任务中的应用,包括反应控制和基于视觉的操作。
- 引入一个聚焦于机器人领域的代码生成基准并分析规模效应。
提出的方法
- 使用 OpenAI Codex 根据作为注释提供的自然语言指令生成类似 Python 的策略代码。
- 用_instruction-to-code_映射的示例进行提示(小样本),以生成处理感知输出并控制执行器的策略代码。
- 通过递归定义未定义函数来实现分层代码生成,以构建更大、可重用的策略模块。
- 通过在受限的全局/局部作用域内使用 Python 的 exec 安全地在真实机器人上执行生成的 LMPs。
- 将 LMP 与感知和控制 API(例如开箱词汇检测器、NumPy、Shapely,以及 PD/阻抗式原语)绑定。
- 在机器人基准测试(RoboCodeGen、HumanEval)和真实硬件上对桌面和移动操作任务进行评估。
实验结果
研究问题
- RQ1能否让能够写代码的 LLM 将自然语言指令翻译为可执行的机器人策略,从而对感知和控制参数进行推理?
- RQ2分层代码生成是否提升了机器人策略的质量和泛化能力,以及标准代码生成基准?
- RQ3与基于语言的规划器和传统模仿学习基线相比,CaP 在机器人任务中的表现如何?
- RQ4感知驱动的开词汇检测器和控制原语在多大程度上实现了 LMPs 的灵活任务绑定?
- RQ5CaP 在跨领域和不同模型规模下的局限性与规模性行为是什么?
主要发现
- 分层代码生成提高了策略质量和代码生成基准,在较大的 Codex 模型下在 HumanEval 上达到 39.8% 的 P@1。
- CaP 通过开词汇感知和可编程控制原语,在多种机器人平台上实现了反应式和基于航点的策略。
- CaP 可以泛化到未见指令和对象,并且能够在无需额外训练的情况下将策略代码适应到新任务。
- 在机器人基准测试中,CaP 在已见属性场景下达到或超过某些监督基线的性能,并对未见属性和任务显示出强健的泛化能力。
- 更大的模型和分层提示与代码生成和机器人任务的更好性能相关。
更好的研究,从现在开始
从阅读论文到最终审阅,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。