Spaces:
Sleeping

youssefreda9 commited on
Commit
7e24e70
·
1 Parent(s): 9be89fb

fix(critical): stop spelling from corrupting correct words + fix pronoun agreement + reject hallucinations

Browse files

3 critical fixes:

1. IV PROTECTION: When both original AND correction are in-vocabulary (valid
Arabic words), ONLY accept the change if it's a known orthographic fix
(hamza whitelist or ه→ة). This blocks وكان→وكأن type corruption where
the model changes one correct word to a completely different correct word.

2. PRONOUN EXCLUSION: fix_subject_verb_agreement now excludes pronouns
(أنا, أنت, هو, etc.) from triggering plural verb agreement. Previously
it incorrectly changed أنا ذهبت → أنا ذهبتوا.

3. HALLUCINATION FILTER: Grammar diffs with Jaccard char similarity <0.3
are rejected (e.g. جالس→جاكسون). Prevents model hallucinations from
reaching the user.

Also adds [SPELLING] Accepted/Rejected debug logging for production tracing.

59/59 tests passing

2 files changed +96 -20
Files changed (2)
src/app.py+57-5
src/nlp/grammar/grammar_rules.py+39-15