# Is the Arabic that models train on already corrupted? **Audit of 341 public Arabic datasets on Hugging Face — 9 September 2026, corrected 13 September 2026** > **Correction, 13 September 2026.** This write-up said `Yousefmd/arabic_ocr_dataset` stored > its labels in **visual** order and called that the complete `reshape` + `bidi` signature. > That was wrong. Only the shaping step ran there; the words are in logical order and plain > NFKC recovers them. The counts were right, the mechanism inferred from them was not. See > *Correction log* at the end. ## The question The `arabic_reshaper` + `python-bidi` recipe writes presentation-form, visually-ordered Arabic into files. Either half can run without the other, and the detector used here sees only the first: presentation forms in stored text, never word order. It appears in 3,168 indexed Python files, and half of a hand-checked six-project sample was rendering text backwards because of it. If that ever ran upstream of a training corpus, every model trained or evaluated on it learned from text no Arabic reader would accept. Nobody had measured whether it did. ## Method Rows pulled through the Hugging Face **datasets-server** rows API (no full downloads), scanned with the detector from `arabic-lint` 0.5.0. 100 rows per dataset, first `train`/`test` split. Re-runnable: `python3 audit_all.py`. Raw results in `audit_all.json`. ## Result | | | |---|---| | datasets attempted | **341** | | readable through the viewer | **276** | | rows sampled | **26,318** | | text fields scanned | **119,517** | | datasets with any finding | **21** | | datasets with a form in **every** sampled field | **1** | ### One dataset carries presentation forms in every sampled label, and it is an OCR ground-truth set **`Yousefmd/arabic_ocr_dataset`** — every text field stores presentation forms: 3 to 50 per label (median 24), INITIAL, MEDIAL, FINAL and ISOLATED forms together. Verified on **1,000 of 1,000 labels, 100%**, sampled through ten windows spanning the whole 20,000-row split; in the audit's own 100-row scan, 108 of 113 findings are runs of five or more forms (108 reshaped, 5 partial, 0 stray). Every figure here is re-derivable with `python3 verify_yousefmd.py`. **Only the shaping half of the recipe ran.** The words are in logical order, so `unicodedata.normalize("NFKC", stored)` alone recovers the text and no reversal is wanted. Two independent checks against the live rows: - of **5,423** sampled words carrying more than one presentation form, **0** begin with a FINAL form and **0** meaningfully end with an INITIAL form (one does, `الـ20`, and that is a correctly shaped lam before a tatweel, not visual order). A word written in visual order reads FINAL-first from memory, so zero is decisive. - `arabic_reshaper.reshape(NFKC(stored)) == stored` for **1,000 of 1,000** labels. The stored string is exactly `reshape()` output with `get_display()` never applied. ⚠️ The counts above are the corrected ones. A first pass classified a presentation form by testing the Unicode name for `ARABIC LETTER ... FORM`, which **silently drops every lam-alef ligature** (U+FEF5-FEFC are named `ARABIC LIGATURE ...`) — an undercount sitting exactly on the character the visual-order test is most sensitive to. The check now asks arabic-lint's own `is_presentation_form()`, so these numbers cannot drift from what the tool reports. This matters more than its size because the corrupted field is the **label**. A model trained on it learns to emit presentation forms instead of plain letters, so its output will not compare equal to ordinary Arabic even when the recognition is correct. That is the propagation path from a rendering bug into model weights, observed in the wild rather than argued for. ⚠️ **State the scale honestly: 17 downloads, 0 likes, last modified November 2025.** This proves the mechanism reaches training data. It is *not* evidence that widely-used Arabic corpora are affected, and it must not be reported as if it were. ### Everything else was a stray glyph The other 20 datasets with findings had **no reshaped runs at all**. Every finding was a single presentation-form character in otherwise correct text. Most common flagged codepoints: `U+FE91` BEH INITIAL FORM, `U+FEDF` LAM INITIAL FORM, `U+FE9F` JEEM INITIAL FORM, `U+FEEB` HEH INITIAL FORM. ## What the stray glyphs are, and why they still matter An initial form stored in text is unambiguously wrong: correct Arabic stores the base letter and lets the renderer choose the shape. These are copy-paste from PDFs, keyboard and IME artifacts, and OCR output, not evidence of the recipe. **Measured, and it is worse than "different tokens".** On tokenizers without a Unicode normalisation step, a word containing one stray presentation form is not split, it is replaced by the unknown token. Every character of meaning is discarded before the model sees it. One corrupted letter out of four is enough: `بيت` becomes `[UNK]`. | tokenizer | effect of one stray presentation form | |---|---| | `aubmindlab/bert-base-arabertv02` (Arabic-specific) | **6/6 words → `[UNK]`** | | `google-bert/bert-base-multilingual-cased` | **6/6 words → `[UNK]`** | | `xlm-roberta-base` (SentencePiece) | 0/6 — identical tokens, unaffected | | `Qwen/Qwen2.5-0.5B` (byte-level BPE) | word survives, but as entirely different tokens | The irony is that the two Arabic-capable BERTs destroy the word while the multilingual SentencePiece model is immune, because XLM-R normalises and they do not. Re-runnable: `tokenizer_cost.py`, tokenizer files only, no weights. Datasets carrying them include two Arabic **LLM instruction-tuning** sets. ## Limits, stated plainly **65 of 341 datasets could not be read** through the viewer API: 41 server errors, 11 with no dataset viewer, 6 gated, 3 bad gateways. An initial sweep reported 121 unreadable, but **61 of those were 429s caused by my own request rate**; a slower second pass recovered them. > ⚠️ **Reproducing the 276 figure takes BOTH passes.** `audit_all.py` alone returns about 220 readable, because the rate-limited failures are still counted as unreadable at that point. `retry_failed.py` is the second pass and is included here; run it after `audit_all.py`, against the same `audit_all.json`. This file previously described the two-pass method without shipping the second script, which made the headline coverage number un-reproducible from the published code. Flagged by an external reviewer, 2026-10-08. That is not a random 19%: the viewer is most often unavailable on the **largest** corpora, which are exactly the ones that matter most for pretraining. So this audit covers the mid-size and small end of the distribution well and the head of it poorly, and no claim here should be read as covering web-scale corpora. 100 rows per dataset also cannot find a defect confined to a rare subset. ## The finding that came out of the first attempt The first run reported **35.6%** of `synth_shamela_ocr_arabic_books`, 27.4% of `freococo/ocr_arabic_books` and 5.5% of `arabic-turath-ocr` as corrupted. **All false positives, and the bug was in `arabic-lint`.** Arabic Presentation Forms-A is interleaved: the ornate parentheses `﴾ ﴿` enclosing a Quranic quotation sit at U+FD3E/U+FD3F, inside the positional-form range, with honorific ligatures just above. The tool excluded only the word ligatures, so it flagged Quranic punctuation as damage — on Islamic heritage text, a large share of all Arabic corpora. Fixed in **arabic-lint 0.5.0**: the class is derived from the Unicode character name rather than tabulated ranges, so a shaping artefact is exactly a codepoint named `... ISOLATED/INITIAL/MEDIAL/FINAL FORM` and new additions classify themselves. ⚠️ The audit was one command from being published with three named datasets and a headline percentage. What stopped it was reading the flagged characters instead of trusting the count. **A measurement tool pointed at someone else's work has to be checked against text you can read before the number leaves your machine.** --- ## Correction log **2026-09-13 — `Yousefmd/arabic_ocr_dataset` is not stored in visual order.** Originally published here, on the dataset card, in the `arabic-lint` README and in a discussion opened on that repository: the labels had been through `arabic_reshaper.reshape()` **and** `bidi.algorithm.get_display()`, "the recipe's complete signature". Only the first ran. Measured against the live rows on 13 September: plain `unicodedata.normalize("NFKC", stored)` returns `بدأت قراءة الصفحات الأولى على نغمات`, correct readable Arabic in logical order, with no reversal of any kind. Structurally, 0 of 5,423 multi-form words begin with a FINAL form. And `arabic_reshaper.reshape(NFKC(stored))` reproduces the stored string byte for byte in 1,000 of 1,000 labels, which pins down exactly which half ran. **The part that mattered was the advice, not the wording.** The discussion warned that recovery "is not simply NFKC plus reverse" because a lam-alef ligature would come back swapped. That hazard exists only when the surrounding text is in visual order. Here it is not: `ﻻﺑﻌﺪ` becomes `لابعد` and `ﻭﻻﻧﻲ` becomes `ولاني`, both correct. We told a maintainer his problem was harder than it is, in public, on his own repository. Also corrected in the same pass: "23 to 29 presentation forms per label" (real range 3 to 50, median 24), and "fully corrupted" where "carries stored presentation forms in every sampled field" is what was measured. **Cause.** The detector reports stored glyph forms. Word order is a separate property, was never measured, and was assumed because the two calls are almost always copied together. The counts were checked against text that could be read; the diagnosis was not. That is the same lesson as the 35.6% false positive above, one step further along, and this time it was published before it was caught.