huggingface/tokenizers
repository·main·Indexed 27 days ago
https://github.com/huggingface/tokenizersA high-performance library implemented in Rust for training and using state-of-the-art tokenizers in research and production environments. It provides bindings for Python and NodeJS, supporting various models including BPE, WordPiece, and Unigram. The library includes specialized classes like CharBPETokenizer and BertWordPieceTokenizer, and supports free-threaded CPython (3.14t) for concurrent encoding.
What's inside tokenizers
- Hugging Face Tokenizers is a high-performance library designed for both research and production environments. It provides implementations of modern, widely-used tokenizers used in the 🤗 Transformers ecosystem. The library is written in Rust, enabling extremely fast training and tokenization (e.g., processing 1GB of text in less than 20 seconds on a server CPU).
Overview of tokenizers features and bindings
mainThe
tokenizerslibrary provides high-performance implementations of common tokenization algorithms (BPE, WordPiece, Unigram) designed for both research and production.Key Features:
- Extremely fast Rust-based implementation (can tokenize ~1GB of text in <20s on server CPU).
- Supports training new vocabularies.
- Normalization includes alignment tracking to map tokens back to original sentence spans.
- Includes pre-processing capabilities like Truncation, Padding, and special token handling.
Supported Language Bindings:
- Rust (Original implementation)
- Python
- Node.js
- Ruby (via external
tokenizers-rubyrepository)
Identify the `tokenizers-linux-arm-gnueabihf` binary
mainThetokenizers-linux-arm-gnueabihfpackage provides the armv7-unknown-linux-gnueabihf binary for thetokenizerslibrary. Use this specific package when targeting ARMv7 Linux systems with hard float support (gnueabihf).Identify the `tokenizers-win32-arm64-msvc` binary
mainThetokenizers-win32-arm64-msvcpackage provides the aarch64-pc-windows-msvc binary for thetokenizerslibrary. Use this specific package when targeting Windows environments running on ARM64 architecture with the MSVC toolchain.Use `tokenizers-android-arm64` for Android aarch64
mainThetokenizers-android-arm64package provides the aarch64-linux-android binary for thetokenizerslibrary. Use this specific package when targeting Android devices with ARM64 (aarch64) architecture.Identify the `tokenizers-linux-arm64-gnu` binary target
mainThetokenizers-linux-arm64-gnupackage provides the aarch64-unknown-linux-gnu binary for thetokenizerslibrary. Use this specific package when targeting Linux systems running on ARM64 architecture with the GNU C library (glibc).Understand the Tokenization Pipeline
mainWhen calling
Tokenizer.encodeorTokenizer.encode_batch, the input text undergoes a four-step pipeline:- Normalization: Cleaning the raw string (e.g., stripping whitespace, lowercasing).
- Pre-Tokenization: Splitting text into smaller objects (like words) to set an upper bound for final tokens.
- Model: Splitting pre-tokens into sub-tokens and mapping them to vocabulary IDs.
- Post-Processing: Adding special tokens or performing final transformations on the
Encoding.
You can also use
decodeto convert token IDs back into text.Identify `tokenizers-android-arm-eabi` compatibility
mainThetokenizers-android-arm-eabipackage provides the armv7-linux-androideabi binary for thetokenizerslibrary. Use this specific package when targeting Android devices with ARMv7 architecture.Key Features of Tokenizers
mainThe library provides several core capabilities for NLP workflows:
- Vocabulary Training & Tokenization: Train new vocabularies and tokenize text using state-of-the-art algorithms.
- High Performance: Optimized Rust implementation for speed.
- Alignment Tracking: Full support for alignment tracking, allowing you to map any token back to its corresponding part in the original sentence, even after destructive normalization.
- Pre-processing: Built-in support for truncation, padding, and adding special tokens required by specific models.
Understand the Tokenizer pipeline
mainA
Tokenizeroperates as a pipeline that processes raw text into anEncoding. The pipeline consists of four main stages:Normalizer: Normalizes the input text (e.g., applying Unicode normalization likeNFDorNFKC).PreTokenizer: Performs initial splits of the text, such as splitting on whitespace.Model: Performs the actual tokenization logic (e.g.,BPEorWordPiece).PostProcessor: Post-processes theEncodingto add necessary elements like special tokens required by language models.
Identify the `tokenizers-freebsd-x64` binary
mainThetokenizers-freebsd-x64package provides the x86_64-unknown-freebsd binary for thetokenizerslibrary. Use this specific package if you are targeting FreeBSD systems on x86_64 architecture.Identify the `tokenizers-darwin-arm64` binary
mainThetokenizers-darwin-arm64package provides the aarch64-apple-darwin binary for thetokenizerslibrary. Use this specific package when targeting Apple Silicon (M1/M2/M3/etc.) architectures on macOS.