SentencePiece is Google's tokenization library that fixes a structural assumption baked into BPE and WordPiece: that whitespace is a special boundary character. SentencePiece treats input as a raw stream of Unicode characters, with no language-specific preprocessing — whitespace is encoded as the visible character ▁ (U+2581) and learned as a regular token.
This sounds like a small detail. It isn't. It means a single tokenizer trained on multilingual data behaves identically for English (where words are space-separated), Chinese/Japanese (where they are not), Korean (where boundaries are mixed), and code (where whitespace carries syntactic meaning).
SentencePiece supports two algorithms: BPE (the bottom-up method we already saw) and Unigram. Unigram works top-down: start with a huge vocabulary and iteratively prune tokens that contribute least to the corpus likelihood until you hit the target size. Llama 1/2 and T5 use SentencePiece + Unigram; Llama 3 switched to byte-level BPE; Gemma 3 uses SentencePiece + Unigram with 262K vocabulary covering 140+ languages.