liveBook · Manning

Byte pair encoding

As explained in Hugging Face in Action

Byte-pair encoding is a subword tokenization algorithm that iteratively merges frequent adjacent units into a vocabulary of subword tokens.

Byte-pair encoding (BPE) is a subword tokenization technique that represents text with reusable pieces rather than requiring every complete word to appear in the vocabulary. It supports broad vocabularies while handling unfamiliar words, languages, and word forms more flexibly. section 5.2.1 section 7.1

BPE is useful because it:

  • Reduces the out-of-vocabulary problem by splitting unfamiliar words into recognizable subunits. section 5.2.1
  • Preserves more internal word information than word-level tokenization, helping with rare words, misspellings, morphology, and compound words. section 5.2.1
  • Provides the token representation used by transformer-based models such as BERT and GPT, including GPT-3.5. section 5.2.1 section 7.1

Tokenizing words into subwords

The word “exhilarating” is shown as four subword tokens: “ex”, “h”, “ilar”, and “ating”. The word “unhappiness” is shown as three tokens, illustrating how one word can be represented through smaller reusable pieces. section 5.2.1 section 7.1

Figure 5.8 Example of subword-level tokenization. The single word "exhilarating" is tokenized into four tokens.
A diagram of a word

Description automatically generated with medium confidence

View the subword-tokenization figure for the “exhilarating” example. section 5.2.1

How Hugging Face in Action covers it

How deep it goes
Defines subword tokenization and illustrates outputs, but stops short of explaining merge mechanics or implementation steps.
Examples
Uses “exhilarating” and “unhappiness” to demonstrate subword token sequences.
What you can do after
Evaluate why modern language models use subword tokens for rare, unfamiliar, and morphologically varied words.
How it connects
Contrasts with word-level and character-level tokenization and connects to out-of-vocabulary handling, transformers, and language models.

Also explained in

Compare how 11 books explain byte pair encoding →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Hugging Face in Action. The section links point to the parts of the book it draws on.