Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🔀 Semitic Router — Hybrid Neural/Symbolic Correction for Semitic Languages

A routing module that uses the Scattering Degree (from the Scattering Law) to decide whether to send a Semitic word to a neural model or a symbolic morphological engine for correction.


🎯 Why?

In Semitic languages (Arabic, Hebrew, Amharic), root radicals can be scattered across a word by inflectional patterns. As the scatter grows, neural language models become less reliable at identifying morphological boundaries (see the Scattering Law repo for the empirical research).

Semitic Router addresses this by:

  • Computing the Scattering Degree (S) of an input word.
  • Routing the word to a neural model when S is low (within the model's reliable range).
  • Routing the word to a symbolic morphological engine when S exceeds a threshold (default: 3.7) — the "Blind Zone".

This hybrid approach combines the strengths of both paradigms.


🛠️ Installation

git clone https://github.com/faresrafat3/semitic-router.git
cd semitic-router
pip install -e .  # (if a setup.py/pyproject.toml is added later)

For now, you can use the package directly by adding the repo root to your PYTHONPATH.


🚀 Quick Start

from semitic_router import SemiticRouter
from semitic_router.morpho_engine import SymbolicMorphoEngine

# Initialize with any neural model that has .correct() or .predict()
symbolic = SymbolicMorphoEngine()
router = SemiticRouter(
    neural_model=my_neural_model,
    symbolic_model=symbolic,
    threshold=3.7,
)

word = "بالمستشفيات"  # scatter > 3.7 → symbolic path
corrected, metadata = router.correct(word)
print(corrected)  # → corrected form
print(metadata)   # → {"scatter": ..., "threshold": ..., "path": "symbolic"}

# Inspect routing decision without correcting
analysis = router.analyze_routing(word)
# {"word": "...", "scatter": ..., "threshold": ..., "decision": "symbolic"|"neural"}

📐 How It Works

Step 1 — Morphological Segmentation

The SymbolicMorphoEngine strips prefixes/suffixes and approximates the root and pattern of the input word.

Step 2 — Scattering Degree Calculation

The router computes the Scattering Degree S as:

$$S = (\text{span of root radicals in stem}) - (\text{number of root radicals})$$

Step 3 — Routing Decision

  • If S ≤ threshold → use the neural model
  • If S > threshold → use the symbolic engine (lexicon lookup or known correction)

Step 4 — Correction

The chosen path returns the corrected word, with metadata about the routing decision.


📁 Repository Structure

semitic-router/
├── README.md
├── semitic_router/
│   ├── __init__.py
│   ├── router.py            ← the SemiticRouter class
│   └── morpho_engine.py     ← the SymbolicMorphoEngine class
└── tests/                   ← unit tests

⚙️ Configuration

Parameter Default Description
neural_model (required) Any object exposing .correct(word) or .predict(word).
symbolic_model SymbolicMorphoEngine() The fallback symbolic engine. Override with a custom one if needed.
threshold 3.7 Scattering Degree above which routing goes symbolic. Adjust based on your validation data.
lexicon_path None Optional path to a newline-delimited lexicon file used by the symbolic engine.

🔬 Research Background

This module is a direct application of the empirical observations in:

  • semitic-scattering-law — Exploratory research on the linear decay of neural model performance as root scatter increases in Semitic morphology.

The 3.7 threshold is an empirical observation from that research, not a universal constant. You should re-calibrate it for your own dataset and language.


📊 Status

  • Phase: Experimental / pre-alpha
  • API stability: Subject to change
  • Tests: Basic unit tests included

📜 License

MIT — see LICENSE.


📫 Contact & Contributions

  • GitHub: @faresrafat3
  • Issues / PRs: Welcome — please open an issue first to discuss major changes.

🙏 Acknowledgments

Inspired by classical Semitic morphology work (McCarthy, Prince, Wright) and modern hybrid NLP architectures. The routing concept is an application of the Scattering Law empirical findings.

About

Hybrid neural/symbolic router that uses the Scattering Degree to route Semitic words between a neural model and a symbolic morphological engine.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages