Skip to main content

Arabic Morph Segmenter

A lightweight neural Arabic morphological segmenter based on BiLSTM + CRF for Modern Standard Arabic (MSA) and multiple Arabic dialects.

Python PyTorch License


Overview

Arabic words frequently contain attached conjunctions, prepositions, articles, pronouns, and other clitics.

For example,

وبكتابهم

should be segmented into

وب + كتاب + هم

instead of being treated as a single token.

This project provides a lightweight neural segmenter that predicts the character-level boundaries of:

  • Prefix
  • Stem
  • Suffix

using a BiLSTM-CRF architecture.

The output can be used as a preprocessing step for:

  • POS Tagging
  • Named Entity Recognition (NER)
  • Lemmatization
  • Dependency Parsing
  • Arabic Search
  • Information Retrieval
  • Large Language Models (LLMs)
  • Arabic NLP pipelines

Features

  • Lightweight (~9 MB)
  • Fast inference
  • Character-level neural segmentation
  • BiLSTM + CRF architecture
  • Supports Modern Standard Arabic
  • Supports multiple Arabic dialects
  • Easy Python API
  • Ready for PyPI

Supported Arabic

Current training includes:

  • Modern Standard Arabic (MSA)
  • Iraqi Arabic
  • Syrian Arabic
  • Moroccan Arabic
  • Najdi Arabic
  • Sanaani Arabic
  • Taizi Arabic

The architecture is language-independent and can easily be extended with additional dialects.


Model Architecture

Characters
      │
      ▼
Character Embedding
      │
      ▼
2-layer BiLSTM
      │
      ▼
Linear Layer
      │
      ▼
CRF
      │
      ▼
P / S / X

Where

  • P = Prefix
  • S = Stem
  • X = Suffix

Installation

pip install arabic-morph-segmenter

Quick Start

from arabic_morph_segmenter import ArabicMorphSegmenter

segmenter = ArabicMorphSegmenter()

result = segmenter.segment_word("وبكتابهم")

print(result)

Output

{
    "word": "وبكتابهم",
    "prefix": "وب",
    "stem": "كتاب",
    "suffix": "هم",
    "segmented": "وب + كتاب + هم"
}

Sentence Segmentation

sentence = "والناس تفرقت من المدرسة"

for token in segmenter.segment_sentence(sentence):
    print(token["segmented"])

Output

وال + ناس
تفرق + ت
من
ال + مدرس + ة

More Examples

Word Segmentation
وندد و + ندد
الفلسطينيون ال + فلسطين + يون
وبكتابهم وب + كتاب + هم
فبالمدرسة فبال + مدرس + ة
والناس وال + ناس
تفرقت تفرق + ت
وسيكتبون وسي + كتب + ون
وللمهندسين ولل + مهندس + ين

Evaluation

Evaluation on the held-out validation set:

Metric Score
Character Accuracy 99.04%
Word Exact Accuracy 96.90%

Training Data

The model was trained on a combination of:

  • Modern Standard Arabic morphological corpus
  • Iraqi dialect
  • Syrian dialect
  • Moroccan dialect
  • Najdi dialect
  • Sanaani dialect
  • Taizi dialect

using character-level prefix/stem/suffix annotations.


Project Structure

arabic_morph_segmenter/
│
├── assets/
│   └── arabic_morph_segmenter_bilstm_crf.pt
│
├── segmenter.py
├── __init__.py
│
examples/
│   └── demo.py
│
README.md
LICENSE

Citation

If you use this project in your research, please cite:

@software{alshargi2026arabicsegmenter,
  author = {Faisal Alshargi},
  title = {Arabic Morph Segmenter},
  year = {2026},
  url = {https://github.com/alshargi/arabic-morph-segmenter}
}

Roadmap

  • ONNX export
  • Hugging Face model
  • REST API
  • CLI interface
  • Transformer version
  • Additional Arabic dialects
  • Confidence scores
  • Batch inference

License

MIT License.


Author

Dr. Faisal Alshargi

AI • NLP • Arabic Language Technologies • Large Language Models

GitHub: https://github.com/alshargi


⭐ If you find this project useful, please consider giving it a star.

Metadata

Release files for arabic-morph-segmenter 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 arabic-morph-segmenter 0.1.0
File Size Uploaded Provenance
arabic_morph_segmenter-0.1.0.tar.gz 8.9 MB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for arabic-morph-segmenter 0.1.0
File Interpreter ABI Platform
arabic_morph_segmenter-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 17.8 MB

Release files / arabic_morph_segmenter-0.1.0.tar.gz

Download URL arabic_morph_segmenter-0.1.0.tar.gz
Size 8.9 MB
Tags Source
SHA-256 checksum
How to use checksums
5725124f894fd87a556cdb2d13aaca025c01311d80f09259b3c68d96a2bb1d80
BLAKE2b-256 checksum
How to use checksums
bd85f5115396ad25d66bfea0359408cff15a265344f474fea431c0313163611d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

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

Download URL arabic_morph_segmenter-0.1.0-py3-none-any.whl
Size 8.9 MB
Tags Python 3
SHA-256 checksum
How to use checksums
a80932983cb228b1875c803a01b5574e6cebc6f78dc1816c75a9b9e6fcccae7d
BLAKE2b-256 checksum
How to use checksums
f44a7a9c3237c4e1ad2899d3c67352fc4a775bb1a7e1d92d456b5c49469b3b97
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Security for arabic-morph-segmenter 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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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