Skip to main content

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

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)

Source distribution for Sujit-Tokenizer 1.0.1
File Size Uploaded
sujit_tokenizer-1.0.1.tar.gz 5.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for Sujit-Tokenizer 1.0.1
File Interpreter ABI Platform
sujit_tokenizer-1.0.1-py3-none-any.whl Python 3 none any Details

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

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

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