---
id: TECH-TOK-001
title: "Tokenization and Embeddings"
alternative_names:
  - "Subword Tokenization"
  - "Byte-Pair Encoding and Word Embeddings"
  - "Input Representation in Language Models"
category: "Technical → Language Models"
volume: III
chapter: 19
entry_type: "Technical Article"
level: 3
status: "Draft"
last_reviewed: 2026-10-15
version: "0.1.0"
prerequisites:
  - "TECH-LLM-001"
  - "TECH-ARCH-001"
related_entries:
  - "TECH-NN-001"
  - "TECH-ATTN-001"
  - "TECH-RAG-001"
  - "TECH-MM-001"
  - "TECH-INFER-001"
  - "SAFE-ETHICS-001"
---

# Tokenization and Embeddings

## 1. Concise Definition
**Tokenization** is the procedure that converts raw input (text, as a sequence of bytes or characters) into a sequence of discrete symbols called **tokens** drawn from a fixed vocabulary. An **embedding** is a learned dense vector assigned to each token (or, in later models, to a whole passage), which is the numerical form on which a neural network operates. Together they define the interface between human-readable data and the Transformer layers of a language model.

## 2. Overview & Significance
A neural language model (see [TECH-LLM-001]) cannot consume a string directly. It needs a finite vocabulary of $|V|$ symbols, each mapped to a vector, and it predicts a distribution over that vocabulary at each step. The choice of vocabulary is therefore a modelling decision with consequences for several things:

- **Sequence length and compute.** A tokenizer that represents a text in fewer tokens makes attention and generation cheaper, because cost grows with the number of tokens (see [TECH-ARCH-001], [TECH-INFER-001]).
- **Coverage.** Word-level vocabularies cannot represent unseen words; characters or bytes can represent anything but yield long sequences.
- **Fairness and cost.** The same content can require very different token counts in different languages, which affects price, latency and usable context (Petrov et al., 2023; Ahia et al., 2023).
- **Reliability.** Tokens present in a vocabulary but rare or absent in training data can cause erratic behaviour (Land & Bartolo, 2024).

Embeddings matter because the geometry of the vector space determines what the model can easily generalise. The same idea extends beyond input: embedding models that map passages or images to vectors are the basis of semantic search (see [TECH-RAG-001]) and of multimodal alignment (see [TECH-MM-001]).

## 3. Historical Development
Before neural models, text was represented as sparse count vectors over a word vocabulary. Dense, learned word vectors became practical with the word2vec models of Mikolov et al. (2013a, 2013b), which learned vectors from large corpora fast enough to use 1.6 billion words in under a day and evaluated them on syntactic and semantic similarity. GloVe (Pennington, Socher & Manning, 2014) fitted vectors to global co-occurrence statistics. fastText (Bojanowski et al., 2017) composed word vectors from character n-grams so that rare and unseen words obtain representations.

The open-vocabulary problem in neural machine translation led Sennrich, Haddow and Birch (2016) to adopt a segmentation based on the byte pair encoding (BPE) compression algorithm, encoding rare words as sequences of subword units; they reported gains of 1.1 and 1.3 BLEU over a back-off dictionary on WMT 15 English–German and English–Russian. Wu et al. (2016) described a related wordpiece approach for Google's translation system. Kudo (2018) proposed a unigram-language-model segmentation with subword regularisation, and Kudo and Richardson (2018) released SentencePiece, which trains directly on raw text without requiring a pre-tokenised word sequence. BERT (Devlin et al., 2019) used a subword vocabulary together with contextual representations, replacing static word vectors with ones that depend on the surrounding sentence.

More recently, token-free approaches processing bytes directly have been scaled to billions of parameters (Xue et al., 2022; Pagnoni et al., 2024), without displacing subword tokenizers in widely documented models as of 2026-10-15.

## 4. Technical / Conceptual Explanation

