🔤 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.2.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.2.0.tar.gz | 6.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| lexibyte-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.6 kB
Release files / lexibyte-0.2.0.tar.gz
| Download URL | lexibyte-0.2.0.tar.gz |
|---|---|
| Size | 6.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
558803eedab36c1e1420c387f7fc028c0bcf6126a29f1cee52d1c919210e80c5
|
|
BLAKE2b-256 checksum How to use checksums |
c79f77e2ba3bea2a3648ab794a7ca54620563e8c29f0fa6767851b40631b4bed
|
| 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.2.0-py3-none-any.whl
| Download URL | lexibyte-0.2.0-py3-none-any.whl |
|---|---|
| Size | 6.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b1f9d087cf999b9bbb91d90beeec1dc219676baf6431bb9269f9a5df843b8647
|
|
BLAKE2b-256 checksum How to use checksums |
6131f5a3dec87b3b9b09f55a4743d3fbd747672eea4c4258a1cad85ab5432075
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.0
|