PROGRAM ZERO 18-month live AI, LLM & full-stack programme · ₹17,999 for all 18 months · Starts 9 January 2027
Explore Program Zero →
Careers Ninza — business and startup leadership training
JOIN ZERO NINZA KIDS
JOIN ZERO NINZA KIDS
See all programs → Free live masterclass → Guides & articles → Newsletter →
Careers Ninza
AI & AUTOMATION 9 min read · Updated 13 October 2026

What is tokenization in LLMs? BPE, WordPiece and SentencePiece explained

Before a language model reads a word, a tokenizer chops text into pieces. How BPE, WordPiece and SentencePiece work, why tokens decide cost and context, and why Indian languages are affected most.

CN
Careers Ninza AI faculty
Careers Ninza · Kolkata, India
Learn this live in Program Zero

Tokenization is how a language model turns text into the units it actually reads, called tokens. Modern tokenizers split text into subword pieces using methods such as byte-pair encoding (BPE), WordPiece or SentencePiece. Tokens matter in practice because models are priced, limited and slowed by token count, and some languages use far more tokens than others.

Tokenization is the least glamorous part of a language model and one of the most consequential. It shapes what a model can represent, how much a request costs, how much fits in the context window, and how fairly a model treats different languages. Here is how it works.

Why not just use words or characters?

Whole words create a huge vocabulary and still miss rare words, names and typos. Single characters keep the vocabulary tiny but make sequences very long, which makes models slow and less able to capture meaning. Subword tokens are the compromise: common words become single tokens, while rare words are built from smaller, reusable pieces.

ApproachVocabularySequence lengthProblem
WordsVery largeShortUnknown words and huge vocabularies
CharactersTinyVery longSlow and harder to learn meaning
Subwords (BPE etc.)Moderate, fixed sizeMediumUneven across languages

How does byte-pair encoding work?

BPE starts from individual characters or bytes and repeatedly merges the most frequent adjacent pair into a new token, until the vocabulary reaches a chosen size. Frequent sequences such as “ing” or “the” become single tokens. Its use for neural models was popularised by research on translating rare words with subword units. Many GPT-style models use byte-level BPE, which can represent any text without unknown tokens.

What are WordPiece and SentencePiece?

—WordPiece is similar to BPE but chooses merges that most increase the likelihood of the training data; it is associated with BERT-style models.
—SentencePiece is a language-independent tokenizer library that treats text as a raw stream, including spaces, so it works well for languages that do not separate words with spaces. It supports BPE and unigram models.

Why do tokens affect cost and speed?

Model APIs usually charge per input and output token, and generation time grows with output tokens. The context window, the maximum text a model can consider at once, is also measured in tokens. A prompt that tokenises efficiently is cheaper, faster and leaves more room for useful context.

Why are Indian languages affected?

Tokenizers learn their pieces from training data. If that data is mostly English, Devanagari, Bengali, Tamil and other scripts get split into many more, smaller tokens than equivalent English text. The result is higher cost, slower responses and less effective context for Indian-language users. Tokenizers trained on balanced, multilingual data reduce this gap. Our guide to building AI for Indian languages covers the wider challenges.

A simple, eye-opening exercise: tokenise the same sentence in English and in your own language with a tokenizer library, and compare the token counts. The difference shows why tokenizer choice matters for products serving India.

How do you build a tokenizer?

—Collect a representative text sample in the languages and domains you care about.
—Normalise text consistently, including Unicode normalisation for Indian scripts.
—Choose an algorithm and vocabulary size; larger vocabularies shorten sequences but enlarge the model.
—Train the tokenizer, then test it on unseen text, code and mixed-language input.
—Freeze it: a model is tied to the tokenizer it was trained with.

How does tokenization affect what models can do?

Tokenization quietly shapes model behaviour. If a number is split into awkward pieces, arithmetic gets harder. If a rare name is split into many fragments, the model may misspell it. If code indentation becomes many tokens, long programs fill the context window quickly. Engineers who understand this design prompts, chunk documents for retrieval and estimate costs much more accurately.

How should you count tokens in your own projects?

Use the tokenizer that matches the model you are calling, since different models use different vocabularies. Count tokens for typical prompts, retrieved context and expected outputs, then multiply by request volume to estimate monthly cost. Trimming repeated instructions, keeping retrieved chunks focused and asking for concise output are usually the cheapest wins.

What tokenization problems do developers hit?

