🔤 LexiByte Engine ("Lexi")
LexiByte is a production-grade, algorithmically optimized Byte-Pair Encoding (BPE) tokenizer, inspired by the architecture used in modern Large Language Models (LLMs) like GPT-2, GPT-4, and Llama.
Built entirely in Python, LexiByte bridges the gap between raw text and Neural Networks by safely compressing UTF-8 byte streams into integer token sequences.
✨ Production-Grade Features
- Sennrich Frequency Optimization: Escapes the $O(N^2)$ training bottleneck by compressing the corpus into a frequency dictionary. It trains on millions of words in seconds by mathematically weighting unique pairs.
- Inference Memoization Cache: Bypasses BPE loops during inference by caching tokenized sequences, delivering $O(1)$ constant time lookups for previously seen words.
- Regex Pre-Splitting Guardrails: Implements GPT-2/GPT-4 style regex boundaries to prevent unnatural merges (e.g., merging punctuation with words, or trailing spaces with letters).
- UTF-8 Byte Level Base: Starts with a base vocabulary of 256 standard UTF-8 bytes, meaning it can theoretically encode any string (including emojis and non-English scripts) without out-of-vocabulary (OOV) errors.
- Special Token Support: Safely handles control tokens (e.g.,
<|endoftext|>).
📚 Documentation
Detailed documentation has been separated into the following guides:
- Architecture & Internal Mechanics - Understand how BPE works, why regex guardrails matter, and view visual pipeline diagrams.
- Training & Inference Deep Dive -
A concrete, step-by-step look at how the
mergesandvocabmaps are built and how production optimization works. - Usage Guide - Step-by-step instructions on training, encoding, decoding, and saving your tokenizer.
- Developer & Publishing Guide - Instructions for maintainers on how to build and publish the package to PyPI.
🚀 Quick Start
Installation (For Users)
You can install LexiByte directly from PyPI using pip.
pip install lexibyte
(If you are developing locally from the source repository, run pip install -r requirements.min.txt instead).
Basic Example
from lexibyte import LexiByteTokenizer
# Initialize tokenizer
tokenizer = LexiByteTokenizer()
# Sample corpus
text = "hello world! 👋 This is the LexiByte engine."
# Train the tokenizer to reach a vocabulary of 276 (256 base bytes + 20 learned merges)
tokenizer.train(text, vocab_size=276, verbose=True)
# Encode text to token IDs
encoded = tokenizer.encode("hello world!")
print("Encoded:", encoded)
# Decode token IDs back to text
decoded = tokenizer.decode(encoded)
print("Decoded:", decoded)
🧠 Context
This project was developed as an advanced Systems Engineering project to bridge the gap between educational tokenizers and scalable production logic.
Release files for lexibyte 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| lexibyte-0.3.0.tar.gz | 6.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| lexibyte-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.7 kB
Release files / lexibyte-0.3.0.tar.gz
| Download URL | lexibyte-0.3.0.tar.gz |
|---|---|
| Size | 6.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2cc651f003bbab3cd90a0ac3070ef6fab5c1d38fe3e21cc7de3bbceddb61aba6
|
|
BLAKE2b-256 checksum How to use checksums |
457de3bbff8d4f2f64c7a114e8136a5756d788c9e0053cfbc5e253eff187f9bb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.0
|
Release files / lexibyte-0.3.0-py3-none-any.whl
| Download URL | lexibyte-0.3.0-py3-none-any.whl |
|---|---|
| Size | 6.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9d305f32edd33752612af78863932ebee567d45fc2b8ab3e155ae558aeedad6c
|
|
BLAKE2b-256 checksum How to use checksums |
bd9134d537119636bf84b69f2742ede601ba83c56f68ef48083ccc41ebaa18ab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.0
|