sentencepiece  by google

Unsupervised text tokenizer for neural network generation

Created 9 years ago
11,955 stars

Top 4.4% on SourcePulse

GitHubView on GitHub
Project Summary

Summary SentencePiece addresses unsupervised text tokenization for neural network-based text generation, particularly LLMs, by providing a fixed-vocabulary tokenizer/detokenizer. It operates directly on raw Unicode text, eliminating language-specific pre-processing and enabling end-to-end, language-independent pipelines.

How It Works The library implements subword unit algorithms like BPE and unigram LM, training directly from raw sentences. Whitespace is preserved as a meta-symbol (, U+2581), ensuring lossless, reversible tokenization and language-independent detokenization. This data-driven approach is effective for languages lacking explicit word boundaries. Subword regularization and BPE-dropout enhance model robustness by virtually augmenting training data through segmentation sampling.

Quick Start & Requirements Install via pip install sentencepiece. Primary interface is Python, with extensive documentation available for API, training, and configuration. Docker deployment is also supported.

Highlighted Details

  • Lossless Tokenization: Preserves whitespace via for perfect text reconstruction.
  • Language Independence: Trains on raw text, ideal for diverse languages without explicit word boundaries.
  • Robustness Features: Subword regularization and BPE-dropout improve model resilience.
  • Performance: Optimized C++ core offers high throughput (~50k sentences/sec) and low memory (~6MB). Self-contained .model files ensure cross-environment consistency.
  • Benchmarking: Outperforms alternatives like Hugging Face Fast tokenizers, especially multi-threaded, though Python GIL limits scaling.

Maintenance & Community The README does not specify community channels, contributors, sponsorships, or a roadmap. It is noted as "not an official Google product."

Licensing & Compatibility Licensed under the Apache 2.0 License, which is permissive for commercial use and integration into closed-source projects.

Limitations & Caveats Python GIL can bottleneck parallel processing scaling during result serialization. As it's not an official Google product, long-term support considerations apply.

Health Check
Last Commit

1 week ago

Responsiveness

Inactive

Pull Requests (30d)
8
Issues (30d)
2
Star History
68 stars in the last 30 days

Explore Similar Projects

Starred by Jeremy Howard Jeremy Howard(Cofounder of fast.ai), Chip Huyen Chip Huyen(Author of "AI Engineering", "Designing Machine Learning Systems"), and
2 more.

tokenmonster by alasdairforsythe

0%
626
Subword tokenizer and vocabulary trainer for multiple languages
Created 3 years ago
Updated 1 day ago
Feedback? Help us improve.