# Tokenizacja tekstu (BPE, WordPiece, SentencePiece)

EN: **Text tokenisation (BPE, WordPiece, SentencePiece)** · id `tokenization` · aliases: tokenization, tokenisation, tokenizacja, tokenizer, tokenizator, BPE, byte pair encoding, byte-level BPE, WordPiece, SentencePiece, Unigram tokenizer, tiktoken, subword tokenization

Path: [AI Atlas](https://aiatlasgraph.com/llms.txt) › [Język, obraz, audio](https://aiatlasgraph.com/t/modalities.md) › [Język naturalny](https://aiatlasgraph.com/t/nlp.md) › Tokenizacja tekstu (BPE, WordPiece, SentencePiece)

## Description

- PL: Zamiana tekstu na ciąg tokenów — kawałków słów z ustalonego słownika — zanim model go zobaczy. Dominują metody podsłowowe: BPE (także w wersji na bajtach, jak w GPT), WordPiece (BERT) i Unigram w bibliotece SentencePiece (T5). Tokenizacja wpływa na koszt, długość kontekstu i to, jak model radzi sobie z językami innymi niż angielski.
- EN: Turning text into a sequence of tokens — sub-word pieces from a fixed vocabulary — before the model sees it. Sub-word methods dominate: BPE (also byte-level, as in GPT), WordPiece (BERT) and Unigram via SentencePiece (T5). Tokenisation affects cost, context length and how well a model handles non-English languages.

## In one sentence

- PL: To dzielenie tekstu na kawałki, które model potrafi odczytać jako liczby.
- EN: This splits text into pieces that a model can read as numbers.

## Problem it solves

- PL: Dwa równie długie teksty mogą kosztować inaczej i zajmować różną część pamięci rozmowy.
- EN: Two texts of similar length can cost differently and occupy different amounts of conversation space.

## What it does

- PL: Słownik przypisuje numery fragmentom słów; rzadki wyraz może wymagać więcej kawałków niż często spotykany.
- EN: A vocabulary assigns numbers to word fragments; a rare word may need more pieces than a common one.

## Everyday example

- PL: Przed wysłaniem długiego polskiego dokumentu sprawdzasz liczbę kawałków tekstu, żeby zmieścić się w limicie modelu.
- EN: Before sending a long document, you check its piece count to stay within the model's input limit.

## This concerns you if you…

- PL: płacisz za ilość tekstu wysyłanego do modelu
- PL: pracujesz z długimi tekstami lub różnymi językami
- EN: pay for the amount of text sent to a model
- EN: work with long texts or different languages

## Keywords

byte-pair encoding · WordPiece · SentencePiece · Unigram tokenizer · byte-level BPE · special tokens · minbpe

## How it works

- PL: Z korpusu dobiera się słownik oraz reguły scalania lub probabilistycznego podziału fragmentów. Segmentator mapuje tekst na identyfikatory tokenów, uwzględniając normalizację i specjalne znaczniki wymagane przez model.
- EN: A corpus determines a vocabulary and merging or probabilistic segmentation rules. A segmenter maps text to token identifiers, accounting for normalisation and special markers required by the model.

## Limits

- PL: Ten sam tekst może mieć różną liczbę tokenów w różnych słownikach. Normalizacja bywa stratna, a języki słabo reprezentowane mogą wymagać dłuższych sekwencji.
- EN: The same text can have different token counts across vocabularies. Normalisation can be lossy, and underrepresented languages may require longer sequences.

## Key terms

- PL: **BPE**: Budowanie tokenów przez iteracyjne scalanie częstych par jednostek.
- PL: **słownik tokenów**: Zestaw fragmentów i identyfikatorów rozpoznawanych przez tokenizer.
- EN: **BPE**: Building tokens by repeatedly merging frequent unit pairs.
- EN: **token vocabulary**: The fragments and identifiers recognised by a tokenizer.

## Know first

- [Statystyka i niepewność (Statistics and uncertainty)](https://aiatlasgraph.com/t/probability.md)

## Examples

- PL: BPE na bajtach (GPT-2, GPT-4) · WordPiece (BERT) · Unigram + SentencePiece (T5) · tokeny specjalne · trenowanie własnego tokenizera
- EN: byte-level BPE (GPT-2, GPT-4) · WordPiece (BERT) · Unigram + SentencePiece (T5) · special tokens · training your own tokenizer

## Related topics

Untyped, symmetric "see also" links.

- [Przewidywanie następnego tokenu (modele autoregresyjne) (Next-token prediction objective)](https://aiatlasgraph.com/t/nexttoken.md)
- [Szacowanie kosztu na zadanie (tokeny) (Cost-per-task estimation)](https://aiatlasgraph.com/t/costestimation.md)
- [Wielojęzyczność i języki o małych zasobach (Multilingual and low-resource language processing)](https://aiatlasgraph.com/t/multilingualnlp.md)

## Sources

- [Neural Networks: Zero to Hero (course repository)](<https://github.com/karpathy/nn-zero-to-hero>) `karpathy-zero-to-hero` · by Andrej Karpathy
- [Hugging Face LLM Course, chapter 6: the Tokenizers library (BPE, WordPiece, Unigram)](<https://huggingface.co/learn/llm-course/chapter6/5>) `hf-llm-course-tokenizers` · by Hugging Face · sponsored
- [Neural Machine Translation of Rare Words with Subword Units](<https://arxiv.org/abs/1508.07909>) `sennrich-bpe-2016` · by Rico Sennrich, Barry Haddow, Alexandra Birch
- [SentencePiece: A simple and language independent subword tokenizer and detokenizer for Neural Text Processing](<https://arxiv.org/abs/1808.06226>) `sentencepiece-2018` · by Taku Kudo, John Richardson
- [minbpe — minimal byte-level BPE](<https://github.com/karpathy/minbpe>) `karpathy-minbpe` · by Andrej Karpathy

---

AI Atlas revision 122 (2026-10-30) · HTML: https://aiatlasgraph.com/t/tokenization · index: https://aiatlasgraph.com/llms.txt · everything: https://aiatlasgraph.com/llms-full.txt · updated 2026-10-30
