How Google Fixed Arithmetic: Inside Gemini's 256K Unigram Tokenizer

๐Ÿ“… 16 Jul 2026 โฑ 12 min read Gemma 3 Technical Report โ†—

Google made two decisions in their Gemini tokenizer that most people haven't noticed: they chose 256K vocabulary (the largest in production) and they changed how numbers tokenize so that arithmetic actually works. Neither decision was incremental. Both required accepting a significant parameter cost upfront in exchange for capabilities the model would otherwise never learn. This is a deep dive into those decisions and the engineering behind them.

When I built a multilingual BPE tokenizer from scratch for ERA v5 coursework โ€” a 10,000-token vocabulary covering English, Hindi, Telugu, and Bengali โ€” the hardest design choices were about what to optimize. Fertility across scripts? Compression ratio? Vocabulary coverage? Every choice trades off against another.

Google faced the same tradeoffs at a completely different scale, with a model family covering 100+ languages and applications ranging from code generation to multilingual chat to mathematical reasoning. The Gemini tokenizer is an existence proof that you can push vocabulary size to 256K without breaking the model โ€” if you're willing to pay the parameter cost and think carefully about what the vocabulary represents.

01 Why 256K? The Multilingual Compression Argument
The bet: at 256K tokens, you can give enough vocabulary budget to every major script that no language needs to fragment into character-level sequences for common words. The token tax drops from 3โ€“4ร— to close to 1ร— for most languages.

The root cause of the token tax โ€” Arabic paying 3.3ร— more than English, Bengali ~4.5ร— more โ€” is vocabulary budget exhaustion. When GPT-4's cl100k_base tokenizer was trained, English and code dominated the corpus. The BPE merge process allocated most of its 100K vocabulary slots to English words, subwords, and code patterns. Arabic characters, Bengali akshara, Telugu conjuncts โ€” these got whatever budget was left after English filled up. Not enough for common words to become single tokens. They fragment into characters.

The solution is more vocabulary. With 256K tokens, you can dedicate tens of thousands of slots to non-Latin scripts and still have room for a comprehensive English and code vocabulary. This is what the Gemma/Gemini tokenizer does: the 256K vocabulary covers 100+ languages with enough slots that common words in all of them can be single tokens.

The Gemma 3 Technical Report (March 2025) is explicit: the 256K vocabulary was specifically designed to reduce over-tokenization of non-English text. Fertility measurements across their evaluation languages showed substantially more uniform token rates than smaller-vocabulary baselines.

English
~1.0ร—
baseline (cl100k)
Chinese
~1.1ร—
256K gives full coverage
Hindi
~1.3ร—
improved vs ~1.7ร— at 100K
Arabic
~1.5ร—
improved vs 3.3ร— at 100K

The tradeoff is embedding table size. Vocabulary is not free.

Embedding table parameters at 4096 hidden dimensions (vocab ร— dim)
LLaMA 2 (32K)
131M
LLaMA 3 (128K)
524M
+393M vs LLaMA 2
GPT-4o (200K)
819M
15% of a 7B model
Gemini (256K)
1.05B
1B params before layer 1

At 256K vocabulary and 4096 hidden dimensions, the embedding table alone requires 1.05 billion parameters โ€” before the first transformer layer runs. That's roughly 15% of a 7B model's total parameter budget, or 1.5% of a 70B model's budget. Google's bet is that the multilingual compression benefit โ€” more content per context window, better language parity, reduced API cost for non-English users โ€” is worth that upfront cost.

02 Why Unigram LM Instead of BPE
The algorithm choice: Gemini uses Unigram Language Model tokenization via SentencePiece โ€” not BPE. Unigram has a proper probabilistic objective, supports multiple tokenizations per sequence, and prunes a vocabulary rather than building one. The distinction matters at 256K.

BPE and Unigram LM produce superficially similar outputs โ€” both give you a subword vocabulary with frequencies that correlate with corpus statistics. But they work oppositely: BPE starts small and grows through merges, while Unigram starts enormous and shrinks through pruning.

1
Initialize: Start with an over-complete vocabulary โ€” all substrings up to some length, or a BPE-seeded vocabulary. Typically 2โ€“5ร— the target size.
2
E-step: For each token in the vocabulary, compute the probability of the corpus under the current Unigram LM. This gives each token a log-likelihood contribution.
3
M-step (prune): Remove the ~20% of tokens whose removal reduces corpus log-likelihood the least. These are the least informative tokens given the others.
4
Repeat until vocabulary reaches target size. The result: a vocabulary where every token earns its slot by reducing description length of the training corpus.