—Numbers and dates split oddly, which can affect arithmetic and formatting.
—Leading spaces creating different tokens for the same word.
—Code and special characters using many tokens.
—Mismatched tokenizers between training and inference, which silently breaks a model.

What are special tokens?

Tokenizers also include special tokens that are not ordinary text: markers for the start and end of a sequence, padding, and in chat models, tokens that separate system instructions, user messages and assistant replies. Formatting a conversation with the wrong special tokens is a common reason a fine-tuned model behaves strangely, so chat templates must match exactly what the model was trained with.

Where does tokenization fit in learning LLMs?

It comes first. Before attention, embeddings or training, you need to know what the model is actually reading. Program Zero’s explainer on how LLMs like ChatGPT and Claude work starts with tokens for exactly this reason, and its NLP, transformers and LLM phase includes building a custom tokenizer with BPE, WordPiece and SentencePiece before training a small GPT. For the architecture that consumes tokens, see transformers explained without the maths.

Program Zero runs live online, so you can learn this from anywhere in India: metros such as Mumbai, Delhi NCR, Kolkata and Chennai, growing cities such as Chandigarh, Bhopal, Surat and Vadodara, and smaller towns such as Dehradun, Jammu, Gwalior and Jabalpur. Every learner joins the same evening classes, at the same fee.

Want to learn this live, with mentors?

In Program Zero you build a custom tokenizer, then a transformer and a small GPT that uses it, over 18 months of live evening classes. ₹17,999 for all 18 months; the batch starts 9 January 2027.

PROGRAM ZERO · 18-MONTH LIVE PROGRAMME
Program Zero: AI, LLM & Full-Stack Developer Programme

Learn AI, large language models and full-stack development live with mentors: from your first line of code to building and deploying your own language model.

₹17,999 for all 18 monthsStarts 9 January 2027Mon–Fri, 9:00–10:30 PM ISTEvery class recorded

Frequently asked questions

What is a token in an LLM?+

A token is a unit of text a language model reads and writes, often a word, part of a word, a punctuation mark or a space. Models process, price and limit text by token count, so efficient tokenization makes requests cheaper and leaves more room in the context window.

What is byte-pair encoding?+

Byte-pair encoding is a tokenization method that starts from characters or bytes and repeatedly merges the most frequent adjacent pair into a new token until a target vocabulary size is reached, so common sequences become single tokens and rare words are built from pieces.

What is the difference between BPE, WordPiece and SentencePiece?+

BPE merges the most frequent pairs. WordPiece chooses merges that most improve the likelihood of the training data. SentencePiece is a language-independent library that treats text, including spaces, as a raw stream and supports BPE and unigram models.

Why do LLMs charge per token?+

Model computation and memory grow with the number of tokens processed and generated, so tokens are a fair proxy for the work done. That is why shorter prompts and concise outputs reduce both cost and response time.

Why do Indian languages use more tokens?+

Tokenizers trained mostly on English learn fewer pieces for Indian scripts, so the same meaning is split into more, smaller tokens. That increases cost, slows responses and uses up the context window faster for Indian-language users.

How many tokens is a word?+

In English, a common word is often one token and longer or rarer words are split into several, so a rough average is a little more than one token per word. Other languages and scripts can need considerably more tokens per word.

Can I change the tokenizer of a trained model?+

Not without retraining or significant adaptation, because the model's embeddings are tied to its vocabulary. Tokenizer choice is made before training and then kept fixed for that model.

Where can I learn how to build a tokenizer?+

Program Zero by Careers Ninza covers tokenizers in depth, including building a custom one, before transformers and training a small GPT, within an 18-month live programme for Rs 17,999.

Related reading

AI & AUTOMATION LLM Course: What You Should Learn to Build Large Language Models Most LLM courses teach you to call an API. Building and adapting language models needs more: tokenisers, transformers, training, fine-tuning, alignment, evaluation and serving. Here is the full syllabus, in order. 10 min read AI & AUTOMATION Agentic AI Course: The Skills You Need to Build AI Agents in 2027 Building reliable AI agents takes more than chaining prompts. The skills an agentic AI course should teach, from tool use and memory to evaluation, security and deployment, and how to judge a course. 10 min read AI & AUTOMATION RLHF and DPO Explained: How Language Models Learn to Be Helpful A pretrained model predicts text; an assistant follows instructions. The bridge is alignment: instruction tuning, RLHF and DPO. How each works, how they differ, and their honest limitations. 9 min read

We teach this, live

Every article here comes from something we teach. Sit in on a free masterclass and judge the mentors yourself.