### 4.1 Byte-pair encoding
BPE learns a vocabulary from a training corpus. In its subword form (Sennrich et al., 2016):

1. Start with a vocabulary of base symbols (characters, or the 256 possible byte values in byte-level variants).
2. Count all adjacent symbol pairs in the corpus.
3. Merge the most frequent pair into a new symbol and add it to the vocabulary; record the merge rule.
4. Repeat until the vocabulary reaches a target size.

At encoding time the learned merges are applied to new text in the order in which they were learned. Frequent words become single tokens; rare words decompose into several pieces. Byte-level BPE starts from bytes so that any Unicode string, including text never seen in training, is representable.

### 4.2 Unigram and WordPiece variants
The unigram model (Kudo, 2018) starts from a large candidate vocabulary and prunes it to maximise the likelihood of the training data under a unigram language model; it can produce several segmentations of the same string with different probabilities, which subword regularisation uses as training noise. WordPiece (Wu et al., 2016) is likewise a data-driven subword scheme. The families differ in how the vocabulary is built and in how ties and ambiguities are resolved; all of them produce a deterministic or sampled mapping from a string to a sequence of vocabulary indices.

### 4.3 The embedding layer
Given token indices $t_1,\dots,t_n$ with $t_i \in \{1,\dots,|V|\}$ and an embedding matrix $E \in \mathbb{R}^{|V|\times d}$, the input to the Transformer is the matrix whose $i$-th row is $x_i = E_{t_i}$, with positional information added or applied inside attention (Vaswani et al., 2017; see [TECH-ARCH-001]). The matrix $E$ is a trained parameter, so $|V|\cdot d$ parameters are spent on it; the output projection back to $|V|$ logits has the same shape and some models share the two matrices. A language model is trained to minimise the cross-entropy

$$ \mathcal{L} = -\frac{1}{n}\sum_{i=1}^{n} \log p_\theta(t_i \mid t_{<i}) $$

over tokens, so its units of prediction are the tokenizer's tokens.

### 4.4 Why tokenizers complicate comparison
Because $\mathcal{L}$ is measured per token, models with different tokenizers have different units. If a tokenizer yields on average $\tau$ tokens per byte of text and the loss in nats per token is $\ell$, the loss per byte in bits is $\ell\,\tau / \ln 2$. Comparisons across tokenizers should therefore use a per-byte or per-character measure, not per-token perplexity. This is a direct consequence of the definitions and is not a claim about any specific model.

### 4.5 Static versus contextual embeddings
word2vec, GloVe and fastText assign one vector per word type, so a polysemous word has one vector. A Transformer layer stack outputs contextual vectors in which the same token receives different representations in different sentences (Devlin et al., 2019). Sentence-level embedding models, such as Sentence-BERT (Reimers & Gurevych, 2019), pool or fine-tune such representations so that semantically similar sentences have high cosine similarity; this is the mechanism used in embedding-based retrieval.

### 4.6 Vocabulary size trade-off
A larger vocabulary shortens sequences but enlarges the embedding and output matrices and makes each rare token less frequently trained. As one documented data point, the Llama 3 report describes a 128K-token vocabulary (100K tokens from the tiktoken tokenizer plus 28K additional tokens for non-English languages) and states that, versus the Llama 2 tokenizer, compression on a sample of English data improved from 3.17 to 3.94 characters per token (Grattafiori et al., 2024). This is a single developer-reported figure on one sample; it is not a general law.

## 5. Types, Components & Classifications

| Level | Description | Advantages | Disadvantages |
| :--- | :--- | :--- | :--- |
| Word | One token per word type | Short sequences, readable | Unseen-word problem; huge vocabularies |
| Character | One token per character | No unseen symbols | Long sequences |
| Byte | One token per byte (256 symbols) | Language-agnostic; no preprocessing (Xue et al., 2022) | Longer sequences, more compute per text |
| Subword (BPE, WordPiece, Unigram) | Variable-length pieces learned from data | Compromise between coverage and length | Language-dependent efficiency; artefacts |
| Learned patches | Dynamic-length byte groups chosen by the model | Reported to match token-based models at scale (Pagnoni et al., 2024) | Newer; less widely deployed |

