ZPĚTBACK

09Tokenizace a embeddingyTokenization and embeddings

Jazykový model nečte písmena ani slova jako my. Text si nejdřív rozseká na tokeny a každému přiřadí vektor čísel (embedding), který zachycuje význam. Podobná slova mají podobné vektory — a leží v prostoru blízko sebe. A language model doesn't read letters or words the way we do. It first chops the text into tokens and assigns each a vector of numbers (an embedding) that captures meaning. Similar words have similar vectors — and lie close together in the space.

Co a jak?What & how?

Co to jeWhat it is Ukázka, jak model „vidí" text. Nejdřív ho rozseká na tokeny (kousky slov) a každému přiřadí embedding — sadu čísel zachycující význam. Podobná slova mají podobná čísla, a tak leží na mapě blízko sebe.A demo of how a model “sees” text. First it chops it into tokens (word pieces) and gives each an embedding — a set of numbers that captures meaning. Similar words get similar numbers, so they sit close together on the map.

Co zkusitWhat to try Napiš text a sleduj, jak se rozdělí na tokeny a rozmístí na 2D mapě významů. Pak zkus „počítání s významem" — slavné analogie jako král − muž + žena = královna.Type some text and watch it split into tokens and spread out on a 2D map of meaning. Then try “computing with meaning” — famous analogies like king − man + woman = queen.

Proč je to důležitéWhy it matters Tohle je první krok každého jazykového modelu: převést slova na čísla, se kterými umí počítat. „Mapa významů" je důvod, proč modely chápou, že pes a štěně spolu souvisejí.This is the first step of every language model: turning words into numbers it can compute with. The “map of meaning” is why models understand that dog and puppy are related.

