[论文解读] Octopus: On-device language model for function calling of software APIs
本文介绍了 Octopus,一个针对 30,000 多个软件 API 进行微调的本地设备 2B、3B 和 7B 参数语言模型家族,旨在提升函数调用的准确性。通过利用课程学习、数据集筛选以及推理阶段的新型条件掩码技术,Octopus 在 API 函数调用方面的准确性超过了 GPT-4,同时保持了低延迟和格式正确性。
In the rapidly evolving domain of artificial intelligence, Large Language Models (LLMs) play a crucial role due to their advanced text processing and generation abilities. This study introduces a new strategy aimed at harnessing on-device LLMs in invoking software APIs. We meticulously compile a dataset derived from software API documentation and apply fine-tuning to LLMs with capacities of 2B, 3B and 7B parameters, specifically to enhance their proficiency in software API interactions. Our approach concentrates on refining the models' grasp of API structures and syntax, significantly enhancing the accuracy of API function calls. Additionally, we propose extit{conditional masking} techniques to ensure outputs in the desired formats and reduce error rates while maintaining inference speeds. We also propose a novel benchmark designed to evaluate the effectiveness of LLMs in API interactions, establishing a foundation for subsequent research. Octopus, the fine-tuned model, is proved to have better performance than GPT-4 for the software APIs calling. This research aims to advance automated software development and API integration, representing substantial progress in aligning LLM capabilities with the demands of practical software engineering applications.
研究动机与目标
- 开发一种轻量级、本地设备部署的 LLM,能够在不依赖 GPT-4 等大型昂贵模型的情况下,准确调用软件 API。
- 解决 LLM 生成的 API 调用中格式错误和幻觉问题,特别是在参数选择和函数名匹配方面。
- 通过条件掩码技术提升推理效率和输出可靠性,确保输出结构符合正确的 JSON 样式。
- 为评估 LLM 在真实世界 API 交互任务中的表现建立新的基准。
- 通过训练参数量小但 API 调用准确率高的模型,实现 LLM 在移动设备和边缘设备上的实际部署。
提出的方法
- 在来自 RapidAPI Hub 的 30,000 多个软件 API 的筛选数据集上,对 2B、3B 和 7B 参数模型(如 CodeLlama、Gemma、Stable Code)进行微调。
- 采用课程学习和负采样策略,以提升模型泛化能力,并减少相似 API 函数之间的混淆。
- 在推理阶段设计了一种条件掩码技术,以约束输出格式,尤其针对枚举类型参数,确保语法正确性。
- 使用包含 few-shot 示范和结构化输入的提示模板,引导函数和参数的选择。
- 在推理过程中采用贪婪解码策略,以最大化函数和参数预测的精确度。
- 构建了一个新基准,包含平衡的可解/不可解查询,并配有由人工标注的真实答案用于评估。
实验结果
研究问题
- RQ1小型本地设备 LLM 是否能在真实世界软件 API 函数调用任务中超越 GPT-4?
- RQ2条件掩码在减少 LLM 生成的 API 调用中的格式错误和幻觉方面有多有效?
- RQ3课程学习和数据集筛选在提升模型在复杂 API 选择与参数生成任务上的性能方面,其作用有多大?
- RQ4紧凑型 LLM 是否能在保持低推理延迟和移动端设备部署可行性的同时,实现高 API 交互准确率?
- RQ5当在多样化、真实世界的 API 数据集上进行微调时,模型规模(2B、3B、7B)对 API 调用准确率的影响如何?
主要发现
- Octopus 7B 模型在所提出的基准测试中,函数调用准确率超过了 GPT-4,函数名和参数预测的精确度均更高。
- 条件掩码显著提升了输出格式的正确性,尤其在枚举类型参数方面,减少了验证损失,且未增加推理时间。
- 所有 Octopus 模型在函数名预测上均表现出近乎完美的准确率,但参数幻觉是基线 GPT-4 输出中的主要错误来源。
- 条件掩码技术在数学上被证明可通过将输出空间限制在有效格式内,从而提高准确性。
- Octopus 系列中的 7B 模型在准确率上超过了 GPT-4,证明了小型、任务特定的模型在专用 API 任务中可超越大型通用模型。
- 数据集和基准已开源,为未来在本地设备 LLM 用于 API 交互方面的研究提供了基础。
更好的研究,从现在开始
从阅读论文到最终审阅,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。