Skip to main content

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.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 afrisyl-tokenizer 0.1.0
File Size Uploaded Provenance Actions
afrisyl_tokenizer-0.1.0.tar.gz 14.1 kB Without provenance Details for afrisyl_tokenizer-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 28.7 kB

Release files / afrisyl_tokenizer-0.1.0.tar.gz

Download URL afrisyl_tokenizer-0.1.0.tar.gz
Size 14.1 kB
Tags Source
SHA-256 checksum
How to use checksums
6811cc4da39434ee07d09276ac7b4190154434a96d3b019d44990faa5411527a
BLAKE2b-256 checksum
How to use checksums
cfa3c7ae06f10141a0b256810ca2e0b309032a859a90d6a811cf4a9852d03879
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.0-py3-none-any.whl

Download URL afrisyl_tokenizer-0.1.0-py3-none-any.whl
Size 14.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0c1f922de8416f65d37672a30a8cbb6ad65cb0e0f597229ba1e0961c0175ece2
BLAKE2b-256 checksum
How to use checksums
51e332e245be64f4343c180ec5837810280c852e4a97a338ac65a54904c9cf59
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.0

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.

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