ToolkenGPT: Augmenting Frozen Language Models with Massive Tools via Tool Embeddings
Shibo Hao1, Tianyang Liu1, Zhen Wang1, 2, Zhiting Hu1 1UC San Diego, 2Mohamed bin Zayed University of Artificial Intelligence {s5hao, til040, zhw085,
Abstract
Augmenting large language models (LLMs) with external tools has emerged as a promising approach to solving complex problems. However, traditional methods, which fine-tune LLMs with tool demonstration data, can be both costly and restricted to a predefined set of tools. Recent in-context learning paradigm alleviates these issues, but the limited context length only allows for a few shots of demonstrations, leading to suboptimal understandings of the tools. Moreover, when there are numerous tools to choose from, in-context learning could completely fail to work. In this paper, we propose an alternative approach, ToolkenGPT, which combines the benefits of both sides. Our approach represents each tool as a token (“toolken”) and learns an embedding for it, enabling tool calls in the same way as generating a regular word token. Once a toolken is triggered, the LLM is prompted to complete arguments for the tool to execute. ToolkenGPT offers the flexibility to plug in an arbitrary number of tools by expanding the set of toolkens on the fly. In addition, it improves tool use by allowing extensive demonstration data for learning the toolken embeddings. In diverse domains, including numerical
中文速览
让大型语言模型(LLM)学会调用外部工具是提升其能力的关键路径,但现有方法要么需要昂贵的全量微调、难以扩展到新工具,要么依赖上下文学习却受限于提示窗口长度、面对大量工具时效果急剧下降。ToolkenGPT 提出了一种新思路:把每个工具表示为一个特殊的"工具词元"(toolken),为其学习一个轻量级嵌入向量并追加到模型的词表头部,这样模型在生成时就能像预测普通词汇一样自然地触发工具调用,触发后再切换到专用提示模式来生成工具参数并执行。实验覆盖数值推理、知识库问答和具身智能体规划三类任务,ToolkenGPT 在支持超过 200 个关系 API 和 58 种具身动作的场景下,均显著优于思维链、ReAct 等主流基线。这项工作的价值在于:它无需修改 LLM 本身的参数,仅靠训练极少量嵌入就能让模型掌握大规模、可动态扩展的工具集,为构建实用的工具增强型语言模型提供了一条高效且灵活的新路线。
原文 arXiv:2305.11554;中英对照 + 大白话阅读 https://aha.fim.ai/paper/2305.11554v4