← all repositories
google/sentencepiece

The tokenizer that treats whitespace as just another character

A C++ tokenizer that trains directly on raw text, no language-specific preprocessing required.

12k stars C++ Data Tooling
sentencepiece
Not currently ranked — collecting fresh signals.
star history

What it does

SentencePiece is an unsupervised text tokenizer and detokenizer designed for neural text generation systems with fixed vocabulary sizes. It trains directly from raw sentences—no pre-tokenization step needed—and implements both byte-pair encoding (BPE) and unigram language model segmentation. The project provides C++ and Python APIs, with the README claiming segmentation speed around 50k sentences/sec and a ~6MB memory footprint.

The interesting bit

The clever trick is treating whitespace as a basic symbol rather than a special delimiter. SentencePiece escapes spaces with a visible meta symbol (U+2581), making tokenization losslessly reversible. This means you can detokenize without language-specific rules—a useful property for languages like Chinese or Japanese where word boundaries aren’t marked by spaces, and for any pipeline where you want to avoid the usual pre/post-processing spaghetti.

Key highlights

  • Trains from raw text; no pre-segmentation required (unlike subword-nmt)
  • Supports BPE, unigram, character, and word-level segmentation
  • Subword regularization and BPE-dropout for on-the-fly data augmentation during NMT training
  • Direct vocabulary ID generation—maps tokens to integer sequences internally
  • NFKC-based Unicode normalization with customizable rules
  • Self-contained: same model file guarantees identical tokenization/detokenization behavior

Caveats

  • README notes this is not an official Google product
  • The comparison table shows WordPiece uses a “slightly different” BPE variant; the implications of this difference aren’t elaborated
  • Performance claims (50k sentences/sec, 6MB footprint) lack context on hardware or text length

Verdict

Worth a look if you’re building multilingual NLP pipelines or want to eliminate language-specific tokenization preprocessing. Skip it if you’re already happy with Hugging Face tokenizers or don’t need the reversible detokenization guarantee.

Frequently asked

What is google/sentencepiece?
A C++ tokenizer that trains directly on raw text, no language-specific preprocessing required.
Is sentencepiece open source?
Yes — google/sentencepiece is open source, released under the Apache-2.0 license.
What language is sentencepiece written in?
google/sentencepiece is primarily written in C++.
How popular is sentencepiece?
google/sentencepiece has 12k stars on GitHub.
Where can I find sentencepiece?
google/sentencepiece is on GitHub at https://github.com/google/sentencepiece.

heatdrop uses Google Analytics to see which pages get read — nothing else. Your call. How we handle data.