LexiMini: A fast, minimal Rust-based BPE tokenizer for Python
Project description
LexiMini
A fast, minimal Byte-Pair Encoding (BPE) tokenizer implemented in Rust, with seamless Python bindings via PyO3.
Highlights
- ⚡ Fast — Core tokenization logic written in Rust for maximum performance
- ** Minimal** — Clean, readable implementation — great for learning how BPE works
- ** Pythonic** — Drop-in Python module via native PyO3 extensions
- ** Trainable** — Train your own BPE vocabulary directly from Python
Quick Start
pip install leximini
import leximini
# Initialize
tokenizer = leximini.get_encoding("gpt2")
# Train on your corpus
tokenizer.train("The quick brown fox jumps over the lazy dog.", 270)
# Encode & Decode
tokens = tokenizer.encode("The quick brown fox")
decoded = tokenizer.decode(tokens)
assert decoded == "The quick brown fox"
Requirements
- Python 3.8+
- Rust and Cargo (for building from source): Install from rustup.rs
Building from Source
From the leximini directory (the folder containing pyproject.toml and Cargo.toml):
pip install maturin
pip install .
Behind the scenes, the maturin build system will automatically invoke Cargo to compile the Rust extension and install it into your active Python environment.
API Reference
Initialization
import leximini
tokenizer = leximini.get_encoding("gpt2")
Training (BPE)
Train byte-pair merges from a sample corpus. Target vocabulary size must be ≥ 256 (base ASCII bytes).
tokenizer.train("your training text here", 270) # 256 base + 14 merges
Encoding & Decoding
tokens = tokenizer.encode("The quick brown fox") # → list of ints
text = tokenizer.decode(tokens) # → original string
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file leximini-0.1.1.tar.gz.
File metadata
- Download URL: leximini-0.1.1.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.12.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8de55f8cc225b295abb178979923a0e4b6d54f86060fb3d0b8edf955c931e620
|
|
| MD5 |
5843af615913409b95cc232a56671795
|
|
| BLAKE2b-256 |
f648171efb1f25ecaf0ae0feb95b31dbcd93609ba2db32970f64d79d3519ceb9
|
File details
Details for the file leximini-0.1.1-cp38-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: leximini-0.1.1-cp38-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 206.2 kB
- Tags: CPython 3.8+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.12.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5ee41f252d1e65beb81b3f558de192ed96c2b17e28650376839899733a56651b
|
|
| MD5 |
0bb6d1a1544be747945a0acddbbe9277
|
|
| BLAKE2b-256 |
1261ad138637c24dfce48e027f9f5dcba2bf55b4e9090c684141f718d11830da
|