Afrisyl-tokenizer
A syllable-aware tokenizer for African languages
Afrisyl-tokenizer is built to fix a core problem: BPE and WordPiece tokenizers break African languages. Instead of splitting "ndinoda" into ['n', 'din', 'oda'], we respect the natural CV syllable structure of Bantu languages.
Built as part of MSc research by Nkosilomusa Ncube, Alumni WeThinkCode.
Key Features
- Syllable-based: Uses CV, CVC, V patterns found in Shona, Ndebele, Zulu, Swahili, etc
- Low fertility: 30% fewer tokens than BPE on Shona text
- Fast: Pure Python + regex. No dependencies for inference
- HF Compatible: Drop-in replacement for HuggingFace tokenizers
- Trainable: Train your own tokenizer on any African language corpus
- Small vocab: 8k-16k vocab covers 95%+ of tokens
- Open Source: MIT Licensed for research and social impact
Installation
pip install afrisyl-tokenizer
Quick Usage
1. Load Tokenizer
from afrisyl_tokenizer import AfriSylTokenizer
# Load default shona vocab from package
tok = AfriSylTokenizer(language="shona")
# Or load custom vocab
# tok = AfriSylTokenizer(vocab_path="path/to/ndebele_vocab.json")
# Batch processing
texts = ["ndinoda rubatsiro", "mhoroi shamwari"]
batch = tok.batch_encode(
texts,
add_bos=True,
add_eos=True,
max_len=32,
padding=True
)
# batch['input_ids'] -> [[1, 12, 45, ...], [1, 8, 22, ...]]
# batch['attention_mask'] -> [[1, 1, 1, ...], [1, 1, 1, ...]]
decoded_batch = tok.batch_decode(batch["input_ids"])
print(decoded_batch)
# ['ndinodarubatsiro', 'mhoroshamwari']
Metadata
Release files for afrisyl-tokenizer 0.1.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 |
|---|---|---|---|---|
| afrisyl_tokenizer-0.1.1.tar.gz | 14.1 kB | Without provenance | Details for afrisyl_tokenizer-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| afrisyl_tokenizer-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for afrisyl_tokenizer-0.1.1-py3-none-any.whl |
Total release size: 28.7 kB
Release files / afrisyl_tokenizer-0.1.1.tar.gz
| Download URL | afrisyl_tokenizer-0.1.1.tar.gz |
|---|---|
| Size | 14.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e14e2121aad73c0a697ba3e077c14a3bd8fe6f0e9eef0f5af6c7e337e3824dd4
|
|
BLAKE2b-256 checksum How to use checksums |
7d0de711c51a3fd4a1f05763e27607240d82ad155e7c1114c80060ddcb37df55
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.0
|
Release files / afrisyl_tokenizer-0.1.1-py3-none-any.whl
| Download URL | afrisyl_tokenizer-0.1.1-py3-none-any.whl |
|---|---|
| Size | 14.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d6e21401f0d4d9205e8efb982d514a2602852dc77f8e205f0c35454f8f73fd8c
|
|
BLAKE2b-256 checksum How to use checksums |
18cf98247fd7e0e29645ca82dcffbe0cd875dbd4d915632bb1a0834fae5f7eca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.0
|
Security for afrisyl-tokenizer 0.1.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.