SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2302.04761 · 2023

Toolformer: Language Models Can Teach Themselves to Use Tools

Thomas Scialom, Roberta Raileanu, Luke Zettlemoyer, Roberto Dessì, Maria Lomeli, Nicola Cancedda, Timo Schick, Jane Dwivedi-Yu

arXiv · PDF · Open in the Atlas

Code that ran

7 of 10 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 1 honoured the contract we drafted, 2 violated it and 1 has no contract verdict; 3 failures of our instrument; 3 no recorded run), measured 2026-11-22; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2302.04761.json · badge: /api/ran/2302.04761.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
lucidrains/toolformer-pytorch community (classifier label)
classifier basis not recorded on the link
7 ran · 3 no recorded run
FunctionStatusWhere it lives
apply_rotary_pos_emb Ran
ran; our contract draft was wrong, not the code
lucidrains/toolformer-pytorch/toolformer_pytorch/palm.py
code served (permissive licence) · get_code("6d7a8eee9f74827c")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 2, dtype family float, shape (2, 4) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
from einops import rearrange

torch.manual_seed(0)

# Analyze the function:
# apply_rotary_pos_emb(pos, t) takes two parameters:
# - pos: used with .cos() and .sin() methods, so it's a tensor
# - t: used in multiplication with pos.cos() and rotate_half(t), so it's a tensor
#
# The rotate_half function:
# - rearranges input as '... (j d) -> ... j d' with j=2
# - This means the last dimension must be even (divisible by 2)
# - unbinds along dim=-2 to get two tensors
# - cats them back together
#
# For apply_rotary_pos_emb to work, pos and t must have compatible shapes
# pos needs to have a last dimension that's even for rotate_half
# Let's create small tensors with batch=2, and last_dim=4

# pos and t should have compatible broadcasting shapes
# pos represents positional embeddings (typically shape: [..., embedding_dim])
# t represents token embeddings (typically shape: [..., embedding_dim])
# where embedding_dim is even

batch_size = 2
embedding_dim = 4

# Create pos tensor with shape (batch_size, embedding_dim)
pos = torch.randn(batch_size, embedding_dim)

# Create t tensor with shape (batch_size, embedding_dim)
t = torch.randn(batch_size, embedding_dim)

