Sujit-Tokenizer
A custom Byte-Level BPE (Byte Pair Encoding) Tokenizer implemented from scratch in Python.
Features
- Byte-level tokenization
- Custom BPE training
- Text encoding and decoding
- Save and load tokenizer models
- UTF-8 support
- Lightweight and dependency-free
Installation
Clone Repository
git clone https://github.com/iamsspm07/Sujit-Tokenizer.git
cd Sujit-Tokenizer
Install Package
pip install -e .
Project Structure
Sujit-Tokenizer/
│
├── Sujit_Tokenizer/
│ ├── __init__.py
│ └── tokenizer.py
│
├── corpus.txt
├── train_and_test.py
│
├── README.md
├── setup.py
├── pyproject.toml
└── LICENSE
Quick Start
Import Tokenizer
from Sujit_Tokenizer import CustomByteLevelBPETokenizer
Train Tokenizer
corpus = [
"Transformers are amazing.",
"Machine Learning is powerful.",
"Python is widely used in AI."
]
tokenizer = CustomByteLevelBPETokenizer(
vocab_size=1000
)
tokenizer.train(corpus)
Save Model
tokenizer.save_model(
"tokenizer.model"
)
Load Model
tokenizer = CustomByteLevelBPETokenizer()
tokenizer.load_model(
"tokenizer.model"
)
Encode Text
encoded = tokenizer.encode(
"Transformers use attention."
)
print(encoded)
Example Output:
[2, 451, 723, 812, 3]
Decode Text
decoded = tokenizer.decode(
encoded
)
print(decoded)
Output:
Transformers use attention.
Training Workflow
Corpus
↓
Byte Conversion
↓
Pair Frequency Counting
↓
BPE Merging
↓
Vocabulary Construction
↓
Tokenizer Model
Special Tokens
| Token | ID |
|---|---|
| 0 | |
| 1 | |
| 2 | |
| 3 |
Example
from Sujit_Tokenizer import CustomByteLevelBPETokenizer
tokenizer = CustomByteLevelBPETokenizer(
vocab_size=1000
)
corpus = [
"Artificial Intelligence",
"Machine Learning",
"Deep Learning"
]
tokenizer.train(corpus)
tokenizer.save_model(
"tokenizer.model"
)
tokenizer.load_model(
"tokenizer.model"
)
text = "Machine Learning"
encoded = tokenizer.encode(text)
print(encoded)
decoded = tokenizer.decode(encoded)
print(decoded)
Use Cases
- NLP experiments
- Tokenization research
- Educational projects
- Understanding BPE internals
- Building custom language models
- Learning tokenizer architecture
Future Enhancements
- Faster BPE training
- WordPiece tokenizer
- SentencePiece tokenizer
- Parallel processing
- Vocabulary statistics
- Token frequency analysis
- Hugging Face compatibility
Author
Sujit Maity, Praveen Kumar Kannan
License
MIT License
Metadata
Release files for Sujit-Tokenizer 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sujit_tokenizer-1.0.1.tar.gz | 5.0 kB | Without provenance | Details for sujit_tokenizer-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sujit_tokenizer-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for sujit_tokenizer-1.0.1-py3-none-any.whl |
Total release size: 9.7 kB
Release files / sujit_tokenizer-1.0.1.tar.gz
| Download URL | sujit_tokenizer-1.0.1.tar.gz |
|---|---|
| Size | 5.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b9ca342f3eae744181585ab6a7073115d49f6abed8edbde9ddf101872bb482b5
|
|
BLAKE2b-256 checksum How to use checksums |
f9630f699c789b036ffbd88769ae39eb8eaa9ed97873579019422792afb0b012
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Release files / sujit_tokenizer-1.0.1-py3-none-any.whl
| Download URL | sujit_tokenizer-1.0.1-py3-none-any.whl |
|---|---|
| Size | 4.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f1a952f62001046ca7627aa6b8f5191a2ffe1dbe5e0392ad0dd49c0e4d7b815e
|
|
BLAKE2b-256 checksum How to use checksums |
d669aa468f3aaa496f619cbae7fe3d3706cc00dcfaac3e4b2d3baedfa0c45dab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Security for Sujit-Tokenizer 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.