SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2106.12672 · ICLR · 2022

Charformer: Fast Character Transformers via Gradient-based Subword Tokenization

Sebastian Ruder, Yi Tay, Dara Bahri, Donald Metzler, Zhen Qin, Vinh Tran, Jai Gupta, Won Chung, Simon Baumgartner, Cong 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 (3 of them constructed an object rather than computing a result; 1 honoured the contract we drafted, 0 violated it and 3 have 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/2106.12672.json · badge: /api/ran/2106.12672.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/charformer-pytorch reimplementation (classifier label)
classifier basis: classifier_2025
7 ran · 3 no recorded run
FunctionStatusWhere it lives
DepthwiseConv1d Ran
ran on a synthesized input · constructed an object; no result was computed
lucidrains/charformer-pytorch/charformer_pytorch/charformer_pytorch.py
code served (permissive licence) · get_code("c943760822a257f4")
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 an instance of its own class, DepthwiseConv1d: the run constructed the object and did not call it, so no result was computed. 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
from torch import nn

torch.manual_seed(0)

# DepthwiseConv1d takes dim_in, dim_out, and kernel_size as parameters
# Looking at the forward pass:
# - self.conv is nn.Conv1d(dim_in, dim_out, kernel_size, groups=dim_in)
# - self.proj_out is nn.Conv1d(dim_out, dim_out, 1)
# The forward method takes x and applies conv then proj_out
# For this to work: dim_in must be divisible by groups (which equals dim_in for depthwise)
# So dim_in should equal dim_in (depthwise constraint is satisfied by design)
# dim_out should be >= dim_in for the groups parameter to work in Conv1d

# Valid parameters:
dim_in = 4
dim_out = 4
kernel_size = 3

ARGS = {
    "dim_in": dim_in,
    "dim_out": dim_out,
    "kernel_size": kernel_size,
}
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 DepthwiseConv1d — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a DepthwiseConv1d 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
GBST Ran
ran on a synthesized input · constructed an object; no result was computed
lucidrains/charformer-pytorch/charformer_pytorch/charformer_pytorch.py
code served (permissive licence) · get_code("6b018c0bea889c94")
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 an instance of its own class, GBST: the run constructed the object and did not call it, so no result was computed. 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

torch.manual_seed(0)

ARGS = {
    'num_tokens': 100,
    'dim': 4,
    'max_block_size': 8,
    'blocks': None,
    'downsample_factor': 2,
    'score_consensus_attn': True,
}
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 GBST — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a GBST 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
Pad Ran
ran on a synthesized input · constructed an object; no result was computed
lucidrains/charformer-pytorch/charformer_pytorch/charformer_pytorch.py
code served (permissive licence) · get_code("72d15a97b98b8f2d")
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 an instance of its own class, Pad: the run constructed the object and did not call it, so no result was computed. 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
import torch.nn.functional as F

torch.manual_seed(0)

# Create a small input tensor (batch_size=2, channels=4, height=3, width=3)
x = torch.randn(2, 4, 3, 3)

# Define padding as a tuple: (left, right, top, bottom) for 2D or (left, right) for 1D
# Using (1, 1, 2, 2) for 2D padding on height and width
padding = (1, 1, 2, 2)

# Define the value to pad with
value = 0.5

ARGS = {
    'padding': padding,
    'value': value
}
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 Pad — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a Pad 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
masked_mean Ran
ran; our contract draft was wrong, not the code
lucidrains/charformer-pytorch/charformer_pytorch/charformer_pytorch.py
code served (permissive licence) · get_code("830a1e254dcbecbe")
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
import math

torch.manual_seed(0)

# Create a small tensor with shape (2, 4, 3)
# This will be the tensor to compute masked mean over
tensor = torch.randn(2, 4, 3)

# Create a mask with shape (2, 4)
# Boolean mask indicating which elements are valid
mask = torch.tensor([
    [True, True, True, False],
    [True, False, True, True]
])

# dim parameter for reduction
dim = -1

ARGS = {
    "tensor": tensor,
    "mask": mask,
    "dim": dim
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
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
masked_mean Ran
ran; our contract draft was wrong, not the code
lucidrains/charformer-pytorch/charformer_pytorch/charformer_pytorch.py
code served (permissive licence) · get_code("a32cff24bac6b0fd")
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

torch.manual_seed(0)

# Create a tensor with shape (2, 4, 3) - batch=2, sequence=4, features=3
tensor = torch.randn(2, 4, 3)

# Create a mask with shape (2, 4) - batch=2, sequence=4
# The mask will be broadcast to match tensor dimensions
mask = torch.tensor([
    [True, True, False, True],
    [True, False, True, True]
])

ARGS = {
    "tensor": tensor,
    "mask": mask,
    "dim": -1
}
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 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
next_divisible_length Ran
ran, honoured the contract we drafted
lucidrains/charformer-pytorch/charformer_pytorch/charformer_pytorch.py
code served (permissive licence) · get_code("a78cb0f6103c1464")
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 int, ndim 0, dtype family int, shape () 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 math

def next_divisible_length(seqlen, multiple):
    return math.ceil(seqlen / multiple) * multiple

ARGS = {
    "seqlen": 100,
    "multiple": 8
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type int, ndim 0, dtype family int, shape () — shape () 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
pad_to_multiple Ran
ran; our contract draft was wrong, not the code
lucidrains/charformer-pytorch/charformer_pytorch/charformer_pytorch.py
code served (permissive licence) · get_code("5a84e35f3a42e1eb")
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 3, dtype family float, shape (2, 5, 7) 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
import math
import torch.nn.functional as F

torch.manual_seed(0)

# Create a small tensor with distinct dimensions for probing
# Shape: (batch=2, seq_len=5, features=4)
tensor = torch.randn(2, 5, 4)

# Parameters for pad_to_multiple function
ARGS = {
    "tensor": tensor,
    "multiple": 8,
    "seq_dim": 1,
    "dim": -1,
    "value": 0.0
}
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 Tensor, ndim 3, dtype family float, shape (2, 5, 7) — shape (2, 5, 7) 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
exists Not yet run
unverified (harvested, no recorded run)
lucidrains/charformer-pytorch/charformer_pytorch/charformer_pytorch.py
code served (permissive licence) · get_code("9632f809d8608df4")
How it ran

no invocation recorded. this sample carries JSON test cases instead of a setup block; get_reference_implementation serves them with the level they back.

lcm Not yet run
unverified (harvested, no recorded run)
lucidrains/charformer-pytorch/charformer_pytorch/charformer_pytorch.py
code served (permissive licence) · get_code("9f9701376e781647")
How it ran

no invocation recorded.

next_divisible_length Not yet run
unverified (harvested, no recorded run)
lucidrains/charformer-pytorch/charformer_pytorch/charformer_pytorch.py
code served (permissive licence) · get_code("f52d38502f83c1fb")
How it ran

no invocation recorded. this sample carries JSON test cases instead of a setup block; get_reference_implementation serves them with the level they back.

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 8 distinct functions with an identity, 1 are also present in other papers whose code we hold (1 with at least one paper dated earlier, 1 the same month, 1 later) and 7 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
brick of this paper's assembly: helper
486 other papers
47 dated earlier, 5 the same month, 432 later, 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

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

State-of-the-art models in natural language processing rely on separate rigid subword tokenization algorithms, which limit their generalization ability and adaptation to new settings. In this paper, we propose a new model inductive bias that learns a subword tokenization end-to-end as part of the model. To this end, we introduce a soft gradient-based subword tokenization module (GBST) that automatically learns latent subword representations from characters in a data-driven fashion. Concretely, GBST enumerates candidate subword blocks and learns to score them in a position-wise fashion using a block scoring network. We additionally introduce CHARFORMER, a deep Transformer model that integrates GBST and operates on the byte level. Via extensive experiments on English GLUE, multilingual, and noisy text datasets, we show that CHARFORMER outperforms a series of competitive byte-level baselines while generally performing on par and sometimes outperforming subword-based models. Additionally, CHARFORMER is fast, improving the speed of both vanilla byte-level and subword-level Transformers by 28-100% while maintaining competitive quality. We believe this work paves the way for highly performant token-free models that are trained completely end-to-end.

For agents

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

get_harvested_code_for_paper("2106.12672")
get_code_for_paper("2106.12672")
have("2106.12672")

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

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

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

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

Connect an agent — have() is free.