ARGS = {
    'pos': pos,
    't': t,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
einops, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 2, dtype family float, shape (2, 4) — shape (2, 4) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
default Ran
ran, violated the contract we drafted
lucidrains/toolformer-pytorch/toolformer_pytorch/toolformer_pytorch.py
pointer only (licence: MIT); the stored copy get_code serves, from ThomasMrY/VCT, is pointer only (licence: NONE) · get_code("60fff7c3c400d7ff")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from ThomasMrY/VCT, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

exists Ran
ran, violated the contract we drafted
lucidrains/toolformer-pytorch/toolformer_pytorch/palm.py
pointer only (licence: MIT); the stored copy get_code serves, from ThomasMrY/VCT, is pointer only (licence: NONE) · get_code("aa5486a3650902d8")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from ThomasMrY/VCT, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

get_optimizer Ran
ran on a synthesized input
lucidrains/toolformer-pytorch/toolformer_pytorch/optimizer.py
code served (permissive licence) · get_code("c8cd79d20c3ffda7")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned AdamW. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn
from torch.optim import AdamW, Adam

torch.manual_seed(0)

# Create a small model with parameters of different dimensions
class TinyModel(nn.Module):
    def __init__(self):
        super().__init__()
        # 2D parameter - will be included in wd_params
        self.linear1 = nn.Linear(4, 3)
        # 1D parameter (bias) - will be included in no_wd_params
        self.bias = nn.Parameter(torch.randn(2))
        # Another 2D parameter
        self.linear2 = nn.Linear(3, 2)
    
    def forward(self, x):
        return self.linear2(self.linear1(x))

model = TinyModel()
params = list(model.parameters())

# Ensure we have a mix of 1D and 2D parameters for testing
# params will contain: linear1.weight (2D), linear1.bias (1D), bias (1D), linear2.weight (2D), linear2.bias (1D)

ARGS = {
    'params': params,
    'lr': 0.0001,
    'wd': 0.01,
    'betas': (0.9, 0.99),
    'eps': 1e-08,
    'filter_by_requires_grad': False,
    'group_wd_params': True,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type AdamW — a AdamW output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a AdamW output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
identity Ran
ran, honoured the contract we drafted
lucidrains/toolformer-pytorch/toolformer_pytorch/toolformer_pytorch.py
code served (permissive licence) · get_code("f3232418205f7cbd")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned Tensor, ndim 2, dtype family float, shape (2, 4) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

torch.manual_seed(0)

# The identity function takes a single parameter 't' and returns it unchanged
# We'll provide a simple tensor as the argument
t = torch.randn(2, 4)

ARGS = {
    "t": t
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 2, dtype family float, shape (2, 4) — shape (2, 4) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
rotate_half Ran
ran; our contract draft was wrong, not the code
lucidrains/toolformer-pytorch/toolformer_pytorch/palm.py
code served (permissive licence) · get_code("08213c6683993d3b")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 2, dtype family float, shape (2, 4) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
from einops import rearrange

torch.manual_seed(0)

# The function rotate_half takes a single parameter x (a tensor)
# It expects x to have a shape that can be rearranged with '... (j d) -> ... j d' where j=2
# This means the last dimension must be even (divisible by 2)
# For example, if the last dimension is 4, it gets reshaped to (2, 2)

# Create a small tensor with shape (2, 4) - batch size 2, last dimension 4
x = torch.randn(2, 4)

ARGS = {
    "x": x
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
einops, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 2, dtype family float, shape (2, 4) — shape (2, 4) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
separate_weight_decayable_params Ran
ran; our contract draft was wrong, not the code
lucidrains/toolformer-pytorch/toolformer_pytorch/optimizer.py
pointer only (licence: MIT); the stored copy get_code serves, from levyisthebest/echopulse_prelease, is pointer only (licence: NONE) · get_code("fdc11aefc97f3abb")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from levyisthebest/echopulse_prelease, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

MT Not yet run
unverified (harvested, no recorded run)
lucidrains/toolformer-pytorch/toolformer_pytorch/tools.py
code served (permissive licence) · get_code("c9aee99fdf750877")
How it ran

no invocation recorded.

WikiSearch Not yet run
unverified (harvested, no recorded run)
lucidrains/toolformer-pytorch/toolformer_pytorch/tools.py
code served (permissive licence) · get_code("fef4d2d88441929d")
How it ran

no invocation recorded.

colbertv2_get_request Not yet run
unverified (harvested, no recorded run)
lucidrains/toolformer-pytorch/toolformer_pytorch/tools.py
code served (permissive licence) · get_code("e47ba7a37641fba6")
How it ran

no invocation recorded.

Also present in other papers' code

Of 10 samples lifted from this paper's linked repositories, 10 carry a function identity and 0 do not. Of the 10 distinct functions with an identity, 7 are also present in other papers whose code we hold (6 with at least one paper dated earlier, 2 the same month, 6 later) and 3 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

FunctionAlso present inEarliest-datedOthers named
exists 486 other papers
144 dated earlier, 5 the same month, 331 later, 4 same year, order not determinable, 2 undated · 78 only as an assembly brick
1603.08155 (2016-03)
Perceptual Losses for Real-Time Style Transfer and Super-Resolution
1611.07004 (2016-11)
Image-to-Image Translation with Conditional Adversarial Networks
1804.04637 (2018-04)
EMBER: An Open Dataset for Training Static PE Malware Machine Learning Models
and 483 more not named here
default 163 other papers
72 dated earlier, 2 the same month, 87 later, 1 same year, order not determinable, 1 undated · 27 only as an assembly brick
1603.08155 (2016-03)
Perceptual Losses for Real-Time Style Transfer and Super-Resolution
1810.00825 (2018-10)
Set Transformer: A Framework for Attention-based Permutation-Invariant Neural Networks
1907.01470 (2019-07)
Augmenting Self-attention with Persistent Memory
and 160 more not named here
identity 21 other papers
2 dated earlier, 18 later, 1 undated · 2 only as an assembly brick
2011.10043 (2020-11)
Propagate Yourself: Exploring Pixel-Level Consistency for Unsupervised Visual Representation Learning
2203.08913 (2022-03)
Memorizing Transformers
2306.15687 (2023-06)
Voicebox: Text-Guided Multilingual Universal Speech Generation at Scale
and 18 more not named here
rotate_half 13 other papers
6 dated earlier, 7 later · 2 only as an assembly brick
2112.04426 (2021-12)
Improving language models by retrieving from trillions of tokens
2202.07765 (2022-02)
General-purpose, long-context autoregressive modeling with Perceiver AR
2203.07852 (2022-03)
Block-Recurrent Transformers
and 10 more not named here
separate_weight_decayable_params 8 other papers
2 dated earlier, 6 later
2202.01855 (2022-02)
Self-Supervised Learning with Random-Projection Quantizer for Speech Recognition
2301.11325 (2023-01)
MusicLM: Generating Music From Text
2303.05511 (2023-03)
Scaling up GANs for Text-to-Image Synthesis
and 5 more not named here
apply_rotary_pos_emb 2 other papers
2 dated earlier
2204.02311 (2022-04)
PaLM: Scaling Language Modeling with Pathways
2204.14198 (2022-04)
Flamingo: a Visual Language Model for Few-Shot Learning
colbertv2_get_request 1 other paper
1 later
2310.07289 (2023-10)
Beyond Factuality: A Comprehensive Evaluation of Large Language Models as Knowledge Generators

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-22.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

Language models (LMs) exhibit remarkable abilities to solve new tasks from just a few examples or textual instructions, especially at scale. They also, paradoxically, struggle with basic functionality, such as arithmetic or factual lookup, where much simpler and smaller models excel. In this paper, we show that LMs can teach themselves to use external tools via simple APIs and achieve the best of both worlds. We introduce Toolformer, a model 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. This is done in a self-supervised way, requiring nothing more than a handful of demonstrations for each API. We incorporate a range of tools, including a calculator, a Q&A system, a search engine, a translation system, and a calendar. Toolformer achieves substantially improved zero-shot performance across a variety of downstream tasks, often competitive with much larger models, without sacrificing its core language modeling abilities.

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2302.04761")
get_code_for_paper("2302.04761")
have("2302.04761")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2302.04761.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2302.04761.svg)](https://syntology.ai/paper/2302.04761)

Connect an agent — have() is free.