Skip to main content

🔤 LexiByte Engine ("Lexi")

LexiByte is a production-grade, from-scratch implementation of a 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.

✨ Key Features

  • Pure BPE Algorithm: Iteratively merges the most frequent adjacent byte/token pairs to build a compressed vocabulary.
  • 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.
  • Save/Load Functionality: Export learned merges and special tokens to a JSON file, ready to be plugged into custom transformer models.
  • Special Token Support: Safely handles control tokens (e.g., <|endoftext|>).

📚 Documentation

Detailed documentation has been separated into the following guides:

🚀 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)

Running the Test Script (Local Dev)

If you cloned the repo and want to verify the local build:

python test.py

🧠 Inspiration & Context

This project was developed as part of a High-Impact AI/ML Portfolio, heavily inspired by Andrej Karpathy's "Neural Networks: Zero to Hero" series, specifically the lecture on building the GPT Tokenizer.


Release files for lexibyte 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lexibyte 0.1.0
File Size Uploaded
lexibyte-0.1.0.tar.gz 5.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for lexibyte 0.1.0
File Interpreter ABI Platform
lexibyte-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 12.1 kB

Release files / lexibyte-0.1.0.tar.gz

Download URL lexibyte-0.1.0.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
ab15bd9c531bcbe07111b80ade499b36fb5966053f434df2ae2b0af261c8f73c
BLAKE2b-256 checksum
How to use checksums
6a079b88784577980a2eb064c4320c554c24cabd75d369e6a26e1f93f968a8bd
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.1.0-py3-none-any.whl

Download URL lexibyte-0.1.0-py3-none-any.whl
Size 6.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
49263e19afa4a81ead2a9ac80372cd0eb89d148685afba25e429817f9c9957af
BLAKE2b-256 checksum
How to use checksums
c406ed84a814f2c91545bdd08b27bb4ef4097b91b58166ea086a9c767803ff66
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.0

Release history Release notifications | RSS feed

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page