[论文解读] Gorilla: Large Language Model Connected with Massive APIs
Gorilla 是一个在 LLaMA-7B 上进行微调、引入检索以调用大量 ML API 的模型,在 API 调用准确性方面超过 GPT-4、幻觉现象更少,并通过可检索训练来适应测试时的 API 变更。
Large Language Models (LLMs) have seen an impressive wave of advances recently, with models now excelling in a variety of tasks, such as mathematical reasoning and program synthesis. However, their potential to effectively use tools via API calls remains unfulfilled. This is a challenging task even for today's state-of-the-art LLMs such as GPT-4, largely due to their inability to generate accurate input arguments and their tendency to hallucinate the wrong usage of an API call. We release Gorilla, a finetuned LLaMA-based model that surpasses the performance of GPT-4 on writing API calls. When combined with a document retriever, Gorilla demonstrates a strong capability to adapt to test-time document changes, enabling flexible user updates or version changes. It also substantially mitigates the issue of hallucination, commonly encountered when prompting LLMs directly. To evaluate the model's ability, we introduce APIBench, a comprehensive dataset consisting of HuggingFace, TorchHub, and TensorHub APIs. The successful integration of the retrieval system with Gorilla demonstrates the potential for LLMs to use tools more accurately, keep up with frequently updated documentation, and consequently increase the reliability and applicability of their outputs. Gorilla's code, model, data, and demo are available at https://gorilla.cs.berkeley.edu
研究动机与目标
- 通过微调与检索来实现让大语言模型使用一个大且不断变化的 API 空间的动力
- 创建并利用 APIBench 来基准 API 调用准确性与幻觉现象
- 开发一个可检索训练管线,使其能够适应 API 文档的更新
- 评估约束条件与多检索器在 API 调用质量与可靠性方面的影响
提出的方法
- 通过从 TorchHub、TensorHub 和 HuggingFace 模型中心收集 1,645 个 API 调用并为每个 API 生成 10 对指令–API 对
- 对 LLaMA-7B 基础模型进行指令微调,以专注于 API 调用的生成
- 在训练和推理中引入文档检索器,为提示提供最新的 API 文档(可检索训练)
- 使用基于 AST 的子树匹配来评估生成的 API 调用的功能正确性并识别幻觉
- 支持两种推理模式:零样本(无检索器)和检索(使用检索到的 API 文档)
- 分析带有约束意识的 API 调用(如准确性、参数数量)以研究在选择 API 时的权衡
![Figure 1: Examples of API calls . Example API calls generated by GPT-4 [ 29 ] , Claude [ 3 ] , and Gorilla for the given prompt. In this example, GPT-4 presents a model that doesn’t exist, and Claude picks an incorrect library. In contrast, our Gorilla model can identify the task correctly and sugge](https://ar5iv.labs.arxiv.org/html/2305.15334/assets/x1.png)
实验结果
研究问题
- RQ1在面对一个庞大、存在重叠且不断变化的 API 空间时,LLM 能在自然语言提示下多大程度上生成正确、可执行的 API 调用?
- RQ2在微调/推理中加入检索器是否能提升 API 调用的正确性并减少幻觉,尤其在测试时文档发生变化时?
- RQ3模型是否能够对 API 使用约束进行推理并选择符合给定要求的 API?
- RQ4Gorilla 在跨多个 API 中心的 API 调用任务上,与现有的最先进 LLM(如 GPT-4、Claude 等)相比表现如何?
主要发现
- Gorilla 在 API 功能正确性方面显著优于 GPT-4,并在 TorchHub 和 HuggingFace 上减少幻觉;在 TensorFlow Hub 方面与 GPT-4 相当。
- 轻度微调的 Gorilla 实现了最先进的零样本性能,约比 GPT-4 高 20.43%,比 ChatGPT 高 10.75%,涵盖评估数据集。
- 可检索训练提高了对测试时 API 文档变更的适应性并减少幻觉,相较于非检索基线,尽管检索器不最优有时会降低性能。
- 带有真实检索器的微调取得了显著增益(如在 TorchHub 约提升 ~12.37%,在 HuggingFace ~23.46%),相比不使用检索器的训练,尽管评估时的检索器可能仍然带来降级。
- 研究展示了 Gorilla 理解并应用 API 约束(如选择具备所需准确性和参数范围的模型)的能力,并能在不重新训练的情况下适应文档更新。

阅读本论文
在 Nubint 阅读器中打开原文,边读边就任意段落提问。
在 Nubint 中阅读本论文本解读由 AI 根据论文原文生成,引用前请核对原文。