Skip to main content

Bayan — morphological tokenizer (مُبَيِّن)

Bayan is Ruh's morphological tokenizer: Arabic words are analysed into (root, pattern) pairs instead of BPE subword fragments. English words are bridged through a concept map to shared roots.

from bayan import BayanTokenizer

tok = BayanTokenizer()
tok.tokenize("الكتاب")
# [{'surface': 'الكتاب', 'root': 'كتب', 'root_id': ..., 'pattern': 'NOUN', 'pattern_id': ...}]

tok.roots("العلم نور")     # ['علم', 'نور']
tok.patterns("العلم نور")  # ['NOUN', 'NOUN']
tok.fertility("العلم نور") # 1.0 — one morphological token per word, by construction

"He created man. He taught him al-Bayan (clear expression)." — Quran 55:3-4

Why

Subword tokenizers (BPE/WordPiece) shred Arabic morphology: one root scatters across dozens of unrelated fragments. Bayan keeps the root — the unit Arabic grammar has used for 1,400+ years — so models see كتب in كتاب, كاتب, مكتبة as the same root, not three coincidences.

Install

pip install bayan-tokenizer

Zero dependencies. Pure standard library — no torch, no numpy, no downloads. Works on Python 3.9+.

API

Method Returns
tokenize(text) list of {surface, root, root_id, pattern, pattern_id} — one per word
roots(text) resolved linguistic roots (stopwords and <ENG:…> placeholders excluded)
patterns(text) morphological pattern name per word
fertility(text) tokens-per-word (1.0 by construction; reported for honest BPE comparison)
vocab_size n_roots × n_patterns
supported() True when the tables/lexicon path loaded

Stopwords yield root == "" and pattern "STOPWORD".

Honest limits

  • The bundled analyzer is rule-based (tables + lexicon). It has not been benchmarked against CAMeL Tools or Farasa — do not claim SOTA.
  • Unknown English words surface as <ENG:bucket> placeholders, never as invented roots.
  • BayanTokenizer.with_model(path) is an explicit stub and raises NotAvailableError: model-backed Bayan is not implemented in this release.

Development

The package vendors the tokenizer from the Mizan monorepo (ruh_model/tokenizer/ + backend/qca/roots.py). After changing the upstream sources, re-vendor and rebuild:

python packages/bayan/scripts/sync_vendor.py
cd packages/bayan && python -m build && twine check dist/*

See ../../docs/BAYAN_RELEASE.md for the full release checklist.

License

MIT — see LICENSE.

Metadata

Release files for bayan-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 bayan-tokenizer 0.1.0
File Size Uploaded
bayan_tokenizer-0.1.0.tar.gz 30.1 kB Details

Built distribution (wheel)

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

Total release size: 61.2 kB

Release files / bayan_tokenizer-0.1.0.tar.gz

Download URL bayan_tokenizer-0.1.0.tar.gz
Size 30.1 kB
Tags Source
SHA-256 checksum
How to use checksums
1cbe5e8fda31734defa76db0381f5b094b3324c394e639486b3944298327df8f
BLAKE2b-256 checksum
How to use checksums
21db71c7d49ceb93dc41345c052385e9f167c6fd1e7007c67a1e98e68bd2aad3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / bayan_tokenizer-0.1.0-py3-none-any.whl

Download URL bayan_tokenizer-0.1.0-py3-none-any.whl
Size 31.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
618b52df11d5d469c4339634dd87e53e4d527e91d7adb172bc4bb9e84f65d65f
BLAKE2b-256 checksum
How to use checksums
524c2ee11d2818d37474db11208c6daa6290fdf75f8a37c2631b49ebc5441a6b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.1.0 This release

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