Profile

Settings

Loading…

← Papers

Help

FAQ

Which features require signing in?

You can read the commentary, paper info, Model Structure and related papers of public papers without signing in. Sign in to manage your account or contact us about your inquiries.

Can I upload a PDF file?

Upload papers with an arXiv or DOI link; the commentary is public to everyone. Papers whose source and terms of use can't be verified, so the commentary can't be made public, can't be uploaded. Uploading PDF files and keeping papers private are for subscribers only, and a paper uploaded as a file is saved as private only. Searching for official info by title runs only when you press the button.

Are the figures and AI commentary accurate?

Figures come only from the original paper, and only those whose terms of use are verified are shown. The commentary is written by AI and may be wrong. Check important claims, numbers and figure context against the evidence in the original paper.

I want to report a copyright issue.

Terms of use and the source of the original paper are on the Paper info tab. If there's a problem, choose "Paper content, figures and copyright" under Contact us and send the paper link, the part in question, and evidence that you hold the rights. Receiving your report doesn't confirm any rights or remove anything right away. You can see the result of the review under My inquiries.

I forgot my password.

If you signed up with email, use Forgot password in the sign-in window to reset it with your verified email. If you signed up with Google, Naver or Kakao, change your password with that service.

What should I include in an inquiry?

Tell us which screen you were on and what you were doing when the problem happened, along with the paper link. Don't include personal information such as passwords, API keys, verification codes or phone numbers. Inquiries and replies are stored in Refivu and you can see them under My inquiries.

How do I delete my account?

In Settings, under My account, press Delete account. Review what will be deleted and complete identity verification to delete your account. For other requests, choose "Account" under Contact us.

Paper commentary

Toolformer: Language Models Can Teach Themselves to Use Tools

  • Problem Language models lack up-to-date facts, reliable arithmetic and a sense of time, and scale alone only partly closes these gaps.
  • Method Samples API calls with the language model itself, keeps only the calls whose results lower a weighted loss on later tokens, and finetunes GPT-J on the kept calls.
  • Results Scored 40.4 on ASDiv with the calculator enabled, against 14.8 with calls disabled.

Why plain language models need tools

Large language models solve many tasks from a few examples or an instruction, yet their gaps in current knowledge, precise arithmetic and sense of time are not closed by scale alone. Recent events, low-resource languages, calculation and the current date are each handled poorly, and the models also tend to hallucinate facts.

Existing ways of doing this either depend on large amounts of human annotation or restrict tool use to a single task.

The authors set two goals: tool use should be learned without costly annotation, and the model should keep its generality while choosing for itself when and how to use each tool. They also note that what annotators consider a useful call need not match what the model finds useful.

Sampling candidate calls with the model

The approach borrows from in-context learning: a large language model, shown a handful of human-written examples for one API, annotates a large plain-text corpus with candidate calls. The only supervision is the handful of examples in each prompt, so no labelled calls are needed.

Sampling starts by scoring each position i in the text with the probability that the model starts an API call there, \(p_i = p_M(\text{<API>} \mid P(x), x_{1:i-1})\). Positions whose probability exceeds the sampling threshold \(\tau_s\) are kept, and when more than k positions pass, only the top k are kept. At each kept position up to m calls are sampled, and examples where the model never produces the end token are discarded.

Execution depends on the tool: it may call another neural network, run a Python script or query a retrieval system, but each result must be a single text sequence.

Keeping only calls that lower the loss

Filtering asks whether a call helps the model predict the text that follows it. For a call \(c_i\) with result \(r_i\) at position i, the weighted loss over the tokens from i to n is computed under two conditions. \(L_i^{+} = L_i(e(c_i, r_i))\) conditions on the call and its result, while \(L_i^{-} = \min(L_i(\varepsilon), L_i(e(c_i, \varepsilon)))\) takes the smaller of the loss with no call and the loss with the call but without its result.

The weight of a token at offset t from position i is proportional to \(\max(0, 1 - 0.2 t)\), normalized by the sum of the same quantity over all offsets. Because the losses come from the model's own probabilities, the filter measures how much a call helps by the model's own feedback.

A call is kept when \(L_i^{-} - L_i^{+} \ge \tau_f\), so the call with its result must lower the loss by at least the filtering threshold compared with the better of no call and a call without result. The default threshold is 1.0, and the calculator and machine translation tools use 0.5 because their candidate sets are small.

The call is placed before the text during filtering, since inserting it mid-text before finetuning would interrupt the flow and raise perplexity. The final dataset places each retained call at its own position, so the augmented set contains the original texts with calls only where they help.

Finetuning and decoding with calls

The model is finetuned on the augmented dataset C* with the standard language modeling objective, so the call syntax is learned with the same loss as ordinary text. Since C* keeps the original texts, finetuning exposes the model to the same content as finetuning on C, while the inserted calls show where and with which inputs a tool helps.

At inference, decoding proceeds normally until the model emits the arrow token, which signals that it expects a result. Decoding then pauses, the API is run, and the response and the end token are inserted before decoding resumes.

The five tools

