Abstract
While Large Language Models (LLMs) excel at general language tasks, they often require external tools for specialized domains like mathematics or real-time knowledge retrieval. Current methods like ToolkenGPT represent tools as discrete tokens but initialize them randomly, creating a "semantic gap" between the tool's function and the model's internal vocabulary. We introduce TokenLearning, a framework that bridges this gap by semantically anchoring tool tokens to the model's existing embedding space. By initializing tool embeddings with natural language descriptions and applying $L_2$ regularization during training, TokenLearning achieves superior tool-call accuracy and faster convergence across diverse benchmarks.
Introduction
LLMs frequently encounter limitations in tasks requiring precise numerical reasoning, up-to-date information, or complex physical planning. To mitigate this, researchers have developed "tool-augmented" LLMs. A prominent approach, ToolkenGPT, treats each tool as a special token (a "toolken"). When the model predicts this token, it triggers the corresponding tool call.
However, ToolkenGPT's reliance on random initialization for these tokens forces the model to learn tool semantics from scratch. This lack of alignment makes it difficult for the model to understand that a tool for [add] is related to the concept of addition already present in its word embedding space. This inefficiency is particularly pronounced when training data is scarce or the number of available tools is large.
Methodology: Re-Initialization Token Learning
The TokenLearning framework proposes a three-step process to align tool tokens with the LLM's pre-existing semantic knowledge:
- Prior Token Embeddings ($W_\tau^0$): Instead of random values, the system extracts embeddings for the words comprising a tool's name or description (e.g., using the embedding for "calculator" to initialize a calculator tool token).
- Pooling Operations: For multi-word tool descriptions, the framework employs Average Pooling or Max Pooling to aggregate multiple word vectors into a single semantic "prior" vector. Average pooling was found to be more stable and effective for generalization.
- Regularized Learning: During the fine-tuning phase, the model optimizes tool embeddings ($W_\tau$). To prevent "semantic drift"—where the embedding loses its original meaning—an $L_2$ regularization term is added to the loss function. This term penalizes the model if the learned embedding deviates too far from its semantic prior.
Experimental Evaluation
The researchers evaluated TokenLearning using the LLaMA-2 family (7B, 13B, and 70B) across four distinct benchmarks:
- GSM8K-XL: A math dataset with large numbers requiring a calculator.
- FuncQA: Multi-step numerical reasoning.
- KAMEL: A knowledge-heavy task involving up to 234 relational tools for querying Wikidata.
- VirtualHome: An embodied planning task with 58 different action/object tools for household chores.
Key Results
TokenLearning consistently outperformed baseline methods across all model sizes and tasks. On the GSM8K-XL benchmark, TokenLearning improved accuracy by approximately 3% over ToolkenGPT. Notably, for the LLaMA2-70B model, it achieved an accuracy of 54.22%, significantly higher than ToolkenGPT's 47.89%.
In the KAMEL dataset, TokenLearning demonstrated superior scalability; as the number of tools increased to 234, it maintained high accuracy while In-Context Learning (ICL) and ToolkenGPT performance degraded. In the VirtualHome planning task, TokenLearning reached a success rate of 0.78 with LLaMA2-70B, outperforming both ICL (0.34) and ToolkenGPT (0.76).
Discussion and Conclusion
The primary insight of this work is that "semantic anchoring" is vital for efficient tool use. By starting tool tokens at a known semantic location in the embedding space, the model does not need to re-learn the concept; it only needs to learn the specific trigger conditions for the tool.
While highly effective, the method's performance is sensitive to the quality of tool naming. Cryptic or non-descriptive names may provide poor priors. Future work may explore automated descriptive naming or dynamic tool tokens that adapt based on conversational context. Overall, TokenLearning provides a robust and scalable path for enhancing the utility of LLMs through precise tool integration.
Summary updated