BPE vs WordPiece vs SentencePiece: Which One Does Your Model Use

A side-by-side comparison of BPE, WordPiece, and SentencePiece: how each picks its merges, how to spot them in the tokens, and which models use which.

Aug 10, 20266 min readFollow

Topics You Will Master

The one rule that separates BPE, WordPiece, and SentencePiece
How to spot each method just by looking at its tokens
Which famous models use which tokenizer
How to pick a method when you train your own

We have now met all three subword methods. BPE glues the most frequent pair. WordPiece glues the pair that best predicts the text. SentencePiece skips word splitting and reads the raw stream. Three methods, one job.

So how do you tell them apart in the wild? The good news is that each one leaves a fingerprint in its output, and once you know the fingerprint you can name the tokenizer at a glance.

Bestseller

LLM Fine-Tuning with Hugging Face: LoRA, QLoRA, PEFT

Fine-tune BERT, T5, ViT, LLaMA-style models and Qwen3-TTS using Hugging Face Transformers, custom datasets, LoRA, QLoRA.

Enroll on Udemy 30 day refund, lifetime access

One Word, Three Tokenizers


The One Difference That Matters

All three methods start small and build bigger pieces. That part is shared. The difference is the question each one asks before it merges.

BPE asks "which pair appears most often?" WordPiece asks "which pair helps me predict text best?" SentencePiece asks something else entirely, because it changes the input rather than the rule: "what if we never split on spaces at all?"

In simple words, BPE and WordPiece argue about which pair to glue. SentencePiece argues about what counts as a starting piece.

How BPE and WordPiece Pick a Merge


Fingerprint One: The ## Marker

The easiest tell is the ## prefix. If you see tokens like play and ##ing, you are looking at WordPiece. No other common method uses that marker.

PYTHON
# WordPiece output has ## on inside pieces
# "playing" -> ["play", "##ing"]

The ## says "join me to the piece before me". It only appears inside a word, never at the start.

Reading the ## Marker


Fingerprint Two: The Space Marker

SentencePiece leaves a different mark. Because it keeps spaces as part of the token, its pieces often begin with a small underscore-style symbol that stands for a space.

So a sentence tokenized by SentencePiece looks like _New, _York, _City. That leading mark is the space itself, travelling with the token.

Where the Space Goes


Fingerprint Three: Plain Pieces

If the tokens have no ## and no space marker, and the pieces look like ordinary chunks of words, you are most likely looking at BPE.

Byte-level BPE, the version GPT uses, sometimes shows odd-looking symbols for spaces and accents, because it works on raw bytes. That is its own small tell.

Let me tabulate the fingerprints for your better understanding.

What you see in the tokens The method Example
## in front of inside pieces WordPiece play, ##ing
A leading underscore mark SentencePiece _New, _York
Plain pieces, no markers BPE low, est

Naming a Tokenizer From Its Output


How Each One Handles a New Word

Give all three the same unseen word and they all survive, but they cut it differently. BPE replays its merge list. WordPiece takes the longest matching piece first. SentencePiece works from its pruned vocabulary over the raw stream.

The splits often look similar. WordPiece tends to cut at meaningful seams a little more often, because its rule rewards pieces that predict real language.

One Rare Word, Three Splits


Which Models Use Which

This is the practical part. BPE, in its byte-level form, powers the GPT family and many open models. WordPiece powers the BERT family. SentencePiece powers T5, Llama, and most multilingual models.

Here, we can see the three methods laid out side by side.

BPE WordPiece SentencePiece
Merge rule Most frequent pair Pair that best predicts Prune the weakest pieces
Starting units Characters, split on spaces Characters, split on spaces The raw character stream
Needs spaces? Yes Yes No
Marker in output None ## on continuations Underscore for the space
Rebuilds text exactly By rule By rule By construction
Typical models GPT, RoBERTa, BART BERT, DistilBERT, Electra T5, mT5, Llama, ALBERT

If you are loading a model from Hugging Face, you rarely choose the tokenizer yourself. It ships with the model, and it must match, because the token IDs are meaningless to a model trained on a different vocabulary.

The Tokenizer Ships With the Model


Why the Tokenizer Must Match the Model

Here is a mistake worth avoiding. A token ID is just a row number in the model's embedding table. Row 5021 means "able" only because that model learned it that way.

Swap in a different tokenizer and the same word turns into different numbers. The model will still run, but it will read nonsense. This is why every model on Hugging Face ships its tokenizer alongside its weights.

PYTHON
# the tokenizer and the model must come from the same checkpoint
# token id 5021 means "able" only for THIS vocabulary

What Breaks When the Tokenizer Is Wrong


Choosing a Method for Your Own Model

If you ever train a tokenizer from scratch, the choice is simpler than it looks. For English-only text, BPE is a safe default. For a BERT-style encoder, WordPiece fits the family. For anything multilingual, or text with code, or scripts without spaces, SentencePiece is the natural pick.

In practice most teams start from an existing tokenizer and only train a new one when their text looks nothing like ordinary web text.

Choosing a Method for a New Tokenizer


The Shared Family Tree

Step back and the three look less like rivals and more like cousins. All three build subwords. All three keep the vocabulary at a fixed size. All three survive words they never saw.

That shared idea, pieces smaller than words but bigger than letters, is what makes modern language models possible at all.

Where the Three Methods Diverge


Recap

This is how the three subword methods compare. BPE merges the most frequent pair, WordPiece merges the pair that best predicts real language, and SentencePiece drops word splitting entirely so it can read any script.

You can name them by their fingerprints: ## means WordPiece, a leading space mark means SentencePiece, and plain pieces usually mean BPE. Whichever one your model uses, the rule is the same: the tokenizer must match the model, because token IDs only mean something inside the vocabulary that created them.

In the next article, we look at the special tokens that sit alongside these pieces, the ones in square brackets like [CLS] and [SEP], and what each of them is for.

Found this useful? Keep building with me.

New tutorials every week on YouTube: or go deeper with a full structured course.

Find this tutorial useful?

Subscribe to our YouTube channels for more practical production walk-throughs.

Discussion & Comments