1 · tokenizace — jak se text rozseká na kousky1 · tokenization — how text is chopped into pieces
Co znamenají ta čísla? Pod každým tokenem je jeho ID (např. #22040) — pořadové číslo daného kousku ve slovníku modelu. Model totiž nepracuje s písmeny ani slovy, ale právě s těmito čísly: text → tokeny → ID, a teprve s ID dál počítá. Stejný kousek má vždy stejné ID.

Barvy jen opticky oddělují sousední tokeny. Všimni si, že delší slova se rozpadnou na menší kousky (tzv. subword tokeny) — díky tomu model zvládne i slovo, které nikdy neviděl, poskládáním z částí. V praxi je 1 token ≈ 4 znaky (zhruba ¾ slova).  ID je tu jen ilustrativní, dopočítané z textu tokenu — skutečné modely mají pevný slovník desítek tisíc tokenů.
What do those numbers mean? Under each token is its ID (e.g. #22040) — the index of that piece in the model's vocabulary. The model doesn't work with letters or words, but with these numbers: text → tokens → IDs, and only then does it compute with the IDs. The same piece always has the same ID.

The colors just visually separate neighboring tokens. Notice that longer words break into smaller pieces (so-called subword tokens) — this lets the model handle even a word it has never seen by assembling it from parts. In practice 1 token ≈ 4 characters (roughly ¾ of a word).  The ID here is only illustrative, derived from the token's text — real models have a fixed vocabulary of tens of thousands of tokens.
2 · embeddingy — mapa významů (klikni na slovo)2 · embeddings — a map of meaning (click a word)
Analogie — počítání s významy (klikni a sleduj šipky):Analogies — computing with meaning (click and watch the arrows):
Každý token (slovo) dostane navíc embedding — seznam čísel (vektor), který zachycuje jeho význam. Skutečné modely jich mají stovky až tisíce na jedno slovo; tady je pro názornost promítáme do 2 rozměrů, abychom je viděli jako body na ploše.

Slova, která se v textech objevují v podobných souvislostech, skončí blízko sebe — proto vznikají shluky (zvířata, barvy, doprava…). Vzdálenost mezi body měří podobnost významu a směr nese vztah: posun „muž → žena" je stejný jako „král → královna", takže král − muž + žena dopadne u královny. Vyzkoušej tlačítka výše.
Each token (word) also gets an embedding — a list of numbers (a vector) that captures its meaning. Real models have hundreds to thousands of them per word; here, for clarity, we project them into 2 dimensions so we can see them as points on a plane.

Words that appear in similar contexts end up close together — that's why clusters form (animals, colors, transport…). The distance between points measures similarity of meaning and the direction carries a relationship: the shift "man → woman" is the same as "king → queen", so king − man + woman lands at queen. Try the buttons above.
Jak ta analogie funguje? Embeddingy dovolují se slovy počítat jako s čísly. Klíčové je, že některé směry v prostoru mají stálý význam. Směr „muž → žena" (změna pohlaví) je skoro stejný, ať vyjdeš od kohokoli — od muže, od krále i od prince.

Takže když vezmeš král, odečteš „muž" (zbude „panovník bez pohlaví") a přičteš „žena", posuneš se přesně na ženský protějšek → královna. Stejně to platí pro princ → princezna. A funguje to i jinde: u čísel je „o jedna víc" taky pevný posun, proto dva − jedna + tři = čtyři.

Na mapě: modrá šipka je rozdíl A − B (ten „směr významu"), oranžová je úplně stejný posun přiložený k C — a kam dopadne, tam leží výsledek 🎯. Skutečné modely tohle zvládají v mnoha rozměrech najednou (pohlaví, množné číslo, čas, země↔hlavní město…).
How does the analogy work? Embeddings let you compute with words like numbers. The key is that some directions in the space have a consistent meaning. The direction "man → woman" (a change of gender) is almost the same wherever you start — from man, from king, or from prince.

So if you take king, subtract "man" (leaving "a genderless monarch") and add "woman", you move exactly to the female counterpart → queen. The same holds for prince → princess. And it works elsewhere too: with numbers "one more" is also a fixed shift, which is why two − one + three = four.

On the map: the blue arrow is the difference A − B (the "direction of meaning"), the orange one is the exact same shift applied to C — and where it lands is the result 🎯. Real models do this across many dimensions at once (gender, plural, tense, country↔capital…).
Co je „význam" pro počítačWhat "meaning" is for a computer

Slovo samo o sobě je pro stroj jen řetězec znaků. Embedding ho převede na bod v prostoru (ve skutečnosti o stovkách rozměrů, tady promítnutý do 2D). Model se ho naučí tak, že slova z podobných souvislostí umístí blízko sebe — a vzdálenosti i směry pak nesou význam. A word by itself is just a string of characters to a machine. An embedding turns it into a point in space (actually with hundreds of dimensions, here projected into 2D). The model learns it so that words from similar contexts are placed close together — and distances and directions then carry meaning.

Tokeny, ne slovaTokens, not words

Model pracuje s tokeny — kousky textu (slovo, část slova, znaménko). Díky tomu zvládne i slova, která nikdy neviděl, složením z částí. The model works with tokens — pieces of text (a word, part of a word, a punctuation mark). This lets it handle even words it has never seen by composing them from parts.

Blízkost = podobnostCloseness = similarity

Pes a kočka leží blízko, auto a vlak taky. Vzdálenost mezi vektory měří, jak významově podobná slova jsou. Dog and cat lie close together, so do car and train. The distance between vectors measures how similar in meaning words are.

Směry mají smyslDirections have meaning

Nejde jen o blízkost — i směry něco znamenají. Posun „muž → žena" je stejný jako „král → královna". Proto vyjde král − muž + žena ≈ královna. It's not just about closeness — directions mean something too. The shift "man → woman" is the same as "king → queen". That's why king − man + woman ≈ queen.

Základ dnešních LLMThe foundation of today's LLMs

Každé slovo na vstupu modelu je takový vektor. Celé „porozumění" jazyku stojí na tom, že podobné věci mají podobná čísla. Every word on a model's input is such a vector. All "understanding" of language rests on similar things having similar numbers.