Five tools are explored, each meeting two constraints: inputs and outputs can be written as text, and a few demonstrations of use can be given. The examples in Figure 1 show calls of the question answering tool, the calculator, the translation tool and the Wikipedia search tool inside ordinary text.

The question answering tool is Atlas, a retrieval-augmented language model finetuned on Natural Questions. The calculator supports the four basic arithmetic operations and rounds results to two decimal places.

Wikipedia Search uses a BM25 retriever over the Wikipedia dump from KILT and returns short snippets, so the model must extract the relevant part itself.

Machine translation uses the 600M parameter NLLB model, which covers 200 languages, detects the source language with fastText and always translates into English. The calendar returns the current date without taking any input, which gives temporal context.

Data, training and decoding setup

The language modeling dataset C is a subset of CCNet, and the base model is GPT-J with 6.7B parameters. Heuristics restrict annotation to texts likely to benefit from a tool; for the calculator, a text must contain at least three numbers.

The compared models are GPT-J without finetuning, GPT-J + CC finetuned on C without calls, Toolformer finetuned on C*, and Toolformer with calls disabled at decoding. For most tasks OPT (66B) and GPT-3 (175B) are added, which are about 10 and 25 times larger than the other baselines.

Evaluation is zero-shot: each model receives a task instruction but no in-context examples, unlike earlier tool-use work that gave dataset-specific demonstrations. Toolformer starts a call whenever the API start token is among its k most likely tokens, with k = 10 used in the experiments, and greedy decoding corresponds to k = 1. Each input allows at most one API call.

Factual completion on LAMA

LAMA statements come from Wikipedia, so Wikipedia Search is disabled for Toolformer to avoid an unfair advantage. A prediction counts as correct when the right word appears within the first five predicted words.

On SQuAD, Google-RE and T-REx, Toolformer scores 33.8, 11.5 and 53.5. The strongest GPT-J row is Toolformer with calls disabled, at 22.1, 6.3 and 34.9, so the gains are 11.7, 5.2 and 18.6 points; GPT-J + CC scores 19.2, 5.6 and 33.2.

OPT (66B) reaches 21.6, 2.9 and 30.1 and GPT-3 (175B) reaches 26.8, 7.0 and 39.8, so Toolformer leads both despite their size. With calls disabled, Toolformer still scores above plain GPT-J on all three subsets, at 22.1 against 17.8 on SQuAD, 6.3 against 4.9 on Google-RE and 34.9 against 31.9 on T-REx.

Toolformer called the question answering tool in 98.1% of examples, another tool in 0.7% and no tool in 1.2%.

Arithmetic benchmarks and the calculator

ASDiv, SVAMP and MAWPS have numeric answers, so the first number the model predicts is scored, and when an equation appears, the number after its equals sign is used.

Toolformer scores 40.4 on ASDiv, 29.4 on SVAMP and 44.0 on MAWPS, whereas GPT-J scores 7.5, 5.2 and 9.9. Allowing calls more than doubles the score on every benchmark, from 14.8 to 40.4 on ASDiv and from 15.0 to 44.0 on MAWPS.

With calls disabled, Toolformer scores 14.8, 6.3 and 15.0, above GPT-J + CC at 9.6, 5.0 and 9.3. The authors attribute this to finetuning on many examples of calls and their results, which may improve the model's own arithmetic.

The calculator was used for 97.9% of examples across the benchmarks. Enabled Toolformer also scores above OPT (66B), at 6.0, 4.9 and 7.9, and GPT-3 (175B), at 14.0, 10.0 and 19.8.

Question answering with Wikipedia Search

Web Questions, Natural Questions and TriviaQA are scored by whether the first 20 predicted words contain the correct answer, not by exact match. The question answering tool is disabled for Toolformer, since using it would make these tasks trivial given that it was finetuned on Natural Questions.

Toolformer scores 26.3 on WebQS, 17.7 on NQ and 48.8 on TriviaQA, against 18.5, 12.8 and 43.9 for GPT-J. With calls disabled it reaches 18.9, 12.6 and 46.7, and Toolformer used Wikipedia Search in 99.3% of examples.

GPT-3 (175B) scores 29.0, 22.6 and 65.9, so Toolformer stays below it on all three datasets. The authors point to the simplicity of the search engine, which often returns poor matches, and to Toolformer's inability to rephrase queries or read several results.

Multilingual questions and translation

MLQA gives an English context with questions in Spanish, German, Hindi, Vietnamese, Simplified Chinese or Arabic. The metric is the share of generations, capped at 10 words, that contain the correct answer.

Calls raise Toolformer's score in every language: 20.6 against 19.8 in Spanish, 13.5 against 11.9 in German, 1.4 against 1.2 in Hindi, 10.6 against 10.1 in Vietnamese, 16.8 against 15.0 in Chinese and 3.7 against 3.1 in Arabic. The translation tool is used for 63.8% to 94.9% of examples depending on the language, and for 7.3% in Hindi.

Toolformer does not consistently beat vanilla GPT-J: GPT-J reaches 16.5 in German and 18.2 in Chinese, above Toolformer's 13.5 and 16.8. The authors link this to finetuning on CCNet deteriorating performance for some languages, possibly through a distribution shift from GPT-J's pretraining data.