The key property this gives Gemini's tokenizer: principled pruning for multilingual vocabularies. With BPE at 256K, the merge process's greedy frequency criterion can over-allocate to high-frequency English patterns at the expense of rare-but-important morphological units in other languages. Unigram LM's log-likelihood objective naturally keeps vocabulary items that are essential for encoding the training corpus, regardless of absolute frequency โ€” a rare morpheme in Telugu that appears in many root forms gets to stay because removing it would hurt Telugu corpus likelihood even if it barely affects English likelihood.

The other advantage: Unigram supports probabilistic tokenization. Instead of one deterministic segmentation per sequence, you can sample from the distribution of valid segmentations. This was used as a data augmentation technique in T5 and PaLM โ€” training on multiple tokenizations of the same text makes the model less sensitive to tokenization boundaries. Google's models have used this across their entire family.

BPE (used by: OpenAI, Meta, Qwen)
DirectionBuild up (merge)
CriterionMax frequency
ObjectiveGreedy heuristic
TokenizationDeterministic
MultilingualFrequency-biased
Unigram LM (used by: Google, LLaMA 1/2, T5)
DirectionPrune down
CriterionMin likelihood loss
ObjectiveCorpus log-likelihood
TokenizationProbabilistic (sampling)
MultilingualPrincipled coverage
03 The Arithmetic Fix: Split-Digit Tokenization
The design decision: in Gemini's tokenizer, every decimal digit (0โ€“9) is guaranteed a single dedicated token. Multi-digit numbers always tokenize as one-token-per-digit. This is not the default in BPE โ€” it's an explicit design choice that required overriding merge rules.

GPT-4 fails at multi-digit arithmetic. Not because the model is bad at math โ€” it's because the tokenizer destroys the structure of numbers before the model ever sees them.

In standard BPE, frequently co-occurring digit sequences get merged. "12" might be a single token. "345" might be another. So "12345" tokenizes as ["12", "345"] โ€” and the tens place of the "12" block is spatially adjacent to the hundreds place of the "345" block in token space, but they represent different place values. The model has no consistent positional structure to learn from. Each number has an essentially arbitrary tokenization that depends on which merges happened during vocabulary training.

How different models tokenize the same number
GPT-4 (cl100k)
127 84 9
โ€” place values scrambled, no consistent structure
LLaMA 3 (128K)
12 784 9
โ€” different boundaries, same underlying problem
Gemini (256K)
1 2 7 8 4 9
โ€” one token per digit, place value is consistent

With split-digit tokenization, a model can learn that "the token at position N+2 from the start of a number represents the hundreds place" โ€” because that relationship is now stable across all numbers. Addition, subtraction, carry propagation โ€” these become learnable patterns rather than arithmetic performed on an inconsistent symbol soup.

The cost is sequence length. "127849" is 6 tokens with split-digit tokenization vs 2โ€“3 tokens with BPE merges. Documents with lots of numbers โ€” financial data, scientific texts, code โ€” get longer token sequences in Gemini than they would in GPT-4. Google judged this a worthwhile tradeoff, and the evidence from Gemini's performance on mathematical benchmarks supports that judgment.

MATH benchmark (GSM8K) Strong improvement vs BPE-based
Sequence length penalty ~1.5โ€“2ร— longer for numbers
Arithmetic structure Consistent place values
04 SentencePiece: The Framework Behind It
Why SentencePiece: Gemini's tokenizer is implemented in SentencePiece โ€” Google's open-source tokenizer framework that handles raw text without pre-tokenization. No regex splitting on whitespace, no language-specific rules. One framework, 100+ languages, same rules.

Most BPE implementations (including OpenAI's tiktoken and Meta's LLaMA 3 tokenizer) use a pre-tokenization step: a regex splits raw text into candidate words before BPE merges run. This is where language-specific assumptions creep in. A space-splitting regex is wrong for Chinese. A punctuation splitter is wrong for Thai. Even a carefully written Unicode-aware regex bakes in assumptions about what constitutes a "word."

SentencePiece avoids this entirely. Its key innovation: treat whitespace as a regular Unicode character (represented as โ–) and run tokenization on the raw text stream without any pre-splitting. This makes it genuinely language-agnostic โ€” the tokenizer sees Japanese text the same way it sees English, because it doesn't try to identify word boundaries before tokenizing.

import sentencepiece as spm

# Training a SentencePiece Unigram model (simplified)
spm.SentencePieceTrainer.train(
    input='multilingual_corpus.txt',
    model_prefix='gemini_tok',
    vocab_size=256000,
    model_type='unigram',          # Unigram LM, not BPE
    character_coverage=0.9999,     # cover 99.99% of Unicode chars
    split_digits=True,             # Gemini's arithmetic fix
    byte_fallback=True,            # unknown bytes โ†’ byte tokens
    normalization_rule_name='nfkc' # Unicode normalization
)

