Rishe (ریشه): fast Persian text processing for Python, built in Rust
pip install rishe gives you Persian normalization, tokenization, sentence
splitting, lemmatization, ezafe detection and informal → formal conversion
from one Rust core: no models to download, prebuilt wheels for Linux, macOS
and Windows. The core is also available as a Rust crate.
- Normalization is ~70× faster than Hazm and Shekar; tokenization is on par with them. See docs/BENCHMARKS.md for the full numbers, including where Rishe loses.
Pipeline.pipe()processes batches in parallel (rayon) with the GIL released.
Status: alpha (0.1). Rishe is a fast preprocessing layer, not a replacement for Hazm or Shekar: there is no POS tagging, NER, parsing, spell checking or embeddings.
Install
or, from Rust (Cargo.toml): rishe = "0.1"
Quick start
=
=
# ['آن', 'دارد', 'تو', 'خانه', 'کتاب', 'میخواند', '،', 'چیست', '؟']
# ['آن', 'داشت', 'تو', 'خانه', 'کتاب', 'خواند', '،', 'چیست', '؟']
# 'آن دارد تو خانه کتاب میخواند، چیست؟'
, ,
# ['سلام', '،', 'دنیا', '!']
# 'رفت' (past-stem lemmas, UD style)
# parallel batch -> list[ProcessedDoc]
use Pipeline;
let pipe = create; // unify digits, strip diacritics, fix ZWNJ
let doc = pipe.process;
println!;
Known limitations
Pipeline.__call__also rewrites colloquial words to formal ones, sodoc.tokenscan differ from the surface text. Useword_tokenizefor plain tokenization.- Informal → formal conversion is lexicon- and rule-based. Common forms
(
اون,خونه,داره,چیه,میخوام) work; many suffixed or rarer forms (خونهام,کتابه) are left unchanged. - Lemmas follow the Universal Dependencies convention (verbs lemmatize to the past stem). Accuracy on UD is ~0.90 (Seraji) and ~0.88 (PerDT).
- Ezafe detection is rule-based and has not been evaluated.
Building from source
scripts/extract_lexicons.py regenerates data/*.tsv from Hazm's data
files; build.rs compiles them into FSTs.
License
Dual-licensed under Apache-2.0 or MIT, at your option. The bundled lexicons are derived from Hazm data (MIT); see NOTICE.md.