Preprint
Machine Learning

Toolformer

Timo Schick, Jane Dwivedi-Yu, Roberto Dessì, R. Raileanu, M. Lomeli, Luke Zettlemoyer, Nicola Cancedda, Thomas Scialom
February 1, 2023Neural Information Processing Systems4,835 citations

4.8k

Citations

186

Influential Citations

Neural Information Processing Systems

Venue

2023

Year

Abstract

An LLM trained to decide which APIs to call, when to call them, what arguments to pass, and how to best incorporate the results into future token prediction.

Analysis

Why This Paper Matters

Large language models (LLMs) are powerful but fundamentally limited by the knowledge and reasoning abilities encoded in their static parameters. They cannot access real-time information, perform precise arithmetic, or interact with external systems. Toolformer addresses this by teaching LLMs to use tools—APIs for search, calculation, translation, and more—in a fully self-supervised manner. This is a paradigm shift: instead of scaling models to absurd sizes, we can equip smaller models with the ability to call external functions, dramatically expanding their capabilities without additional human supervision.

How It Works

Figure 1

The core idea is to augment a language model's training data with API calls. The model learns to decide which API to call, when to call it, what arguments to pass, and how to incorporate the result into the text. This is achieved through a self-supervised loop:

  1. API Call Generation: Given a text sequence, the model uses its in-context learning ability to generate candidate API calls. Each call is linearized into a special token format: <API>API_NAME(INPUT)</API> for the call, and <API>API_NAME(INPUT)→RESULT</API> for the call with its result.

  2. Execution and Filtering: The generated calls are executed against real APIs. The result is evaluated by measuring how much it reduces the loss on predicting the next tokens in the original text. Only calls that improve prediction are kept.

  3. Dataset Augmentation: The filtered API calls are merged back into the original text, creating an augmented dataset C*. The model is then fine-tuned on this dataset, learning to generate and use API calls naturally.

Key steps in toolformer approach, illustrated for a question answering tool

The approach requires only a handful of demonstrations per API to bootstrap the process. The tools used include a question answering system (Atlas), a Wikipedia search engine (BM25), a calculator, a calendar API, and a machine translation model (NLLB-600M).

Results

Figure 3

Toolformer, based on GPT-J (6.7B parameters), was evaluated on a range of benchmarks:

  • LAMA (factual knowledge): Toolformer significantly outperformed GPT-J and even larger models like OPT (66B) and GPT-3 (175B). It used the QA tool in 98.1% of cases.

  • Math datasets (ASDiv, SVAMP, MAWPS): Toolformer with calculator access outperformed all baselines, including larger models. It chose to use the calculator in 97.9% of examples.

  • Question Answering (WebQuestions, Natural Questions, TriviaQA): Toolformer achieved 99.3% accuracy on TriviaQA using Wikipedia search, outperforming GPT-3 despite being 25x smaller.

  • Multilingual QA (MLQA): Toolformer learned to use the translation tool, improving performance across languages. Usage varied from 63.8% to 94.9% per language, except Hindi (7.3%).

  • Temporal Datasets (TEMPLAMA, DATESET): Toolformer effectively used the calendar tool for date-dependent queries, outperforming all baselines.

Results on subsets of LAMA.

Results for various benchmarks requiring mathematical reasoning.

Results for various question answering dataset.

Results on MLQA for Spanish (Es), German (De), Hindi (Hi), Vietnamese (Vi), Chinese (Zh) and Arabic (Ar).

Results for the temporal datasets.

Significance

Toolformer demonstrates that LLMs can teach themselves to use tools without human annotations, using only a handful of API demonstrations. This is a major step toward more autonomous and capable AI systems. The ability to offload tasks like arithmetic and factual lookup to external tools means that smaller models can match or exceed the performance of much larger ones, reducing computational costs. The self-supervised nature of the training also means that new tools can be added with minimal effort.

However, the model is limited to single API calls—it cannot chain multiple tools or interact with APIs beyond a single request-response. Future work could explore multi-step tool use, dynamic API selection, and integration with more complex environments. Despite these limitations, Toolformer opens a promising direction for building LLMs that are not just larger, but smarter through tool use.