google/sentencepiece

Unsupervised text tokenizer for Neural Network-based text generation.

What it solves

SentencePiece provides a fast, language-independent way to convert raw text into subword units (tokens) for neural network-based text generation systems, such as Large Language Models. It eliminates the need for language-specific pre-processing or pre-tokenizers, which is especially useful for languages without explicit word boundaries like Chinese, Japanese, and Thai.

How it works

It treats input text as a raw sequence of Unicode characters and implements subword algorithms like Byte-Pair-Encoding (BPE) and the unigram language model. To ensure detokenization is lossless and reversible, it replaces whitespaces with a special meta-symbol (). The system is written in optimized C++ for high performance and generates a self-contained .model file containing all vocabulary mapping and normalization rules.

Who it’s for

It is designed for developers and researchers building LLMs or other neural text generation systems that require a fixed vocabulary size prior to training.

Highlights

  • Lossless Detokenization: Treats whitespace as a symbol, making the process of converting tokens back to text a simple string join operation.
  • Language Independent: Trains directly from raw sentences without requiring external pre-tokenizers like MeCab or Moses.
  • Subword Regularization: Supports on-the-fly sampling (BPE-Dropout and Unigram sampling) to make models more resilient to noise and spelling variations.
  • High Performance: Optimized C++ implementation capable of processing approximately 50,000 sentences per second with a small memory footprint.

Related

  • Project
  • Project
  • Project
  • Project
  • Project