The Byte Latent Transformer (Pagnoni et al., 2024) groups bytes into patches whose lengths depend on the entropy of the next byte; the authors report the first FLOP-controlled scaling study of byte-level models up to 8B parameters and 4T training bytes and better scaling than token-based models at fixed inference cost. This is single-group evidence (Preliminary).

## 6. Applications & Concrete Examples
- **Text LLMs.** Every widely used autoregressive language model uses a tokenizer, with the vocabulary and algorithm usually published for open-weight models. For closed models the vocabulary may be exposed through the API or a library, but whether the training-time tokenizer matches a published one is a developer matter; this article does not infer it.
- **Billing.** Commercial APIs commonly price by tokens. Ahia et al. (2023) analysed OpenAI's API on multilingual benchmarks in 22 languages and report that speakers of many of the languages are overcharged while obtaining poorer results, because of differences in token counts.
- **Retrieval.** Dense passage encoders map queries and documents to vectors for nearest-neighbour search (Reimers & Gurevych, 2019; Karpukhin et al., 2020).
- **Cross-modal embeddings.** CLIP-style models align image and text embeddings in a shared space (see [TECH-MM-001]).

## 7. Advantages, Limitations & Unresolved Questions

### Advantages of subword tokenization
Fixed, moderate sequence lengths; no unseen-word failure; a mature toolchain (Kudo & Richardson, 2018).

### Limitations
- **Cross-language disparity.** Petrov et al. (2023) report that the same text translated into different languages can differ in tokenization length by up to 15 times in some cases, even for tokenizers built for multilingual support, with character- and byte-level models still showing over 4x differences for some language pairs. They argue this produces unequal cost, latency and available context (see [SAFE-ETHICS-001]).
- **Tokenizer quality affects downstream performance.** Rust et al. (2021) examine monolingual performance of multilingual models as a function of tokenizer quality.
- **Under-trained ("glitch") tokens.** Land and Bartolo (2024) present methods to detect vocabulary tokens that are nearly or entirely absent from training data and show such tokens are prevalent across a diverse set of models; these can induce unwanted behaviour.
- **Opaque units.** Models see tokens, not characters. Tasks that depend on spelling or on character-level structure can be harder; the extent for any given model must be measured, not assumed.

### Unresolved questions
1. Whether tokenizer-free models will match subword models at the largest scales; current evidence is limited to the studies cited (Preliminary).
2. How to design vocabularies that are fair across languages without large cost in compute.
3. How much of the geometric structure of embedding spaces reflects meaning rather than corpus statistics; the word-vector literature measures similarity tasks and does not settle this.

## 8. Current State of Knowledge
As of 2026-10-15, subword tokenization (BPE variants and SentencePiece-style unigram or BPE models) remains the standard in documented language models, with byte-level BPE common for coverage. Dense learned embeddings, both input embeddings and sentence-level retrieval embeddings, are standard components. Claims about the tokenizer or vocabulary of a specific closed model should be taken only from developer documentation or from the model's public tokenizer, and are otherwise **undisclosed**. Current vocabulary sizes and compression rates of named models belong in the Living Reference (`MODEL-001`), not in this article.

## 9. Future Trajectory & Strategic Outlook
Observed directions: dynamic or learned segmentation (Pagnoni et al., 2024), explicit tests for under-trained tokens (Land & Bartolo, 2024), and fairness-aware tokenizer design (Petrov et al., 2023). Whether byte-level or patch-based models become the default is open; no forecast is registered here.

