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.
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.
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.
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"}The SymbolicMorphoEngine strips prefixes/suffixes and approximates the root and pattern of the input word.
The router computes the Scattering Degree S as:
- If
S ≤ threshold→ use the neural model - If
S > threshold→ use the symbolic engine (lexicon lookup or known correction)
The chosen path returns the corrected word, with metadata about the routing decision.
semitic-router/
├── README.md
├── semitic_router/
│ ├── __init__.py
│ ├── router.py ← the SemiticRouter class
│ └── morpho_engine.py ← the SymbolicMorphoEngine class
└── tests/ ← unit tests
| 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. |
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.
- Phase: Experimental / pre-alpha
- API stability: Subject to change
- Tests: Basic unit tests included
MIT — see LICENSE.
- GitHub: @faresrafat3
- Issues / PRs: Welcome — please open an issue first to discuss major changes.
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.