A modern UTF-8 native tokenizer engine for Python designed for speed, scalability, and simplicity. Built with C++ for performance and exposed through an easy-to-use Python API.
Integrate blazing fast tokenization into your workflow with zero friction.
Available on PyPI. Install via pip in your virtual environment.
pip install py_tokenizer_ansh
pip install py_tokenizer_ansh
from py_tokenizer import engine
engine(
"/storage/emulated/0/Download/big.txt", # Input file
4, # Threads
True, # Normalize
False, # Verbose
100, # Chunk size
8, # Epochs
True # Generate vocab
)
This command instantly generates the tokenizer vocabulary (vocabulary.json) and related output files utilizing native multi-threading.
Every feature is designed to maximize throughput and minimize developer friction.
Correctly handles multilingual Unicode text without breaking UTF-8 characters.
Uses multiple CPU threads for faster vocabulary generation and preprocessing.
Core engine written in modern C++ for maximum speed and memory efficiency.
Simple Python interface with minimal setup. Integrates directly into your workflow.
Automatically creates optimized vocabulary.json from vast text datasets.
Engineered to work flawlessly with both small experiments and very large text files.
Easy to integrate into Natural Language Processing (NLP) and Artificial Intelligence projects.
Designed to be inherently simple and efficient, without unnecessary bloat or dependencies.
py_tokenizer is built from the ground up to eliminate bottlenecks during text ingestion and vocabulary generation, processing gigabytes of text effortlessly.
Under the hood, memory allocation and string manipulation are handled by highly optimized C++ routines bypassing Python's GIL.
Chunk-based reading allows multiple CPU threads to process segments of large files concurrently.
Streams text efficiently instead of loading massive datasets into RAM entirely, avoiding out-of-memory errors.
Directly interprets UTF-8 byte streams, ensuring perfect token boundaries across all languages.
Choose the interface that fits your project's complexity.
The simplest interface for quickly processing text files. Suitable for beginners and small-scale projects where advanced tuning is unnecessary.
from py_tokenizer import basic_engine
basic_engine("data.txt")
The advanced processing engine for professional use. Unlocks the full power of the C++ backend.
See how we stack up against standard implementations.
| Feature | py_tokenizer | Typical Tokenizers |
|---|---|---|
| UTF-8 Native | Sometimes | |
| Multi-threading | Limited | |
| Modern C++ Backend | Rare | |
| Python API | ||
| Vocabulary Generation | Limited | |
| Large File Support | Depends | |
| Easy Integration |
Versatile enough to handle modern AI development workloads.
Dive deep into the architecture, view advanced API examples, and learn how to customize tokenization for your specific language models. Full documentation is currently being compiled and will be available shortly on ReadTheDocs.
py_tokenizer is an open-source project maintained by Ansh Raj. We welcome contributions, feature requests, and bug reports on GitHub.
Source code, issues, and contribution guidelines.
Explore more tools and projects by Ansh Raj.