## 10. Related Entries & Knowledge Graph
- **Foundational Concepts**:
  - [[TECH-LLM-001] Large Language Models](./TECH-LLM-001_large_language_models.md): The models that consume tokens.
  - [[TECH-ARCH-001] The Transformer Architecture](./TECH-ARCH-001_transformer_architecture.md): Where embeddings and positional information enter the network.
  - [[TECH-NN-001] Artificial Neural Networks](./TECH-NN-001_artificial_neural_networks.md): Learned representations in general.
- **Related Methods & Technologies**:
  - [[TECH-ATTN-001] Attention Mechanisms](./TECH-ATTN-001_attention_mechanisms.md): Cost of attention grows with token count.
  - [[TECH-RAG-001] Retrieval-Augmented Generation](./TECH-RAG-001_retrieval_augmented_generation.md): Embedding-based retrieval.
  - [[TECH-MM-001] Multimodal Foundation Models](./TECH-MM-001_multimodal_foundation_models.md): Image and audio tokens and shared embedding spaces.
  - [[TECH-INFER-001] Inference, Quantization and Efficiency](./TECH-INFER-001_inference_quantization_and_efficiency.md): Token count drives serving cost.
- **Advanced Implications & Future Trajectories**:
  - [[SAFE-ETHICS-001] AI Ethics, Bias and Fairness](../vol08_safety_governance/SAFE-ETHICS-001_ai_ethics_bias_and_fairness.md): Language-community disparities.

