APflow. All field notesكل الملاحظات
Book a callاحجز مكالمة
OCR · Field noteقراءة آلية · ملاحظة ميدانية

Why Arabic OCR still fails, and how we fixed itلماذا يفشل التعرّف الضوئي على العربية، وكيف عالجناه

Ligatures, diacritics, and mixed-direction invoices break almost every off-the-shelf engine. Here is exactly where they fail, and the three changes that took us from 71% to 99.2% on real Gulf tax invoices.الحروف المتصلة والتشكيل والفواتير ثنائية الاتجاه تُربك معظم المحركات الجاهزة. هنا بالضبط أين تفشل، والتغييرات الثلاثة التي نقلتنا من ٧١٪ إلى ٩٩٫٢٪ على فواتير ضريبية خليجية حقيقية.

APflow
Field notes · May 2026 · 6 min readملاحظات ميدانية · مايو ٢٠٢٦ · ٦ دقائق
ق
figure: the Arabic glyph "qāf" at scaleشكل: حرف "القاف" بحجم كبير

A typical Saudi tax invoice is a small act of typographic chaos. The vendor name runs right-to-left in Arabic, the line items are bilingual, the VAT number marches left-to-right, and the totals sit in a table whose columns flip direction halfway down the page. To a human, it is obvious. To most OCR engines, it is noise.الفاتورة الضريبية السعودية النموذجية فوضى طباعية صغيرة. اسم المورّد يجري من اليمين إلى اليسار بالعربية، والبنود ثنائية اللغة، ورقم ضريبة القيمة المضافة يسير من اليسار إلى اليمين، والمجاميع في جدول تنقلب اتجاهات أعمدته في منتصف الصفحة. بالنسبة للإنسان، الأمر بديهي. أما لمعظم محركات القراءة الآلية، فهو ضجيج.

We learned this the hard way. Our first pipeline used a best-in-class commercial OCR API, the kind that tops English benchmarks. On clean English receipts it was flawless. On the first batch of real Gulf invoices, it returned 71% field-level accuracy. For accounts payable, 71% is not "mostly working." It means roughly one in three invoices needs a human to re-key it, which defeats the entire point.تعلّمنا هذا بالطريقة الصعبة. اعتمد خط معالجتنا الأول على واجهة قراءة آلية تجارية من الطراز الأول، من النوع الذي يتصدّر اختبارات الإنجليزية. على الإيصالات الإنجليزية النظيفة كان أداؤه مثاليًا. وعلى أول دفعة من الفواتير الخليجية الحقيقية، أعاد دقة ٧١٪ على مستوى الحقول. وبالنسبة للحسابات الدائنة، ٧١٪ ليست «تعمل في الغالب»: تعني أن واحدة من كل ثلاث فواتير تقريبًا تحتاج إلى إعادة إدخال يدوي، وهذا يُلغي الغرض كله.

The problem isn't the alphabetالمشكلة ليست في الأبجدية

It is tempting to assume Arabic is hard because it has different letters. It doesn't work that way. The alphabet is small, 28 base letters. The difficulty is that each letter changes shape depending on where it sits in a word: isolated, initial, medial, or final. The same letter can have four visual forms, and adjacent letters fuse into ligatures that share strokes.من المغري الافتراض أن العربية صعبة لأن حروفها مختلفة، لكن الأمر ليس كذلك. الأبجدية صغيرة، ٢٨ حرفًا أساسيًا. الصعوبة أن كل حرف يغيّر شكله حسب موضعه في الكلمة: منفصلًا، أو في البداية، أو في الوسط، أو في النهاية. للحرف الواحد أربعة أشكال بصرية، والحروف المتجاورة تندمج في روابط تتشارك الخطوط.

Stack diacritics (the small marks that disambiguate vowels and doubling) on top, and a single rendered "word" may be one connected blob of ink that the model has to segment from context, not from whitespace. English OCR leans heavily on the gaps between characters. Arabic gives it far fewer.أضِف فوقها التشكيل (العلامات الصغيرة التي تميّز الحركات والتشديد)، وقد تصبح «الكلمة» الواحدة كتلة حبر متصلة على النموذج أن يجزّئها من السياق، لا من الفراغات. تعتمد القراءة الآلية للإنجليزية بشدة على الفجوات بين الحروف، والعربية تمنحها فجوات أقل بكثير.

RAW OCR OUTPUTمخرجات القراءة الخام
ف ا ت و رة ضر يب ية
SAR l38,5?5.OO
Letters split apart · "1" read as "l" · "7" read as "?"حروف متفرّقة · «١» قُرئت «l» · «٧» قُرئت «؟»
APFLOW OUTPUTمخرجات APflow
فاتورة ضريبية
SAR 138,575.00
Reassembled word · numerals validated against the table totalكلمة معاد تجميعها · أرقام مُتحقَّق منها مقابل مجموع الجدول
The same invoice line, before and after. "فاتورة ضريبية" means tax invoice.البند نفسه من الفاتورة، قبل المعالجة وبعدها.

Mixed direction is where it really breaksالاتجاه المختلط هو ما يكسرها فعلًا

Even when the characters are read correctly, layout destroys them. Invoices are tables, and Gulf invoices are bidirectional tables. A description column flows right-to-left, the quantity and price columns are left-to-right, and the engine has to decide reading order before it can decide what belongs to which row.حتى حين تُقرأ الحروف بشكل صحيح، يدمّرها التخطيط. الفواتير جداول، والفواتير الخليجية جداول ثنائية الاتجاه. عمود الوصف يجري من اليمين إلى اليسار، وعمودا الكمية والسعر من اليسار إلى اليمين، وعلى المحرّك أن يحدّد ترتيب القراءة قبل أن يحدّد ما الذي ينتمي إلى أي صف.

