Log inStart free
LESSON 8.04 · 6 STAGES · 3 CONTROLS · 3 CHECKSPRO · PREVIEW

Unigram tokenization and SentencePiece

Watch a Unigram tokenizer learn its pieces, then cut text along the likeliest path.


Pro lesson. Stage 1 is free to watch. Pro opens all 6 stages, 3 controls and 3 checks, in this lesson and every other.

Go Pro · $8.25/mo
EXPLAINER · 8.04 · TOKENIZER BAY17 CHARACTERS · 3 ▁ MARKS
01
Stage 1 of 6 · Spaces become ▁
SentencePiece reads the raw text as one stream. A ▁ marks the start and each space.
Explain it simply

You see the text as a row of character cells. SentencePiece puts a space mark at the start and in place of each space. The training words above it have their marks too. Now a space is a character like any other, so decoding gives back the exact text.

The text "She drinks milk." becomes 17 characters. Each space and the start get a ▁.

textpiece probabilitylosschosen pathfallback byte
training text · 26 wordstext, normalizedvocabulary · not trained yet▁The▁cat▁sat▁on▁the×3▁mat.×6▁She×2▁likes▁warm▁milk×2▁We▁drink×2▁at▁home▁He▁will▁some▁tea▁reads▁text▁I▁split▁bread▁in▁two▁She▁drinks▁milk."She drinks milk." → "▁She▁drinks▁milk."training text · 26 wordstext, normalizedvocabulary · not trained yet▁The▁cat▁sat▁on▁the×3▁mat.×6▁She×2▁likes▁warm▁milk×2▁We▁drink×2▁at▁home▁He▁will▁some▁tea▁reads▁text▁I▁split▁bread▁in▁two▁She▁drinks▁milk."She drinks milk." → "▁She▁drinks▁milk."
Toy: the 8.C1 training text, 26 words; pieces of at most 8 characters
STAGE 1 / 6
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
x=▁+text, each space→▁\sy{x}{data}{x} = \text{▁} + \text{text, each space} \to \text{▁}
She drinks milk.→17 characters\text{She drinks milk.} \to 17 \text{ characters}

A ▁ starts the text and replaces each space.

Common mix-ups

MYTHUnigram builds its vocabulary by adding pieces, as BPE does.

The fix, and 1 more mix-up with the diagram to show them, come with Pro.

Predict, then reveal
3 CHECKS · PRO
Q01With 10 learned pieces, how does the word text split?

Make your guess, then test it in the diagram. All 3 checks come with Pro.

PRO LESSON · YOU WATCHED STAGE 1 OF 6
Unlock the full explainer
  • 5 more stages and 3 live controls
  • 2 mix-up cards and 3 predict-then-reveal checks
  • Watch it as a narrated video, in three voices
  • Every Pro lesson and capstone · 656 in total

$99 a year, or $15 a month. Cancel any time.