Mahesh's Byte Pair Encoding tokenizer
Project description
Mahesh-BPE
Mahesh-BPE is a simple and educational implementation of the Byte Pair Encoding (BPE) algorithm, designed for NLP tokenization and vocabulary compression. It is useful for developers, students, and AI/ML enthusiasts who want to understand and experiment with BPE-based tokenization.
🚀 Features
- ✅ Pure Python implementation of BPE
- ✂️ Tokenizes text into characters and merges frequent pairs
- ⚙️ Customizable number of merge operations (
epochs) - 📚 Returns vocabulary and encoded text
- 🧼 Handles multiple spaces and unknown tokens
📦 Installation
pip install mahesh-bpe
Or, if you're installing it locally:
pip install .
🔧 Usage
from mahesh_bpe import BPE
bpe = BPE(epoch=1000)
text = "This is the sample text. This text is a sample. sa"
bpe.train(text)
print("Vocabulary:", bpe.vocab)
print("Encoded:", bpe.encode("the"))
🧠 How It Works
- Tokenization: Splits input into characters and space-preserved tokens.
- Pair Counting: Finds most frequent adjacent token pairs.
- Merging: Merges those pairs iteratively.
- Vocabulary Building: Updates internal vocabulary.
- Encoding: Applies learned merges to new text.
⚙️ Parameters
| Parameter | Description | Default |
|---|---|---|
epoch |
Number of merge iterations | 50 |
📄 License
This project is licensed under the MIT License.
👥 Authors
- Durja LLC
- Manoj Nayak
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 mahesh_bpe-0.1.0.tar.gz.
File metadata
- Download URL: mahesh_bpe-0.1.0.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee4f87b29ff05b6db95e0c8346bdfd7ea78f50687061b56fc6f9e8cf525f4041
|
|
| MD5 |
4a82b8857005fe63d54b1b98cb2d6ede
|
|
| BLAKE2b-256 |
1caf4e9b3799efe8c290d0016bc08ca49c838c7cf949d73383420310fcad791a
|
File details
Details for the file mahesh_bpe-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mahesh_bpe-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
854e351a4727e790a5397267a6c729ca7097c47a1f101b683bfbc843c6c6cf9b
|
|
| MD5 |
f9afb5a09e565716511ea671360db5b0
|
|
| BLAKE2b-256 |
ab151eafaa749adb89f9adee3e432150f59fd5baf16382954a90c920b15e997d
|