## 11. References & Foundational Literature
1. Mikolov, T., Chen, K., Corrado, G., & Dean, J. (2013a). *Efficient Estimation of Word Representations in Vector Space*. arXiv:1301.3781. [word2vec architectures; vectors learned from a 1.6-billion-word set in under a day, evaluated on syntactic and semantic similarity].
2. Mikolov, T., Sutskever, I., Chen, K., Corrado, G., & Dean, J. (2013b). *Distributed Representations of Words and Phrases and their Compositionality*. NeurIPS 2013. arXiv:1310.4546. [Skip-gram training refinements and phrase vectors].
3. Pennington, J., Socher, R., & Manning, C. (2014). *GloVe: Global Vectors for Word Representation*. Proceedings of EMNLP 2014. https://doi.org/10.3115/v1/D14-1162. [Word vectors fitted to global co-occurrence statistics].
4. Bojanowski, P., Grave, E., Joulin, A., & Mikolov, T. (2017). *Enriching Word Vectors with Subword Information*. Transactions of the ACL, 5. arXiv:1607.04606. [Character n-gram composition for rare and unseen words].
5. Sennrich, R., Haddow, B., & Birch, A. (2016). *Neural Machine Translation of Rare Words with Subword Units*. Proceedings of ACL 2016. arXiv:1508.07909. [BPE-based subword segmentation; +1.1 and +1.3 BLEU on WMT 15].
6. Wu, Y., Schuster, M., Chen, Z., et al. (2016). *Google's Neural Machine Translation System: Bridging the Gap between Human and Machine Translation*. arXiv:1609.08144. [Wordpiece segmentation in a production NMT system].
7. Kudo, T. (2018). *Subword Regularization: Improving Neural Network Translation Models with Multiple Subword Candidates*. Proceedings of ACL 2018. arXiv:1804.10959. [Unigram language-model segmentation and sampled segmentations as regularisation].
8. Kudo, T., & Richardson, J. (2018). *SentencePiece: A simple and language independent subword tokenizer and detokenizer for Neural Text Processing*. Proceedings of EMNLP 2018 (System Demonstrations). arXiv:1808.06226. [Subword training directly from raw sentences].
9. Devlin, J., Chang, M.-W., Lee, K., & Toutanova, K. (2019). *BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding*. Proceedings of NAACL-HLT 2019. arXiv:1810.04805. [Subword input and contextual representations].
10. Reimers, N., & Gurevych, I. (2019). *Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks*. Proceedings of EMNLP-IJCNLP 2019. arXiv:1908.10084. [Sentence embeddings compared by cosine similarity].
11. Karpukhin, V., Oğuz, B., Min, S., Lewis, P., Wu, L., Edunov, S., Chen, D., & Yih, W. (2020). *Dense Passage Retrieval for Open-Domain Question Answering*. Proceedings of EMNLP 2020. arXiv:2004.04906. [Learned dense encoders for retrieval].
12. Xue, L., Barua, A., Constant, N., Al-Rfou, R., Narang, S., Kale, M., Roberts, A., & Raffel, C. (2022). *ByT5: Towards a token-free future with pre-trained byte-to-byte models*. Transactions of the ACL, 10. arXiv:2105.13626. [Byte-level Transformers with trade-off analysis].
13. Rust, P., Pfeiffer, J., Vulić, I., Ruder, S., & Gurevych, I. (2021). *How Good is Your Tokenizer? On the Monolingual Performance of Multilingual Language Models*. Proceedings of ACL-IJCNLP 2021. arXiv:2012.15613. [Tokenizer quality and monolingual downstream performance].
14. Petrov, A., La Malfa, E., Torr, P. H. S., & Bibi, A. (2023). *Language Model Tokenizers Introduce Unfairness Between Languages*. NeurIPS 2023. arXiv:2305.15425. [Up to 15x tokenization-length differences across languages for the same text].
15. Ahia, O., Kumar, S., Gonen, H., Kasai, J., Mortensen, D. R., Smith, N. A., & Tsvetkov, Y. (2023). *Do All Languages Cost the Same? Tokenization in the Era of Commercial Language Models*. Proceedings of EMNLP 2023. arXiv:2305.13707. [API pricing disparities across 22 languages].
16. Land, S., & Bartolo, M. (2024). *Fishing for Magikarp: Automatically Detecting Under-trained Tokens in Large Language Models*. Proceedings of EMNLP 2024. arXiv:2405.05417. [Detection of under-trained vocabulary tokens].
17. Pagnoni, A., Pasunuru, R., Rodriguez, P., et al. (2024). *Byte Latent Transformer: Patches Scale Better Than Tokens*. arXiv:2412.09871. [Entropy-based byte patching; scaling study up to 8B parameters and 4T bytes].
18. Grattafiori, A., Dubey, A., Jauhri, A., et al. (2024). *The Llama 3 Herd of Models*. arXiv:2407.21783. [Documents a 128K vocabulary and the reported change in compression rate].
19. Vaswani, A., Shazeer, N., Parmar, N., Uszkoreit, J., Jones, L., Gomez, A. N., Kaiser, Ł., & Polosukhin, I. (2017). *Attention Is All You Need*. NeurIPS 2017. arXiv:1706.03762. [Transformer input embeddings and positional encodings].

## 12. Evidential Classification Matrix
| Section / Claim | Evidence Category | Supporting Source | Confidence / Status |
| :--- | :--- | :--- | :--- |
| BPE merge algorithm and its use for subword vocabularies | Established | Sennrich et al. (2016) | High |
| Unigram segmentation and SentencePiece | Established | Kudo (2018); Kudo & Richardson (2018) | High |
| Per-byte measure needed for cross-tokenizer comparison | Established (derivation from definitions) | Section 4.4 | High |
| Cross-language token-count disparity | Well Supported | Petrov et al. (2023); Ahia et al. (2023) | High for reported languages and tokenizers |
| Under-trained tokens are prevalent and cause erratic behaviour | Well Supported | Land & Bartolo (2024) | Moderate-High |
| Byte/patch models match token-based models at scale | Preliminary | Pagnoni et al. (2024); Xue et al. (2022) | Moderate; limited independent replication |
| Tokenizer of any specific closed model | Undisclosed unless developer-documented | Developer documentation | Not inferred |

## 13. Revision History
- **v0.1.0** (2026-10-15): Initial draft. Citations checked against arXiv/Crossref/publisher pages where marked; not independently fact-checked.