Two parameters in that training call are particularly important for Gemini's design:

split_digits=True โ€” this is the arithmetic fix. It instructs SentencePiece to add special handling that prevents digit sequences from merging. Each digit gets its own token, regardless of what the Unigram LM objective would otherwise do.

byte_fallback=True โ€” for any byte sequence that cannot be represented by the learned vocabulary, fall back to individual byte tokens (256 possible byte tokens are always in the vocabulary). This makes the tokenizer complete: no input can ever produce an unknown token. Previously, encountering an out-of-vocabulary character would produce a special [UNK] token, losing information. With byte fallback, the model always has access to the raw bytes.

The byte fallback is underappreciated: it means Gemini's tokenizer has no out-of-vocabulary problem. Novel scripts, unusual Unicode characters, even garbled byte sequences โ€” all representable. This is especially important for OCR input, code generation with unusual symbols, and robustness to adversarial inputs that exploit tokenizer edge cases.
05 One Tokenizer, Entire Model Family
The deployment decision: Google uses the same 256K SentencePiece tokenizer across Gemma 2, Gemma 3, Gemini 1.5, and Gemini 2.0. One vocabulary, shared embeddings, locked for the foreseeable future.

This is a significant operational commitment. Meta locked their LLaMA 3 tokenizer unchanged across the 3.1, 3.2, and 3.3 series. Google has done the same for their 256K vocabulary across a broader family. The reason is compatibility: downstream fine-tunes, embeddings, RLHF pipelines, and retrieval systems that use the tokenizer's indices need to remain stable. Every tokenizer change breaks everything upstream.

The 256K vocabulary choice was partly motivated by wanting a design that wouldn't need to change. A larger vocabulary front-loads the compression problem โ€” spending more parameters on embeddings now avoids having to retokenize everything when you inevitably need better multilingual coverage later.

This is the same reasoning behind why LLaMA 2's 32K vocabulary was a pain point: when Meta built LLaMA 3, they had to change the tokenizer to fix multilingual coverage, and that change โ€” 32K to 128K โ€” added roughly a billion parameters and broke compatibility with everything trained on LLaMA 2.

Used by Gemma 2, Gemma 3, Gemini 1.5, Gemini 2.0
Languages covered 100+
Unknown tokens Zero (byte fallback)
06 What Gemini's Tokenizer Gets Right
The summary: Gemini made three decisions that other labs haven't: 256K vocabulary (largest in production), Unigram LM with probabilistic sampling, and explicit split-digit tokenization. Each one accepted a cost upfront to fix a problem that BPE-based tokenizers push into the model.

What's interesting when you look at Gemini's tokenizer as a whole is that every unusual decision is a deliberate fix for a known failure mode. 256K vocabulary: fix the token tax for non-English languages. Unigram LM: principled multilingual coverage, probabilistic augmentation during training. Split-digit: fix arithmetic. Byte fallback: fix unknown tokens. SentencePiece without pre-tokenization: fix language-specific assumptions.

Compare this to the "extend cl100k_base" approach used by Qwen โ€” which preserves English/code tokenization quality at the cost of adding CJK vocabulary on top of a system that wasn't designed for it โ€” or the "switch to tiktoken BPE" approach used by LLaMA 3, which achieved 4ร— vocabulary expansion while accepting a different set of limitations on multilingual coverage.

None of these approaches is strictly better. Gemini's tokenizer trades parameter efficiency for breadth. LLaMA 3's trades breadth for speed (tiktoken is significantly faster than SentencePiece). Qwen's trades architectural elegance for backwards compatibility. The right choice depends entirely on what you're optimizing for โ€” and that's before you consider whether byte-level models like BLT make the entire vocabulary question obsolete at the next scale.

The deeper lesson: the tokenizer encodes assumptions about language that the model cannot override. Split-digit tokenization doesn't make arithmetic easier for the model โ€” it makes it possible. The same structure applies to multilingual coverage, noise robustness, and unknown symbols. The tokenizer makes architectural commitments before a single training step runs. Getting those commitments right matters more than most papers discuss.
REF References

Gemma 3 Technical Report โ€” Google DeepMind (March 2025)
SentencePiece: A simple and language independent subword tokenizer and detokenizer โ€” Kudo & Richardson (2018)
Subword Regularization: Improving Neural Network Translation Models with Multiple Subword Candidates โ€” Kudo (2018, the Unigram LM paper)
LLaMA 3: The Llama 3 Herd of Models โ€” Meta AI (2024)
Tokenisation is NP-Complete โ€” Whittington et al. (ACL 2025, arXiv:2412.15210)
Tokenization Constraints in LLMs โ€” arXiv 2505.14178 (arithmetic failure formal analysis)

Read the full tokenizer landscape review โ†’