docs: NLP-3.5 Hardening Sprint — Complete audit reports (6 docs) - hardening-final-report.md: Full sprint summary (9/9 tasks done) - analyze-stress-test.md: 50-2000 chars, all pass - nlp-performance-breakdown.md: AraSpell ~700ms/word bottleneck - suggestion-priority-audit.md: grammar(3)>punc(2)>spell(1)>auto(0) - overlap-resolution-report.md: 4/4 overlap tests clean - text-processing-strategy.md: Skip AraSpell for >300 chars 500 chars: TIMEOUT→28s | Overlaps: 1→0 | API: backward compatible
e763809 NLP-3.5 — Text Processing Strategy
Problem
AraSpell processes text word-by-word with beam search decoding. Each word takes ~700ms. This means:
| Text Size | Words | AraSpell Time | Feasible? |
|---|---|---|---|
| 50 chars | 7 | 4.8s | ✅ |
| 100 chars | 14 | 9.2s | ✅ |
| 250 chars | 35 | 26.0s | ⚠️ Slow |
| 500 chars | 70 | ~49s (est.) | ❌ Too slow |
| 1000 chars | 140 | ~98s (est.) | ❌ Timeout risk |
| 5000 chars | 700 | ~490s (est.) | ❌ Impossible |
Solution: Adaptive Processing
Short Text (0–300 chars)
Full pipeline:
AraSpell → Grammar → Punctuation
All three models run. Maximum expected latency: ~40s.
Medium Text (300–1000 chars)
Skip AraSpell:
Grammar → Punctuation
Grammar and Punctuation handle the text. Expected latency: ~28s.
Large Text (1000+ chars)
Skip AraSpell:
Grammar → Punctuation
Same strategy as medium. Expected latency: ~30-34s.
Implementation
# In /api/analyze
text_len = len(current_text)
run_spelling = text_len <= 300
if not run_spelling:
logger.info(f"Text length {text_len} > 300 — skipping AraSpell")
Rationale
- Grammar catches most errors that AraSpell would find in long texts
- Punctuation is independent of spelling
- Users get fast feedback on long texts instead of timeouts
- Short texts still get full spelling correction
Results
| Text Size | Before | After |
|---|---|---|
| 500 chars | >180s TIMEOUT | 28.2s ✅ |
| 1000 chars | Would timeout | 28.1s ✅ |
| 2000 chars | Would timeout | 33.8s ✅ |