Merge punctuation_rules V1+V2: V2 threshold+fallback, V1 softened exclamation guard for short texts
e100026 | # Ezz Phase Report 🚀 | |
| **To:** The Team | |
| **Subject:** Major Pipeline Overhaul, New Safety Guards, & Benchmark Explosion | |
| Here is a full breakdown of every local edit and fix we applied to the codebase that hasn't been uploaded yet, the exact problems they solve, and our incredible new benchmark results. | |
| --- | |
| ## 1. Punctuation Hallucinations on Short Phrases | |
| * **The Source Problem:** The Punctuation model was overly aggressive. It would blindly append terminal punctuation (periods, question marks) to the end of very short phrases, titles, and especially named entities (like names of people or cities). | |
| * **Sample Input:** `الخطة السنوية للشركة` (3 words) | |
| * **Sample Output (Bug):** `الخطة السنوية للشركة.` *(Wrongly added a period)* | |
| * **The Solution:** We implemented a strict **TerminalPunctuationGuard** in `src/nlp/punctuation/punctuation_rules.py`. By enforcing a hard limit of `_full_word_count < 5`, any text shorter than 5 words is strictly protected from having terminal punctuation appended. This completely saved the Entities dataset! | |
| ## 2. Plural Marker Destruction in Jazm Contexts | |
| * **The Source Problem:** In Arabic, plural verbs end in `وا`. However, the Grammar model's rule for dropping weak letters in Jazm contexts (like `يخشى` → `يخشَ`) was accidentally matching the `ا` in `وا` and aggressively truncating plural markers. | |
| * **Sample Input:** `لم يفعلون` | |
| * **Sample Output (Bug):** `لم يفعلوَ` *(Destroyed the plural)* | |
| * **The Solution:** Updated `src/nlp/grammar/grammar_rules.py` to explicitly protect the `وا` suffix (`if not word.endswith('وا')`), ensuring plural verbs safely bypass the singular truncation rule. **Result:** `لم يفعلوا` is now perfectly preserved. | |
| ## 3. Misspelled Alif Maqsura in Jazm Contexts | |
| * **The Source Problem:** Many users mistakenly type a `ي` (Yaa) instead of `ى` (Alif Maqsura) at the end of verbs (typing `يسعي` instead of `يسعى`). When this typo entered a Jazm context (`لم`), the grammar rule saw the `ي`, truncated it, and wrongly applied a Kasra (`ِ`) instead of a Fatha (`َ`). | |
| * **Sample Input:** `لم يسعي` | |
| * **Sample Output (Bug):** `لم يسعِ` | |
| * **The Solution:** We built a dynamic stem whitelist directly into the Jazm rules (`fatha_stems = {'يسع', 'يخش', 'ينس'...}`). Now, when the rule detects a known Alif Maqsura verb masquerading with a Yaa, it correctly forces a Fatha: **`لم يسعَ`**. | |
| ## 4. Singular Nasb Contexts Missing Fatha | |
| * **The Source Problem:** Singular verbs ending in weak letters (`و`, `ي`) were not receiving their grammatically required explicit Fatha in Nasb contexts (`أن`, `لن`). | |
| * **Sample Input:** `لن يدعو` | |
| * **Sample Output (Bug):** `لن يدعو` | |
| * **The Solution:** Added missing Nasb rules to proactively append the Fatha (`َ`) to verbs ending in `و` and `ي`. **Result:** `لن يدعوَ`. | |
| --- | |
| ## 5. Removing the Obsolete IVtoOOV Filter | |
| * **The Source Problem:** The pipeline previously had a rigid `IVtoOOV` (In-Vocabulary to Out-Of-Vocabulary) filter that heavily penalized structural grammar changes. Because of this, massive amounts of completely valid grammar fixes were being thrown away as False Negatives, blocking the Grammar model from doing its job. | |
| * **The Solution:** We removed the obsolete `IVtoOOV` filter from the pipeline. This successfully unblocked the Grammar model, allowing valid structural changes to pass through, which directly doubled the Grammar dataset's recall! | |
| ## 6. Dual & Plural Grammar Agreements | |
| * **The Source Problem:** The grammar rules lacked support for noun-adjective and demonstrative pronoun agreements for dual and plural forms. | |
| * **The Solution:** Added missing demonstrative (`هذان/هاتان`) and noun-adjective dual/plural agreement rules to `grammar_rules.py`, and explicitly added bypass rules in `app.py` so these corrections wouldn't be erroneously blocked by spelling. | |
| ## 7. Pipeline Filter Reordering (Jaccard) | |
| * **The Source Problem:** Valid grammar bypass rules were being evaluated *after* the strict Jaccard distance filter, meaning heavy structural changes were getting rejected before they could even be authorized by the bypass rules. | |
| * **The Solution:** Reordered the `Jaccard` filter in `app.py` to correctly run *after* evaluating grammar bypass rules, ensuring authorized grammar corrections are properly verified. | |
| ## 8. Conditional Sentences Overcorrection | |
| * **The Source Problem:** The grammar rule for conditional sentences was overcorrecting common words like `إن` (if) and `من` (who) when they were followed by non-verbs, incorrectly forcing verbs into Jazm. | |
| * **The Solution:** Prevented the conditional sentences rule from triggering by strictly requiring that the subsequent word must be a verb. | |
| --- | |
| ## 📈 Benchmark Achievements | |
| Thanks to these highly targeted fixes, the Phase 10 benchmark results skyrocketed. We obliterated False Positives (down by 41!). | |
| | Metric | Previous Run | **Current Run** | Difference | | |
| |---|---|---|---| | |
| | **Overall Pass Rate** | 56.2% | **74.38%** | 🚀 **+18.18%** | | |
| | **Entities Pass Rate** | 13.3% | **63.33%** | 🟢 **+50.0%** | | |
| | **Grammar Pass Rate** | 57.8% | **91.11%** | 🟢 **+33.3%** | | |
| | **True Positives** | 95 | **112** | 🟢 **+17** | | |
| | **False Positives** | 79 | **38** | 📉 **-41** *(Massive drop!)* | | |
| --- | |
| ## 🚨 The Next Target: The "StageLocker" Bug | |
| While we hit ~75%, the **Collision Dataset** is still suffering (only 32% pass rate). | |
| **The Bug:** The pipeline utilizes a `StageLocker` inside `app.py`. When the Spelling model fixes a misspelled word, the StageLocker "locks" that word to protect it. However, if that exact word (or the context immediately around it) has a **Grammar error**, the Grammar model is completely blinded and blocked from touching it. | |
| **Next Steps:** We must relax the StageLocker boundaries to allow the Grammar model to safely interact with words previously modified by Spelling! | |