Get the order wrong and you don't get garbage, you get something worse: a plausible number attached to the wrong field. A unit price lands in the VAT cell. The total parses fine, reconciles to nothing, and a clerk spends ten minutes finding a digit that the machine quietly misplaced.أخطئ في الترتيب فلن تحصل على هراء، بل على ما هو أسوأ: رقم معقول مُلصق بالحقل الخطأ. سعر الوحدة يحطّ في خانة الضريبة، فيُحلَّل المجموع سليمًا، ولا يطابق شيئًا، ويقضي الموظّف عشر دقائق بحثًا عن رقم نقله الجهاز بهدوء إلى مكان خاطئ.

A wrong number that looks right is more expensive than no number at all.الرقم الخاطئ الذي يبدو صحيحًا أغلى من غياب الرقم تمامًا.

What we actually changedما الذي غيّرناه فعليًا

The fix wasn't one model. It was three layers, each catching what the one before it missed.لم يكن الحل نموذجًا واحدًا، بل ثلاث طبقات، تلتقط كلٌّ منها ما فات التي قبلها.

  1. 1 Layout-aware segmentation first.
    Before any text recognition, a vision model maps the page into directional regions (which blocks are right-to-left, which cells are numeric), so reading order is decided from geometry, not guessed from characters.
    تجزئة واعية بالتخطيط أولًا.
    قبل أي تعرّف على النص، يرسم نموذج رؤية خريطة للصفحة إلى مناطق حسب الاتجاه (أي الكتل من اليمين إلى اليسار، وأي الخانات رقمية)، فيُحدَّد ترتيب القراءة من الهندسة، لا تخمينًا من الحروف.
  2. 2 An Arabic-first recognizer.
    We fine-tuned an open model on hundreds of thousands of real invoice crops: ligatures, stamps, low-contrast scans, handwriting in the margins, instead of the clean synthetic text most engines train on.
    محرّك تعرّف عربي أولًا.
    صقلنا نموذجًا مفتوحًا على مئات الآلاف من قصاصات الفواتير الحقيقية: روابط، وأختام، ومسوحات منخفضة التباين، وكتابات يدوية في الهوامش، بدلًا من النصوص الاصطناعية النظيفة التي تتدرّب عليها معظم المحركات.
  3. 3 Numbers must reconcile.
    Every extracted figure is checked against the invoice's own arithmetic: line items must sum to the subtotal, VAT must equal 15%, the total must add up. A number that doesn't balance is flagged, never silently posted.
    الأرقام يجب أن تتطابق.
    يُراجَع كل رقم مستخرَج مقابل حساب الفاتورة نفسها: يجب أن تجمع البنود إلى المجموع الفرعي، وأن تساوي الضريبة ١٥٪، وأن يتوازن الإجمالي. وأي رقم لا يتوازن يُعلَّم، ولا يُرحَّل بصمت أبدًا.
99.2%
field-level accuracy, up from 71%دقة على مستوى الحقول، ارتفاعًا من ٧١٪
Measured on 4,000 held-out Gulf tax invoices across 60 vendors, including scanned, photographed, and exported PDFs.مقيسة على ٤٠٠٠ فاتورة ضريبية خليجية محجوزة للاختبار من ٦٠ مورّدًا، تشمل المسوحات والصور وملفات PDF المُصدَّرة.

Why on-prem made it harder, and betterلماذا جعلها التشغيل المحلي أصعب، وأفضل

We could have shipped a cloud API and called it done. But finance teams in the region cannot send vendor data to a third party, so the whole pipeline had to run on the customer's own GPUs. That constraint forced a discipline that ended up improving accuracy: every model had to be small enough to run locally, which meant we couldn't hide behind a giant general-purpose system. Each layer had to earn its place.كان بإمكاننا إطلاق واجهة سحابية واعتبار الأمر منتهيًا، لكن فرق المالية في المنطقة لا تستطيع إرسال بيانات الموردين إلى طرف ثالث، فكان على خط المعالجة بأكمله أن يعمل على معالِجات العميل نفسه. وذلك القيد فرض انضباطًا انتهى إلى تحسين الدقة: كان على كل نموذج أن يكون صغيرًا بما يكفي للعمل محليًا، ما يعني أننا لم نستطع الاختباء خلف نظام عملاق عام الغرض. كان على كل طبقة أن تستحق مكانها.

The result is a pipeline that reads an Arabic invoice as well as a careful human clerk, fast enough to keep up with a full mailroom, and it never leaves the building.والنتيجة خط معالجة يقرأ الفاتورة العربية بدقة موظّف بشري متأنٍّ، وبسرعة تواكب غرفة بريد كاملة، ولا يغادر المبنى أبدًا.

The short versionباختصار

Arabic OCR fails on layout and direction long before it fails on letters. Fix the reading order, train on the messy real thing, and make the numbers prove themselves, and the alphabet stops being the hard part.تفشل القراءة الآلية للعربية في التخطيط والاتجاه قبل أن تفشل في الحروف بوقت طويل. صحّح ترتيب القراءة، ودرّب على الواقع الفوضوي، واجعل الأرقام تُثبت نفسها، عندها تتوقف الأبجدية عن أن تكون الجزء الصعب.

See it read your invoices, on your servers.شاهدوه يقرأ فواتيركم، على خوادمكم.

Bring three of your worst invoices. We'll run them live on a scoping call.أحضروا ثلاثًا من أصعب فواتيركم. سنشغّلها مباشرةً في مكالمة تقييم.

Book a scoping call →احجز مكالمة تقييم ←
KEEP READINGتابع القراءة