Tokenizers

Fast, production-grade tokenizer implementations for NLP and LLMs, written in Rust

Library
Cargo
v1.0.0-rc.3
11,193 stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
96 /100 Excellent
Development Activity 100
Maintenance 100
Community 84
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
85 /100 Excellent
Architecture 87
Code Quality 88
Innovation 85
Learning Curve 78

Tokenizers is Hugging Face’s Rust implementation of today’s most widely used text tokenization algorithms — BPE, WordPiece, Unigram, and byte-level variants — built for training new vocabularies and encoding text at very high throughput. The core library is written entirely in Rust for speed and memory efficiency, with official bindings for Python, Node.js, and (community-maintained) Ruby, so the same fast tokenizer implementation can be trained and used consistently across a project’s Rust services and Python/JS model pipelines.

It underlies tokenization for the Hugging Face transformers ecosystem and countless independent NLP/LLM projects, handling not just encoding but the surrounding pipeline: normalization, pre-tokenization, truncation/padding, special-token insertion, and alignment tracking back to the original text so token-to-character offsets are always recoverable.

What You Get

  • Rust implementations of BPE, WordPiece, Unigram, and byte-level BPE tokenizer algorithms
  • Vocabulary training from raw text corpora, not just inference on pretrained vocab files
  • Official Python and Node.js bindings (plus a community Ruby binding) sharing the same Rust core
  • Composable pipeline stages: normalizers, pre-tokenizers, models, and post-processors that can be mixed and matched
  • Offset/alignment tracking so every output token maps back to its exact position in the original string
  • Built-in truncation, padding, and special-token handling for feeding models directly

Common Use Cases

  • Tokenizing training and inference text for transformer-based language models at high throughput
  • Training a custom BPE/WordPiece/Unigram vocabulary for a domain-specific or non-English corpus
  • Sharing one tokenizer implementation across a Python training pipeline and a Rust/Node.js production inference service
  • Recovering exact character offsets for named-entity recognition or span-extraction tasks that need token-to-text alignment

Under The Hood

Architecture The crate’s Rust source under tokenizers/src/ is organized around a Tokenizer struct defined in tokenizer/mod.rs (nearly 1,900 lines) that orchestrates a pipeline of normalizers/, pre_tokenizers/, models/ (the actual BPE/WordPiece/Unigram/WordLevel algorithms), and processors/ (post-processing such as adding special tokens), each implemented as a trait so stages are swappable; decoders/ mirrors this for turning token ids back into text. lib.rs re-exports the public surface and wires the crate together, while the bindings/python and bindings/node directories wrap this same core via PyO3/napi so all language bindings share one battle-tested implementation rather than reimplementing tokenization logic per language. Tech Stack Pure Rust (edition 2018) at the core with no heavyweight runtime dependencies, using PyO3 for the Python binding and napi-rs/N-API for the Node.js binding; the crate is published to crates.io as tokenizers and to PyPI as the tokenizers package (via the Python binding), keeping one source of truth. Code Quality Testing is extensive and multi-layered: tests/ includes training.rs, serialization.rs, offsets.rs, unigram.rs, added_tokens.rs, and a documentation.rs test that verifies README examples actually compile and run, plus a common/ shared-fixture module; CI runs a dedicated Rust workflow (badge referenced in the README) on every push. API Design The public API centers on a small number of composable builder types (Tokenizer::new, .with_normalizer, .with_pre_tokenizer, .encode/.encode_batch, .train) that read as a clear declarative pipeline, and the crate ships runnable examples/ (encode_batch.rs, serialization.rs) alongside the documentation tests, keeping the learning curve low despite the algorithmic complexity underneath.

Used by 16 apps in this directory

Python
62%
Apache 2.0

marimo

Data Engineering · Developer Tools

23,309

A reactive Python notebook that eliminates hidden state, runs reproducibly, and deploys as a web app or script — stored as pure Python, built for the AI era.

View details
90
Repo Health
91
Technical
65
Dependency
Built with
Python 62%
TypeScript 37%
Updated 5 days ago
Rust
100%
Other

Meilisearch

Search

59,644

Lightning-fast hybrid search engine with AI-powered semantic and full-text retrieval for modern applications.

View details
90
Repo Health
88
Technical
67
Dependency
Built with
Rust 100%
Updated 6 days ago
Python
95%
MIT

MemPalace

AI Agents · AI Development · AI Memory

59,720

Local-first AI memory with verbatim storage, pluggable backends, and 96.6% retrieval recall on LongMemEval — no API key required.

View details
86
Repo Health
84
Technical
73
Dependency
Built with
Python 95%
Updated 6 days ago
Rust
63%
MIT

PostgresML

AI Development · Databases

6,823

Run ML training and LLM inference natively inside PostgreSQL with GPU acceleration — no data movement required.

View details
51
Repo Health
76
Technical
64
Dependency
Built with
Rust 63%
JavaScript 11%
Updated 1 years ago
Python
57%
Other

Sentry

Analytics · Developer Tools · Monitoring

45,632

Developer-first error tracking and performance monitoring platform with AI-powered root-cause analysis across 20+ languages and frameworks.

View details
95
Repo Health
80
Technical
66
Dependency
Built with
Python 57%
TypeScript 42%
Updated 5 days ago
Python
94%
Apache 2.0

SWIRL

Data Engineering · Databases · Search

3,046

Federated AI search and RAG across 100+ enterprise sources—no data extraction, no vector database required.

View details
61
Repo Health
83
Technical
65
Dependency
Built with
Python 94%
Updated 1 weeks ago
Rust
66%
Apache 2.0

Temps

Analytics · Devops · Monitoring

865

A self-hosted Rust PaaS that replaces Vercel, Sentry, PostHog, Pingdom, Resend, and E2B with one binary — plus 440+ CLI operations agents like Claude Code can drive directly.

View details
81
Repo Health
86
Technical
66
Dependency
Built with
Rust 66%
TypeScript 33%
Updated 6 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers