Skip to main content

Lightweight Arabic morphological prefix-stem-suffix segmenter using BiLSTM-CRF.

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

arabic_morph_segmenter-0.1.0.tar.gz (8.9 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

arabic_morph_segmenter-0.1.0-py3-none-any.whl (8.9 MB view details)

Uploaded Python 3

File details

Details for the file arabic_morph_segmenter-0.1.0.tar.gz.

File metadata

  • Download URL: arabic_morph_segmenter-0.1.0.tar.gz
  • Upload date:
  • Size: 8.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for arabic_morph_segmenter-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5725124f894fd87a556cdb2d13aaca025c01311d80f09259b3c68d96a2bb1d80
MD5 88d68efd91fadf2e1a6b958bd1e16559
BLAKE2b-256 bd85f5115396ad25d66bfea0359408cff15a265344f474fea431c0313163611d

See more details on using hashes here.

File details

Details for the file arabic_morph_segmenter-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for arabic_morph_segmenter-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a80932983cb228b1875c803a01b5574e6cebc6f78dc1816c75a9b9e6fcccae7d
MD5 90c8e0308b93b8b3c03fcdff2529025f
BLAKE2b-256 f44a7a9c3237c4e1ad2899d3c67352fc4a775bb1a7e1d92d456b5c49469b3b97

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page