ToolkenGPT: Augmenting Frozen Language Models with Massive Tools via Tool Embeddings

Shibo Hao,Tianyang Liu,Zhen Wang,Zhiting Hu
2024-01-16
Abstract:Augmenting large language models (LLMs) with external tools has emerged as a promising approach to solving complex problems. However, traditional methods, which finetune 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, $\textbf{ToolkenGPT}$, which combines the benefits of both sides. Our approach represents each $\underline{tool}$ as a to$\underline{ken}$ ($\textit{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 reasoning, knowledge-based question answering, and embodied plan generation, our approach effectively augments LLMs with tools and substantially outperforms various latest baselines. ToolkenGPT demonstrates the promising ability to use relevant tools from a large tool set in complex scenarios.
Computation and Language,Machine Learning
What problem does this paper attempt to address?
### Problems the Paper Aims to Solve This paper aims to address some key issues encountered by large language models (LLMs) when integrating with external tools. Specifically: 1. **Limitations of Existing Methods**: - **Fine-tuning Methods**: Traditional fine-tuning methods, while enhancing the capabilities of LLMs, are costly and limited to predefined sets of tools. - **Context-based Learning Methods**: Although these can alleviate some issues, they are constrained by context length, allowing only a few examples, which leads to insufficient understanding of the tools. When faced with a large number of tools, this context-based learning approach may completely fail. 2. **Proposed New Method**: - **ToolkenGPT**: This method represents each tool as a "tool token" (toolken) and learns an embedding representation for it, enabling LLMs to call these tools while generating normal vocabulary tokens. Once a tool token is triggered, LLMs are prompted to complete the corresponding input parameters to execute the tool. This approach not only flexibly supports any number of tools but also allows the use of a large amount of demonstration data to optimize tool embedding representations. 3. **Application Areas**: - **Numerical Reasoning**: ToolkenGPT excels in handling complex mathematical problems, significantly outperforming baseline methods. - **Knowledge Base Question Answering**: By invoking numerous relational APIs, ToolkenGPT can perform fact prediction. - **Embodied Plan Generation**: In tasks involving environmental interaction, ToolkenGPT demonstrates better grounding capabilities. In summary, the goal of this paper is to propose a new solution through ToolkenGPT, enabling LLMs to efficiently master and use a large number of tools without extensive fine-tuning, thereby overcoming the limitations of existing methods.