OPT and GPT-3 score low largely because they often fail to answer in English. In the variant where context and question are both English, GPT-3 is the strongest of the compared models, which the authors take as evidence that its weak MLQA scores reflect the multilingual setting.

Temporal questions and the calendar tool

TEMPLAMA contains cloze queries built from Wikidata with answers for the years 2010 to 2020, while DATESET is generated from templates over random dates and durations and requires knowing the current date.

Toolformer scores 16.3 on TEMPLAMA, against 13.7 for GPT-J and 12.7 with calls disabled. The calendar is used for only 0.2% of TEMPLAMA examples, so the gain comes mostly from the Wikipedia search and question answering calls.

On DATESET Toolformer scores 27.3, against 5.9 with calls disabled and 3.9 for GPT-J, and it uses the calendar in 54.8% of examples.

The best strategy on TEMPLAMA would query the calendar first and then the question answering system with that date, but the one-call limit and independently sampled training calls make it hard to learn.

Language modeling and model size

Perplexity on WikiText is 9.9 for GPT-J, 10.3 for GPT-J + CC and 10.3 for Toolformer with calls disabled, and on the CCNet validation subset it is 10.6, 10.5 and 10.5. Lower perplexity is better, so GPT-J keeps the best WikiText score.

Training on C* does not raise perplexity over training on C when calls are disabled. Perplexity with calls enabled was not computed, because it would require summing over all calls the model could make at each position.

For the scaling study the approach is applied to GPT-2 models of 124M, 355M, 775M and 1.6B parameters, using only the question answering tool, the calculator and Wikipedia Search. A large gap between predictions with and without calls remains even for the largest model.

Figure 4 plots the LAMA, QA and math averages against model size with and without calls.

How the decoding threshold changes call rate

Raising k from 1 to 10 increases how often calls are made, from 40.3% to 98.1% on T-REx and from 8.5% to 100% on WebQS.

At k = 1 the model appears partly calibrated: on T-REx, examples where it skips the call score 44.3, above the 34.9 it gets with no calls at all, and on WebQS they score 19.9 against 18.9. This calibration disappears at higher values of k.

Table 9 reports overall scores, the subsets where a call is made and skipped, and the call rate for each k. At k = 10 the overall T-REx score is 53.5 and the WebQS score is 26.3.

In Table 10 the highest filter score, 5.49, goes to a Wikipedia Search call that gives relevant war memorial information, and the lowest, -1.23, goes to a question answering call that adds nothing useful. The authors argue that some unfiltered noise is useful, since it keeps the model from trusting every result blindly.

Relation to earlier tool-use work

Earlier approaches rely on large human supervision or prompt the model for one known task. TALM uses a similar self-supervised objective for a calculator and a search engine, but only in settings where the model is finetuned for downstream tasks. Other approaches always supply extra information, whether or not it helps, whereas Toolformer learns to request the information it needs.

Self-training and bootstrapping have a long history in tasks such as relation extraction, parsing and retrieval. Toolformer is similarly trained on its own predictions, after a perplexity-based filtering step.

Limitations

Toolformer cannot chain tools, because API calls for each tool are generated independently and the finetuning data contains no chained tool use.

Calls are one-shot, so the model cannot browse many search results or refine a query.

The method is sample-inefficient: processing more than a million documents yields only a few thousand useful calculator calls, and the authors suggest iterating the approach as a remedy. The cost of each tool call is not part of the decision to make a call.

The main results use one 6.7B GPT-J base model, and OPT (66B) and GPT-3 (175B) are compared as baselines that were not trained with this method. The TEMPLAMA and MLQA results do not show consistent gains.

Paper info

Authors
Timo Schick, Jane Dwivedi-Yu, Roberto Dessì, Roberta Raileanu, Maria Lomeli, Luke Zettlemoyer, Nicola Cancedda, Thomas Scialom
Venue
arXiv · Preprint
First published
2023-2-9
Added
2026-10-20
Updated
2023-2-9
Version
v1
arXiv
2302.04761
Category
cs.CL
Original paper terms
arXiv non-exclusive 1.0
What we show
Paper info and commentary

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

Quote from the paper

Timo Schick, Jane Dwivedi-Yu, Roberto Dessì, Roberta Raileanu, Maria Lomeli, Luke Zettlemoyer, Nicola Cancedda, Thomas Scialom (2023). Toolformer: Language Models Can Teach Themselves to Use Tools. arXiv:2302.04761v1. https://arxiv.org/abs/2302.04761v1

BibTeX
@misc{schick2023toolformer,
  title = {{Toolformer: Language Models Can Teach Themselves to Use Tools}},
  author = {Timo Schick and Jane Dwivedi-Yu and Roberto Dessì and Roberta Raileanu and Maria Lomeli and Luke Zettlemoyer and Nicola Cancedda and Thomas Scialom},
  year = {2023},
  eprint = {2302.04761},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2302.04761v1}
}

See related papersBrowse other papers

Paper preview
Account security

Connect Google account

If you connect a Google account, you can sign in with it too.

Refivu

Delete account

Refivu
Refivu

Sign up