Book a 30-min callBook a call

LLM tokenization explained: BPE, vocabularies and why token counts differ

How LLM tokenizers work: BPE, byte-level BPE, WordPiece and Unigram, vocabulary size, and why one text costs different token counts across models.

A sentence box split into a row of colored token blocks, each linked by a line to a numbered slot in a vocabulary stack.
Written by
BYD Tech
Published
Topic
Deep dives
Reading time
15 min read

Questions people ask

How many words is a token?

It depends on the tokenizer and the text. The tiktoken README gives about 4 bytes per token on average in practice, which for English prose is roughly three quarters of a word. Other languages, code and long numbers can need many more tokens per word, so count with the model's own tokenizer whenever the number matters.

Why does the same prompt use more tokens on a different model?

Each model family trains its own tokenizer, with its own vocabulary and training data, so the same text splits into different pieces. Even one vendor can change tokenizers between model generations. Recount your prompts whenever you change models.

Can I use tiktoken to count tokens for Claude or Gemini?

Not accurately. tiktoken implements OpenAI's encodings, and other model families use their own tokenizers. Use the vendor's counting endpoint or the tokenizer that ships with the model; for Claude, that is the count_tokens endpoint.

What is the difference between BPE and WordPiece?

Both build a subword vocabulary bottom-up from characters. BPE adds the most frequent adjacent pair at every step. WordPiece, as the GNMT paper describes it, chooses pieces to maximize the likelihood of the training data. The unigram model goes the other way, pruning a large vocabulary down.

Why do LLMs struggle to count the letters in a word?

Because the model sees tokens, not letters. A word is often one or two tokens, so the model never directly sees its individual characters and has to infer spelling from training. Asking it to spell the word out first, or to use a code tool, usually helps.

Building something like this?