AIWiki
Malaysia
Back to all articles
AI FoundationstokenizationNLPBPE

Tokenizer

4 min readUpdated November 2026
Tokenizer
Type
Text preprocessing component
Used in
Natural language processing, large language models
Key methods
Byte-pair encoding, WordPiece, Unigram LM, SentencePiece
Typical vocabulary
Tens of thousands of entries
Emerged
1990s (subword methods widely from 2016)
Related
Embedding, Context window, Vocabulary
A tokenizer is the program that splits text into tokens — words, word fragments or individual characters — and maps each one to a numeric ID that a neural network can consume. Every large language model is trained and served behind one, and its output is the model's actual view of language: the network never sees characters, only the token sequence the tokenizer produces.

Background

Early systems used word-level dictionaries, which failed on unseen words and inflected forms. A statistical alternative, byte-pair encoding (BPE), was introduced by Philip Gage in 1994 as a general-purpose compression technique and adapted for neural machine translation by Sennrich and colleagues in 2016, where it solved the open-vocabulary problem by learning subword units from data.[1][2]

Modern systems choose among a few families: BPE, which repeatedly merges the most frequent adjacent pair; WordPiece, used by BERT, which merges by likelihood rather than raw frequency; Unigram LM, which starts from a large vocabulary and prunes it probabilistically; and SentencePiece, which treats input as a raw byte stream so that tokenization does not depend on pre-existing word boundaries or a specific language's whitespace conventions.[3] Many current English models instead use a byte-level BPE vocabulary, guaranteeing that any input — including emoji and rare scripts — can be encoded.[4]

Key Concepts

  • Vocabulary. The set of all token strings the model knows, typically tens of thousands of entries plus special control tokens such as the start-of-text marker. A token outside the vocabulary must be broken down into smaller units.
  • Subword splitting. Common words stay intact; rare words are decomposed, so the model handles unseen vocabulary instead of failing on it.
  • Tokens are not words. In English, one token averages roughly four characters, so a 100,000-token document is not 100,000 words. Context windows, token quotas and API metering are all counted in these units.
  • Lossy, one-way knowledge. The tokenizer also defines what the model can express: text that encodes to long sequences costs more context and more compute to process than equivalent text the tokenizer handles compactly.
  • Language asymmetry. Tokenizers trained mostly on English text split other scripts into more tokens per unit of meaning; research on tokenizer bias has documented exactly this effect across dialects and languages.[5]

Applications

Tokenizers are used wherever text enters or leaves a model: chat interfaces that display remaining context, code assistants, translation and transcription tools, and retrieval systems that chunk documents by token count rather than by line. Practitioners also run tokenizers locally to estimate cost and context fit before sending data anywhere, using libraries such as SentencePiece or tiktoken.[3][4]

>See Also

🇲🇾Malaysian Context

🇲🇾 Relevance to Malaysia: token efficiency is a practical cost and quality question for Malaysian organisations. Bahasa Melayu, Chinese and Tamil text encoded by an English-heavy tokenizer expands into more tokens than the equivalent English text, which consumes context window faster and inflates per-token billing — a measurable factor when a Malaysian business compares models or estimates deployment budgets. Teams developing or evaluating national language capabilities, in line with NAIO and MDEC priorities for Malay-language AI, typically start by measuring token counts on representative Malay corpora rather than assuming English benchmarks transfer. Because tokenization is the first step before any text is sent to a hosted model, organisations handling personal data should also account for it when applying PDPA 2010 safeguards to data leaving their systems.

References

  1. ↑Gage, P. A New Algorithm for Data Compression. ACM SIGPLAN Notices, 29(4), 1994
  2. ↑Sennrich, R., Haddow, B. and Birch, A. Neural Machine Translation of Rare Words with Subword Units. arXiv:1508.07909. https://arxiv.org/abs/1508.07909
  3. ↑Kudo, T. and Richardson, J. SentencePiece: A simple and language independent subword tokenizer and detokenizer for Neural Text Processing. arXiv:1808.06226. https://arxiv.org/abs/1808.06226
  4. ↑OpenAI. tiktoken: a fast BPE tokenizer. https://github.com/openai/tiktoken
  5. ↑Dou, Y. et al. Understanding and Countering Linguistic Bias in Multilingual Tokenizers. arXiv:2012.15441. https://arxiv.org/abs/2012.15441