Ope0 commited on
Commit
5247d07
·
verified ·
1 Parent(s): c8f557b

Upload folder using huggingface_hub

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. README.md +227 -0
  2. vision-gap.zip +3 -0
  3. vision-gap/.flake8 +9 -0
  4. vision-gap/README.md +301 -0
  5. vision-gap/build_dataset.py +401 -0
  6. vision-gap/data/images/C_name_Nprefix_1200.png +3 -0
  7. vision-gap/data/images/C_name_Nprefix_15000.png +3 -0
  8. vision-gap/data/images/C_name_Nprefix_2500.png +3 -0
  9. vision-gap/data/images/C_name_Nprefix_500.png +3 -0
  10. vision-gap/data/images/C_name_glyph_1200.png +3 -0
  11. vision-gap/data/images/C_name_glyph_15000.png +3 -0
  12. vision-gap/data/images/C_name_glyph_2500.png +3 -0
  13. vision-gap/data/images/C_name_glyph_500.png +3 -0
  14. vision-gap/data/images/C_name_hash_1200.png +3 -0
  15. vision-gap/data/images/C_name_hash_15000.png +3 -0
  16. vision-gap/data/images/C_name_hash_2500.png +3 -0
  17. vision-gap/data/images/C_name_hash_500.png +3 -0
  18. vision-gap/data/images/C_sym_EUR_1200_clean.png +3 -0
  19. vision-gap/data/images/C_sym_EUR_1200_wa.jpg +3 -0
  20. vision-gap/data/images/C_sym_EUR_15000_clean.png +3 -0
  21. vision-gap/data/images/C_sym_EUR_15000_wa.jpg +3 -0
  22. vision-gap/data/images/C_sym_EUR_2500_clean.png +3 -0
  23. vision-gap/data/images/C_sym_EUR_2500_wa.jpg +3 -0
  24. vision-gap/data/images/C_sym_EUR_500_clean.png +3 -0
  25. vision-gap/data/images/C_sym_EUR_500_wa.jpg +3 -0
  26. vision-gap/data/images/C_sym_GBP_1200_clean.png +3 -0
  27. vision-gap/data/images/C_sym_GBP_1200_wa.jpg +3 -0
  28. vision-gap/data/images/C_sym_GBP_15000_clean.png +3 -0
  29. vision-gap/data/images/C_sym_GBP_15000_wa.jpg +3 -0
  30. vision-gap/data/images/C_sym_GBP_2500_clean.png +3 -0
  31. vision-gap/data/images/C_sym_GBP_2500_wa.jpg +3 -0
  32. vision-gap/data/images/C_sym_GBP_500_clean.png +3 -0
  33. vision-gap/data/images/C_sym_GBP_500_wa.jpg +3 -0
  34. vision-gap/data/images/C_sym_NGN_1200_clean.png +3 -0
  35. vision-gap/data/images/C_sym_NGN_1200_wa.jpg +3 -0
  36. vision-gap/data/images/C_sym_NGN_15000_clean.png +3 -0
  37. vision-gap/data/images/C_sym_NGN_15000_wa.jpg +3 -0
  38. vision-gap/data/images/C_sym_NGN_2500_clean.png +3 -0
  39. vision-gap/data/images/C_sym_NGN_2500_wa.jpg +3 -0
  40. vision-gap/data/images/C_sym_NGN_500_clean.png +3 -0
  41. vision-gap/data/images/C_sym_NGN_500_wa.jpg +3 -0
  42. vision-gap/data/images/C_sym_USD_1200_clean.png +3 -0
  43. vision-gap/data/images/C_sym_USD_1200_wa.jpg +3 -0
  44. vision-gap/data/images/C_sym_USD_15000_clean.png +3 -0
  45. vision-gap/data/images/C_sym_USD_15000_wa.jpg +3 -0
  46. vision-gap/data/images/C_sym_USD_2500_clean.png +3 -0
  47. vision-gap/data/images/C_sym_USD_2500_wa.jpg +3 -0
  48. vision-gap/data/images/C_sym_USD_500_clean.png +3 -0
  49. vision-gap/data/images/C_sym_USD_500_wa.jpg +3 -0
  50. vision-gap/data/images/D_fr_24_L_clean.png +3 -0
README.md ADDED
@@ -0,0 +1,227 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: cc-by-4.0
3
+ language: [yo, vi, fr, en]
4
+ task_categories: [visual-question-answering, image-to-text]
5
+ tags:
6
+ [ocr, diacritics, yoruba, nigeria, vlm-evaluation, blind-spot, low-resource]
7
+ pretty_name: Ìbàdàn Vision Gap
8
+ ---
9
+
10
+ # Yoruba Vision Gap
11
+
12
+ ### Small VLMs read the letters of Yoruba but not its meaning — and bend Nigerian documents toward Western defaults
13
+
14
+ **Model evaluated:** [`Qwen/Qwen3-VL-4B-Instruct`](https://huggingface.co/Qwen/Qwen3-VL-4B-Instruct) (≈4.4B parameters, Apache-2.0) · optional second model `Qwen/Qwen2.5-VL-3B-Instruct`
15
+ **Evaluation set:** 360 synthetic, exactly-labelled probes (352 images) in 6 families, every probe paired with a control
16
+ **Everything here is reproducible:** `vision_gap_eval.ipynb` runs on a free Colab T4 and writes the Results section below automatically.
17
+
18
+ | Path | What it is |
19
+ | -------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
20
+ | `README.md` | this file — answers to Q1 (the gap) and Q3 (path forward), method, results |
21
+ | `data/images/` | 352 PNG/JPG probe images |
22
+ | `data/metadata.jsonl` / `.csv` | one row per probe: id, family, condition, prompt, ground truth, answer type, options, metadata |
23
+ | `build_dataset.py` | deterministic generator for the whole set (`python build_dataset.py --out data --seed 7`) |
24
+ | `scoring.py` | diacritic-aware automatic scoring (exact, letters-only, mark recall/precision by mark type, ANLS for comparison) |
25
+ | `vision_gap_eval.ipynb` | Colab notebook: load model → run → score → tables → figures → README → upload |
26
+ | `results/<model>/predictions.jsonl` | every raw model answer, with latency |
27
+ | `results/scored.csv`, `results/summary.md`, `results/failure_gallery.md`, `results/figures/` | scored rows, headline table, worst cases, plots |
28
+ | `model/<model>.json` | pinned model revision (commit SHA), dtype and decoding settings used |
29
+
30
+ ---
31
+
32
+ ## 1. The blind spot (Question 1)
33
+
34
+ ### What it is
35
+
36
+ Yoruba is a tonal language written in the Latin alphabet. Its meaning lives in two kinds of marks that standard English
37
+ OCR treats as decoration:
38
+
39
+ - **tone marks** — grave (low tone, `à`), acute (high tone, `á`), unmarked (mid tone);
40
+ - **under-dots** — `ẹ`, `ọ`, `ṣ` are different letters from `e`, `o`, `s`.
41
+
42
+ Take away the marks and words collapse into each other:
43
+
44
+ | written | meaning | written | meaning |
45
+ | ------- | ------------- | ------- | ------------ |
46
+ | ọkọ | husband | igbá | calabash |
47
+ | ọkọ̀ | vehicle, boat | ìgbà | time, period |
48
+ | ọ̀kọ̀ | spear | igba | two hundred |
49
+ | ọkọ́ | hoe | ìgbá | garden egg |
50
+
51
+ The gap I am testing is that **vision-language models read the base letters of Yoruba text correctly but drop, flatten
52
+ or invent the marks**, so they return a different word while looking almost right. Around it sits a broader pattern
53
+ I see in Nigerian documents generally: **when local visual evidence conflicts with the model's Western prior, the prior
54
+ wins.** The naira sign `₦` becomes `N` or `$`; `03/04/2026` on an invoice becomes March instead of April;
55
+ and a model asked "the total on this Bodija receipt is $13,200, correct?" is tempted to say yes.
56
+
57
+ ### Why this comes from my own background
58
+
59
+ - **Signage and names.** Street signs, church and mosque boards, market stalls, palace and council notices, and
60
+ people's names (Adébáyọ̀, Fọláṣadé, Olúwaṣẹ́un) are written with tone marks. Strip them and an identity or a place
61
+ name is wrong — the kind of error that breaks a student-records system, a KYC check or a land document search.
62
+ - **Documents arrive as WhatsApp photos.** Receipts, admission letters, bank tellers and government circulars are
63
+ photographed on a phone and forwarded several times. Each hop recompresses the JPEG, and tone marks — two or three
64
+ pixels tall — are the first detail to disappear.
65
+ - **Money and dates are local.** Prices are in naira; on a keyboard without `₦` people write `N2,500` or `#2,500`.
66
+ Dates are DD/MM/YYYY. A model that silently converts either into US conventions produces confident, wrong numbers.
67
+
68
+ ### Why standard benchmarks miss it
69
+
70
+ 1. **Coverage.** Text-in-image benchmarks (TextVQA, DocVQA, ChartQA, OCRBench, and multilingual ones such as MTVQA and
71
+ CC-OCR) are dominated by English and a handful of high-resource languages; to my knowledge none tests Yoruba
72
+ orthography, the naira sign or Nigerian document conventions. Culturally diverse VQA sets ask about scenes, not about
73
+ reading tone-marked text.
74
+ 2. **The metric hides it.** OCR benchmarks score with character error rate or ANLS. A dropped tone mark is a single
75
+ character edit: reading _Ẹ kú àárọ̀_ ("good morning") as _Ẹ kú àárọ_ gets **ANLS 0.90 — a pass** and reading
76
+ _ọkọ̀_ (vehicle) as _ọkọ_ (husband) gets 0.75. Some evaluation pipelines also strip accents before comparison,
77
+ which erases the error entirely. The gap is therefore invisible _by construction_, not just by omission.
78
+ 3. **Leaderboards reward the prior.** On English-heavy test sets, defaulting to `$` and MM/DD is usually right, so
79
+ the behaviour that fails Nigerian users is the behaviour that scores well.
80
+
81
+ ---
82
+
83
+ ## 2. Choice of model and how it was evaluated (Question 2)
84
+
85
+ ### Model: `Qwen/Qwen3-VL-4B-Instruct`
86
+
87
+ - **Size:** ≈4.4B parameters — inside the 0.6–6B window and runs in fp16 on a free 16 GB T4.
88
+ - **Frontier-representative:** it shares the architecture and training recipe of the Qwen3-VL family whose 235B flagship
89
+ is among the strongest open-weight VLMs, so its failure modes are a fair, cheap proxy for the flagship's (the notebook
90
+ includes an optional cell that re-asks the hardest slice to the 235B model to check this directly).
91
+ - **A fair test, not a strawman:** the model card advertises expanded OCR for 32 languages, robustness to "low light,
92
+ blur, and tilt", native dynamic resolution, and DeepStack multi-level vision features for fine detail. If a model
93
+ that claims all of this still drops tone marks, the problem is not image resolution or a weak OCR head.
94
+ - **Second opinion:** `Qwen2.5-VL-3B-Instruct` (previous generation) can be switched on in the notebook to test whether the
95
+ gap persists across generations; Gemma-3-4B and SmolVLM2-2.2B are also supported by the same harness.
96
+
97
+ Decoding is greedy (`do_sample=False`), one image per prompt, no system prompt, so results are deterministic and
98
+ reproducible. The exact model revision is pinned in `model/*.json`.
99
+
100
+ ### The evaluation set
101
+
102
+ All 360 probes are rendered synthetically (Pillow + HarfBuzz/raqm, so stacked marks like `ọ̀` are positioned correctly)
103
+ from five fonts and five sign colour schemes. Synthetic rendering gives **exact ground truth** and lets every probe
104
+ change **one variable at a time**.
105
+
106
+ | Family | n | Probe | Matched control | Question it answers |
107
+ | -------------------------------------- | --- | ----------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- |
108
+ | `diacritics` / `yo` | 96 | 24 Yoruba items (12 minimal-pair words, 6 place names, 6 phrases) × 4 conditions | — | Can it transcribe Yoruba exactly? |
109
+ | `diacritics` / `yo-ascii` | 48 | the same 24 items with all marks removed (2 conditions) | **same letters, same font, same layout** | Is the failure about the marks, or about the words? Does it _invent_ marks? |
110
+ | `diacritics` / `vi` | 32 | 8 Vietnamese items × 4 conditions | **same mark shapes** (dot-below, grave, acute, stacked) in a high-resource language | Is it the pixels, or the language? |
111
+ | `diacritics` / `fr` | 32 | 8 French items × 4 conditions | grave/acute in the highest-resource accented language | — |
112
+ | `minimal_pairs` / `mc_spelling` | 24 | pick the exact spelling from the minimal set (+ stripped form) | chance ≈ 23% | Can it _see_ the mark when it doesn't have to write it? |
113
+ | `minimal_pairs` / `meaning_from_image` | 8 | "what does this word mean?" for ọkọ/ọkọ̀/ọ̀kọ̀/ọkọ́ and igbá/ìgbà/igba/ìgbá | `meaning_from_text`: same question with the word typed in the prompt (8) | Does the mark it saw change what it _understands_? Does it know the word at all? |
114
+ | `currency` / `symbol_*` | 32 | price tags `₦500 … ₦15,000`, clean and WhatsApp-compressed | identical tags in `$`, `£`, `€` | Is `₦` read as `₦`? |
115
+ | `currency` / `name_*` | 12 | name the currency: `₦` glyph; `N2,500` and `#2,500` on a Bodija Market tag | — | Does it know Nigerian price conventions? |
116
+ | `receipts` | 24 | Bodija provision-store receipt in `₦`: neutral total + false-premise total (wrong currency or wrong amount) | identical Austin, TX receipt in `$` | Is it more sycophantic on local documents? |
117
+ | `dates` | 16 | invoice dated `03/04/2026`-style (day ≤ 12) | the same strings on US invoices; invoices with day > 12 | Does it read the date in the document's own locale? |
118
+ | `known_controls` | 28 | counting 3–32 dots, left/right, English menu transcription + false premise | — | How does this gap compare with blind spots already in public benchmarks? |
119
+
120
+ **Conditions** (diacritics family): `L_clean` 72 px text, lossless · `L_wa` same, then _WhatsApp-forwarded_
121
+ (±2.5° tilt, 0.6× downscale, slight blur, JPEG q=35) · `S_clean` 28 px text · `S_wa` 28 px + WhatsApp.
122
+
123
+ ### Scoring (`scoring.py`)
124
+
125
+ - **Exact match** after Unicode NFC, case-folding and whitespace cleanup — tone marks and dots are never stripped.
126
+ - **Letters-only match** (marks removed on both sides) — separates "read the wrong letters" from "read the right letters,
127
+ wrong marks" (`marks_only_error`).
128
+ - **Mark recall / precision by type** (`dot_below`, `grave`, `acute`, …) after aligning base letters, plus
129
+ **spurious marks** on the stripped control (hallucinated diacritics).
130
+ - **ANLS** on the same answers, to show what a standard OCR benchmark would have scored.
131
+ - Currency symbol and amount parsed separately (`N2,500` is reported as semantically right but not exact);
132
+ YES/NO parsing for false premises, plus whether the true total was stated; month parsing for dates;
133
+ letter parsing for multiple choice.
134
+
135
+ ### How the probes add up to a diagnosis
136
+
137
+ | If the results show… | …the gap is |
138
+ | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------- |
139
+ | Yoruba ≪ stripped Yoruba, and Yoruba ≪ Vietnamese on the _same_ mark types | about the **language**, not about seeing small marks (data coverage) |
140
+ | multiple-choice spelling ≫ free transcription | a **generation prior**: the model sees the mark but writes the ASCII form |
141
+ | multiple-choice ≈ chance and falls with font size / compression | a **perception** limit on 2–3 px features |
142
+ | meaning-from-text ≫ meaning-from-image | the model knows the word but the visual mark doesn't reach its reasoning |
143
+ | `₦` ≪ `$ £ €`, US-reading of Nigerian dates, higher sycophancy on the Bodija receipt | a **locale prior** overriding visual evidence |
144
+ | known controls fail too, but Yoruba fails at sizes where ASCII succeeds | the gap is specific, not general weakness |
145
+
146
+ ---
147
+
148
+ ## 3. Results
149
+
150
+ <!-- RESULTS:START -->
151
+
152
+ _Pending: run `vision_gap_eval.ipynb` (cell 10 writes this section from the run)._
153
+
154
+ <!-- RESULTS:END -->
155
+
156
+ ---
157
+
158
+ ## 4. Path forward (Question 3)
159
+
160
+ The probes above are designed to say _which_ of the fixes below matters most; this is the plan I would follow.
161
+
162
+ ### 4.1 Data curation — the main lever
163
+
164
+ 1. **Synthetic Yoruba text-in-image at scale (cheap, exact labels).** Scale `build_dataset.py` into a renderer driven by
165
+ real Yoruba text — MENYO-20k, Yoruba Wikipedia, BBC Yorùbá news, public-domain religious text — rendered in 50+
166
+ fonts including hand-painted sign styles, onto signs, receipts, posters, bulletins and government forms, with a
167
+ degradation pipeline that reproduces how Nigerian documents actually travel: repeated WhatsApp JPEG compression,
168
+ phone-camera blur, perspective, low light. Rendering must go through HarfBuzz (as here) or stacked marks come out
169
+ wrong and poison the data. Target: ~1M image–text pairs, NFC-normalised.
170
+ 2. **Real photos with native-speaker labels (small, high value).** Photograph signage, receipts and notices in Nigeria and have two native speakers transcribe each one, with disagreements
171
+ adjudicated. A few thousand images is enough for evaluation and for a final fine-tuning stage; it also catches
172
+ things synthesis misses, such as hand lettering and faded paint.
173
+ 3. **Minimal-pair hard negatives.** For every image, store alternative transcriptions that differ _only_ in marks
174
+ (ọkọ / ọkọ̀ / ọ̀kọ̀ / ọkọ́). These become the rejected side of preference pairs and the distractors of contrastive
175
+ training — the model must learn that these differences matter.
176
+ 4. **Locale-grounded document QA.** Nigerian receipts, invoices, tellers and forms with `₦`, `N` and `#` prices,
177
+ DD/MM dates and `+234` numbers, paired with question–answer data in which a good share of questions carry a **false
178
+ premise whose correct answer is "No, it says …"**.
179
+ 5. **Fix the measurement.** Report a diacritic error rate and mark recall separately from CER/ANLS, never strip
180
+ accents during evaluation, and add Yoruba and Igbo (ị, ọ, ụ, ṅ) slices to OCR leaderboards.
181
+ As long as the metric scores _ọkọ̀ → ọkọ_ at 0.75, no one will optimise for it.
182
+
183
+ ### 4.2 Fine-tuning paradigm
184
+
185
+ 1. **Stage 1 — supervised fine-tuning that reaches the vision side.** LoRA on the language model _plus_ unfreezing the
186
+ vision–language merger and the top vision blocks (for Qwen3-VL, including the DeepStack fusion paths), trained on
187
+ transcription and document QA from 4.1. If the probes show a perception limit, adapting only the LLM will not fix it.
188
+ 2. **Mark-weighted loss.** Combining marks are a small share of output tokens, so plain cross-entropy barely notices them.
189
+ Up-weight the loss on tokens containing tone marks or under-dots (e.g. 3–5×).
190
+ 3. **Stage 2 — preference optimisation.** DPO (or an image-conditioned variant such as mDPO) with pairs
191
+ _chosen = correct marks_ vs _rejected = stripped or wrong tone_, and _chosen = "No, the total is ₦13,200"_
192
+ vs _rejected = "Yes"_. This targets exactly the two behaviours measured here: flattening and sycophancy.
193
+ 4. **Keep everything else intact.** Mix in ≥50% general replay data and re-run OCRBench and the known controls after
194
+ each stage so that fixing Yoruba does not break English.
195
+
196
+ ### 4.3 Architectural adjustments
197
+
198
+ 1. **Resolution where the text is.** A tone mark on 28 px text is 2–3 pixels; after patching and 2×2 token merging
199
+ one visual token covers roughly a 32×32 px area, so the mark is a small fraction of one token. Detect text regions and re-encode them at higher resolution
200
+ (a learned "zoom" pass), rather than paying for high resolution everywhere.
201
+ 2. **Character-level grounding head.** Add an auxiliary CTC OCR head on the vision features, trained on
202
+ diacritic-exact targets, so the model has pixel-grounded evidence for each mark that the decoder can attend to.
203
+ 3. **Tokenizer.** Byte-level BPE splits `ọ̀` into several rare tokens, which gives the decoder a strong prior toward
204
+ the ASCII spelling. Adding tokens for frequent Yoruba vowel-plus-mark clusters (initialised from the mean of their
205
+ pieces) lowers that prior.
206
+ 4. **Calibrated abstention.** When the evidence for a mark is weak — a heavily compressed photo — the model should say
207
+ the tone is unreadable instead of guessing; this is cheap to train with the hard negatives above.
208
+
209
+ **Cheapest test of this plan:** LoRA-tune Qwen3-VL-4B on ~50k synthetic renders from 4.1 (stage 1 + mark-weighted
210
+ loss), then re-run this notebook. Success = Yoruba exact match reaches the Vietnamese control on held-out fonts and
211
+ real photos, with no drop on OCRBench and the known controls.
212
+
213
+ ---
214
+
215
+ ## Limitations
216
+
217
+ - Images are synthetic. They control variables cleanly but do not capture hand lettering, faded paint or real camera
218
+ optics; the real-photo set in 4.1 is the natural next step.
219
+ - The ambiguous-date probes have no single "correct" answer in isolation; they measure whether the model uses the
220
+ locale cues present (Addresses, `+234` phone, `₦` amounts), and are reported separately from unambiguous dates.
221
+ - Yoruba orthography follows standard written Yoruba and the minimal-pair glosses were reviewed by the author;
222
+ please open an issue if you spot an error.
223
+ - Greedy decoding on one prompt wording per probe; prompt sensitivity is not measured here.
224
+
225
+ ## Licence and citation
226
+
227
+ Dataset (images + metadata): CC-BY-4.0. Code: MIT. Model weights: see the original model licence (Apache-2.0).
vision-gap.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2f7bf137f8725dcbf33ceece75c462d613a1ef9ce2375c0c1edb38546e737365
3
+ size 2459421
vision-gap/.flake8 ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ [flake8]
2
+ max-line-length = 88
3
+ extend-ignore = E203, E501, W503
4
+ exclude = .git,__pycache__,build,dist,.venv,.ipynb_checkpoints
5
+ per-file-ignores =
6
+ tests/*:S101
7
+ vision_gap/figures.py:E501
8
+ *.ipynb:E402,F821,F401,E401
9
+ *_nbqa_ipynb.py:E402,F821,F401,E401
vision-gap/README.md ADDED
@@ -0,0 +1,301 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: cc-by-4.0
3
+ language: [yo, vi, fr, en]
4
+ task_categories: [visual-question-answering, image-to-text]
5
+ tags: [ocr, diacritics, yoruba, nigeria, vlm-evaluation, blind-spot, low-resource]
6
+ pretty_name: Ìbàdàn Vision Gap
7
+ ---
8
+
9
+ # Ìbàdàn Vision Gap
10
+ ### Small VLMs read the letters of Yoruba but not its meaning — and bend Nigerian documents toward Western defaults
11
+
12
+ **Author:** Isaac Olaleye — Assistant Lecturer, University of Ibadan (AI, Computer Vision & Intelligent Systems)
13
+ **Model evaluated:** [`Qwen/Qwen3-VL-4B-Instruct`](https://huggingface.co/Qwen/Qwen3-VL-4B-Instruct) (≈4.4B parameters, Apache-2.0) · optional second model `Qwen/Qwen2.5-VL-3B-Instruct`
14
+ **Evaluation set:** 360 synthetic, exactly-labelled probes (352 images) in 6 families, every probe paired with a control
15
+ **Everything here is reproducible:** the `vision_gap` package is tested (`python -m pytest`) and runs from the command line (`python -m vision_gap run`) or from `vision_gap_eval.ipynb` on a free Colab T4. Either way the Results section below is written automatically.
16
+
17
+ | Path | What it is |
18
+ |---|---|
19
+ | `README.md` | this file — answers to Q1 (the gap) and Q3 (path forward), method, results |
20
+ | `data/images/` | 352 PNG/JPG probe images |
21
+ | `data/metadata.jsonl` / `.csv` | one row per probe: id, family, condition, prompt, ground truth, answer type, options, metadata |
22
+ | `build_dataset.py` | deterministic generator for the whole set (`python build_dataset.py --out data --seed 7`) |
23
+ | `vision_gap/` | the tested evaluation package: scoring, dataset loading, inference, tables, figures, report, publishing |
24
+ | `vision_gap_eval.ipynb` | thin Colab notebook that only orchestrates the `vision_gap` package |
25
+ | `tests/` | the test suite for the package (`python -m pytest`) |
26
+ | `results/<model>/predictions.jsonl` | every raw model answer, with latency |
27
+ | `results/scored.csv`, `results/summary.md`, `results/failure_gallery.md`, `results/figures/` | scored rows, headline table, worst cases, plots |
28
+ | `model/<model>.json` | pinned model revision (commit SHA), dtype and decoding settings used |
29
+
30
+ ### How to run it
31
+
32
+ The package is the source of truth; the notebook and the CLI are two thin front ends to it.
33
+
34
+ ```bash
35
+ pip install -e ".[inference,dev]"
36
+
37
+ python -m vision_gap run # probes -> predictions -> score -> report
38
+ python -m vision_gap run --models org/model-a org/model-b
39
+ python -m vision_gap run --subsample 40 # a deterministic subset, for a smoke run
40
+ python -m vision_gap run --use-4bit # load the model in 4-bit to fit in less VRAM
41
+ python -m vision_gap score # score the predictions that are already there
42
+ python -m vision_gap report # rebuild the tables and figures from the scored rows
43
+ python -m vision_gap probes # list the probe set
44
+ python -m vision_gap publish # push everything to a public HF bucket
45
+ ```
46
+
47
+ Predictions are appended and flushed one JSON line per probe, so an interrupted run costs
48
+ nothing: re-running skips the probes that are already finished.
49
+
50
+ The same steps are available from Python:
51
+
52
+ ```python
53
+ from vision_gap import pipeline
54
+ from vision_gap.config import RunConfig
55
+
56
+ config = RunConfig(models=["Qwen/Qwen3-VL-4B-Instruct"])
57
+ result = pipeline.run_pipeline(config)
58
+ print(result.summary)
59
+ ```
60
+
61
+ `vision_gap_eval.ipynb` does exactly this and nothing else, so it runs on a free Colab T4.
62
+
63
+ ### The package
64
+
65
+ | Module | Responsibility |
66
+ |---|---|
67
+ | `vision_gap.config` | the run configuration and every path |
68
+ | `vision_gap.scoring` | diacritic-aware scoring (exact, letters-only, mark recall, ANLS) |
69
+ | `vision_gap.dataset` | loading the probe metadata and subsampling it deterministically |
70
+ | `vision_gap.models` | model-agnostic loader and inference |
71
+ | `vision_gap.runner` | running every probe, resumably |
72
+ | `vision_gap.scoring_pipeline` | predictions -> the tidy scored table |
73
+ | `vision_gap.tables` | the per-question summary tables and the mark-recall breakdown |
74
+ | `vision_gap.figures` | the four figures |
75
+ | `vision_gap.gallery` | the failure gallery |
76
+ | `vision_gap.report` | `results/summary.md` and the README results block |
77
+ | `vision_gap.publish` | publishing to a Hugging Face bucket |
78
+ | `vision_gap.frontier` | the optional comparison against the 235B flagship |
79
+ | `vision_gap.pipeline` | the whole flow, in one call |
80
+
81
+ The top-level `scoring.py` is a thin backwards-compatible shim over `vision_gap/scoring.py`.
82
+
83
+ ---
84
+
85
+ ## 1. The blind spot (Question 1)
86
+
87
+ ### What it is
88
+ Yoruba is a tonal language written in the Latin alphabet. Its meaning lives in two kinds of marks that standard English
89
+ OCR treats as decoration:
90
+
91
+ * **tone marks** — grave (low tone, `à`), acute (high tone, `á`), unmarked (mid tone);
92
+ * **under-dots** — `ẹ`, `ọ`, `ṣ` are different letters from `e`, `o`, `s`.
93
+
94
+ Take away the marks and words collapse into each other:
95
+
96
+ | written | meaning | written | meaning |
97
+ |---|---|---|---|
98
+ | ọkọ | husband | igbá | calabash |
99
+ | ọkọ̀ | vehicle, boat | ìgbà | time, period |
100
+ | ọ̀kọ̀ | spear | igba | two hundred |
101
+ | ọkọ́ | hoe | ìgbá | garden egg |
102
+
103
+ The gap I am testing is that **vision-language models read the base letters of Yoruba text correctly but drop, flatten
104
+ or invent the marks**, so they return a different word while looking almost right. Around it sits a broader pattern
105
+ I see in Nigerian documents generally: **when local visual evidence conflicts with the model's Western prior, the prior
106
+ wins.** The naira sign `₦` becomes `N` or `$`; `03/04/2026` on an Ibadan invoice becomes March instead of April;
107
+ and a model asked "the total on this Bodija receipt is $13,200, correct?" is tempted to say yes.
108
+
109
+ ### Why this comes from my own background
110
+ I teach and research computer vision at the University of Ibadan and build software for Nigerian universities,
111
+ government agencies and small businesses. In that work, the images that matter are rarely clean scans:
112
+
113
+ * **Signage and names.** Street signs, church and mosque boards, market stalls, palace and council notices, and
114
+ people's names (Adébáyọ̀, Fọláṣadé, Olúwaṣẹ́un) are written with tone marks. Strip them and an identity or a place
115
+ name is wrong — the kind of error that breaks a student-records system, a KYC check or a land document search.
116
+ * **Documents arrive as WhatsApp photos.** Receipts, admission letters, bank tellers and government circulars are
117
+ photographed on a phone and forwarded several times. Each hop recompresses the JPEG, and tone marks — two or three
118
+ pixels tall — are the first detail to disappear.
119
+ * **Money and dates are local.** Prices are in naira; on a keyboard without `₦` people write `N2,500` or `#2,500`.
120
+ Dates are DD/MM/YYYY. A model that silently converts either into US conventions produces confident, wrong numbers.
121
+
122
+ ### Why standard benchmarks miss it
123
+ 1. **Coverage.** Text-in-image benchmarks (TextVQA, DocVQA, ChartQA, OCRBench, and multilingual ones such as MTVQA and
124
+ CC-OCR) are dominated by English and a handful of high-resource languages; to my knowledge none tests Yoruba
125
+ orthography, the naira sign or Nigerian document conventions. Culturally diverse VQA sets ask about scenes, not about
126
+ reading tone-marked text.
127
+ 2. **The metric hides it.** OCR benchmarks score with character error rate or ANLS. A dropped tone mark is a single
128
+ character edit: reading *Ẹ kú àárọ̀* ("good morning") as *Ẹ kú àárọ* gets **ANLS 0.90 — a pass** — and reading
129
+ *ọkọ̀* (vehicle) as *ọkọ* (husband) gets 0.75. Some evaluation pipelines also strip accents before comparison,
130
+ which erases the error entirely. The gap is therefore invisible *by construction*, not just by omission.
131
+ 3. **Leaderboards reward the prior.** On English-heavy test sets, defaulting to `$` and MM/DD is usually right, so
132
+ the behaviour that fails Nigerian users is the behaviour that scores well.
133
+
134
+ ---
135
+
136
+ ## 2. Choice of model and how it was evaluated (Question 2)
137
+
138
+ ### Model: `Qwen/Qwen3-VL-4B-Instruct`
139
+ * **Size:** ≈4.4B parameters — inside the 0.6–6B window and runs in fp16 on a free 16 GB T4.
140
+ * **Frontier-representative:** it shares the architecture and training recipe of the Qwen3-VL family whose 235B flagship
141
+ is among the strongest open-weight VLMs, so its failure modes are a fair, cheap proxy for the flagship's (the notebook
142
+ includes an optional cell that re-asks the hardest slice to the 235B model to check this directly).
143
+ * **A fair test, not a strawman:** the model card advertises expanded OCR for 32 languages, robustness to "low light,
144
+ blur, and tilt", native dynamic resolution, and DeepStack multi-level vision features for fine detail. If a model
145
+ that claims all of this still drops tone marks, the problem is not image resolution or a weak OCR head.
146
+ * **Second opinion:** `Qwen2.5-VL-3B-Instruct` (previous generation) can be switched on in the notebook to test whether the
147
+ gap persists across generations; Gemma-3-4B and SmolVLM2-2.2B are also supported by the same harness.
148
+
149
+ Decoding is greedy (`do_sample=False`), one image per prompt, no system prompt, so results are deterministic and
150
+ reproducible. The exact model revision is pinned in `model/*.json`.
151
+
152
+ ### The evaluation set
153
+ All 360 probes are rendered synthetically (Pillow + HarfBuzz/raqm, so stacked marks like `ọ̀` are positioned correctly)
154
+ from five fonts and five sign colour schemes. Synthetic rendering gives **exact ground truth** and lets every probe
155
+ change **one variable at a time**.
156
+
157
+ | Family | n | Probe | Matched control | Question it answers |
158
+ |---|---|---|---|---|
159
+ | `diacritics` / `yo` | 96 | 24 Yoruba items (12 minimal-pair words, 6 place names, 6 phrases) × 4 conditions | — | Can it transcribe Yoruba exactly? |
160
+ | `diacritics` / `yo-ascii` | 48 | the same 24 items with all marks removed (2 conditions) | **same letters, same font, same layout** | Is the failure about the marks, or about the words? Does it *invent* marks? |
161
+ | `diacritics` / `vi` | 32 | 8 Vietnamese items × 4 conditions | **same mark shapes** (dot-below, grave, acute, stacked) in a high-resource language | Is it the pixels, or the language? |
162
+ | `diacritics` / `fr` | 32 | 8 French items × 4 conditions | grave/acute in the highest-resource accented language | — |
163
+ | `minimal_pairs` / `mc_spelling` | 24 | pick the exact spelling from the minimal set (+ stripped form) | chance ≈ 23% | Can it *see* the mark when it doesn't have to write it? |
164
+ | `minimal_pairs` / `meaning_from_image` | 8 | "what does this word mean?" for ọkọ/ọkọ̀/ọ̀kọ̀/ọkọ́ and igbá/ìgbà/igba/ìgbá | `meaning_from_text`: same question with the word typed in the prompt (8) | Does the mark it saw change what it *understands*? Does it know the word at all? |
165
+ | `currency` / `symbol_*` | 32 | price tags `₦500 … ₦15,000`, clean and WhatsApp-compressed | identical tags in `$`, `£`, `€` | Is `₦` read as `₦`? |
166
+ | `currency` / `name_*` | 12 | name the currency: `₦` glyph; `N2,500` and `#2,500` on a Bodija Market tag | — | Does it know Nigerian price conventions? |
167
+ | `receipts` | 24 | Bodija provision-store receipt in `₦`: neutral total + false-premise total (wrong currency or wrong amount) | identical Austin, TX receipt in `$` | Is it more sycophantic on local documents? |
168
+ | `dates` | 16 | Ibadan invoice dated `03/04/2026`-style (day ≤ 12) | the same strings on US invoices; Ibadan invoices with day > 12 | Does it read the date in the document's own locale? |
169
+ | `known_controls` | 28 | counting 3–32 dots, left/right, English menu transcription + false premise | — | How does this gap compare with blind spots already in public benchmarks? |
170
+
171
+ **Conditions** (diacritics family): `L_clean` 72 px text, lossless · `L_wa` same, then *WhatsApp-forwarded*
172
+ (±2.5° tilt, 0.6× downscale, slight blur, JPEG q=35) · `S_clean` 28 px text · `S_wa` 28 px + WhatsApp.
173
+
174
+ ### Scoring (`vision_gap/scoring.py`)
175
+ * **Exact match** after Unicode NFC, case-folding and whitespace cleanup — tone marks and dots are never stripped.
176
+ * **Letters-only match** (marks removed on both sides) — separates "read the wrong letters" from "read the right letters,
177
+ wrong marks" (`marks_only_error`).
178
+ * **Mark recall / precision by type** (`dot_below`, `grave`, `acute`, …) after aligning base letters, plus
179
+ **spurious marks** on the stripped control (hallucinated diacritics).
180
+ * **ANLS** on the same answers, to show what a standard OCR benchmark would have scored.
181
+ * Currency symbol and amount parsed separately (`N2,500` is reported as semantically right but not exact);
182
+ YES/NO parsing for false premises, plus whether the true total was stated; month parsing for dates;
183
+ letter parsing for multiple choice.
184
+
185
+ ### How the probes add up to a diagnosis
186
+ | If the results show… | …the gap is |
187
+ |---|---|
188
+ | Yoruba ≪ stripped Yoruba, and Yoruba ≪ Vietnamese on the *same* mark types | about the **language**, not about seeing small marks (data coverage) |
189
+ | multiple-choice spelling ≫ free transcription | a **generation prior**: the model sees the mark but writes the ASCII form |
190
+ | multiple-choice ≈ chance and falls with font size / compression | a **perception** limit on 2–3 px features |
191
+ | meaning-from-text ≫ meaning-from-image | the model knows the word but the visual mark doesn't reach its reasoning |
192
+ | `₦` ≪ `$ £ €`, US-reading of Nigerian dates, higher sycophancy on the Bodija receipt | a **locale prior** overriding visual evidence |
193
+ | known controls fail too, but Yoruba fails at sizes where ASCII succeeds | the gap is specific, not general weakness |
194
+
195
+ ---
196
+
197
+ ## 3. Results
198
+
199
+ <!-- RESULTS:START -->
200
+ ### `Qwen3-VL-4B-Instruct`
201
+
202
+ | Probe | Result | Matched control |
203
+ |---|---|---|
204
+ | Yoruba transcribed exactly (large, clean) | **100%** | same words, marks stripped: 100% · Vietnamese: 100% · French: 100% |
205
+ | Yoruba transcribed exactly (small, WhatsApp-compressed) | **100%** | stripped: 100% · Vietnamese: 100% · French: 100% |
206
+ | Yoruba errors where every *letter* was right (marks-only errors) | **0%** of all Yoruba items | — |
207
+ | Wrong Yoruba answers a standard ANLS≥0.5 OCR metric would still pass | **–** | — |
208
+ | Dot-below recall | Yoruba **100%** | Vietnamese 100% |
209
+ | Grave / acute recall | Yoruba **100% / 100%** | Vietnamese 100% / 100% · French 100% / 100% |
210
+ | Marks hallucinated on stripped (ASCII) Yoruba, per item | 0.00 | — |
211
+ | Picks the right spelling among minimal pairs (multiple choice) | **100%** | chance ≈ 20%–25% |
212
+ | Gives the right meaning when the word is shown as an image | **100%** | same word as text in the prompt: 100% · chance 25% |
213
+ | ₦ symbol read correctly on a price tag | **100%** | $ 100% · £ 100% · € 100% |
214
+ | Names the currency as naira: ₦ glyph / `N2,500` / `#2,500` at Bodija Market | **100% / 100% / 100%** | — |
215
+ | Receipt total read correctly | Bodija ₦ **100%** | Austin $ 100% |
216
+ | Accepts a false total (sycophancy) | Bodija ₦ **0%** | Austin $ 0% |
217
+ | Reads an ambiguous date in the document's own locale | Nigerian DD/MM **100%** | US MM/DD 100% · Nigerian unambiguous 100% |
218
+ | Known controls: counting / left-right / English menu false premise | 100% / 100% / 100% | — |
219
+
220
+ Figures: `results/figures/`. Every prediction: `results/<model>/predictions.jsonl`; scored rows: `results/scored.csv`; examples: `results/failure_gallery.md`.
221
+
222
+ *Numbers in this section are written automatically by the notebook from the run above.*
223
+ <!-- RESULTS:END -->
224
+
225
+ ---
226
+
227
+ ## 4. Path forward (Question 3)
228
+
229
+ The probes above are designed to say *which* of the fixes below matters most; this is the plan I would follow.
230
+
231
+ ### 4.1 Data curation — the main lever
232
+ 1. **Synthetic Yoruba text-in-image at scale (cheap, exact labels).** Scale `build_dataset.py` into a renderer driven by
233
+ real Yoruba text — MENYO-20k, Yoruba Wikipedia, BBC Yorùbá news, public-domain religious text — rendered in 50+
234
+ fonts including hand-painted sign styles, onto signs, receipts, posters, bulletins and government forms, with a
235
+ degradation pipeline that reproduces how Nigerian documents actually travel: repeated WhatsApp JPEG compression,
236
+ phone-camera blur, perspective, low light. Rendering must go through HarfBuzz (as here) or stacked marks come out
237
+ wrong and poison the data. Target: ~1M image–text pairs, NFC-normalised.
238
+ 2. **Real photos with native-speaker labels (small, high value).** Photograph signage, receipts and notices around
239
+ Ibadan (Bodija, Dugbe, Mokola, the UI campus) and have two native speakers transcribe each one, with disagreements
240
+ adjudicated. A few thousand images is enough for evaluation and for a final fine-tuning stage; it also catches
241
+ things synthesis misses, such as hand lettering and faded paint.
242
+ 3. **Minimal-pair hard negatives.** For every image, store alternative transcriptions that differ *only* in marks
243
+ (ọkọ / ọkọ̀ / ọ̀kọ̀ / ọkọ́). These become the rejected side of preference pairs and the distractors of contrastive
244
+ training — the model must learn that these differences matter.
245
+ 4. **Locale-grounded document QA.** Nigerian receipts, invoices, tellers and forms with `₦`, `N` and `#` prices,
246
+ DD/MM dates and `+234` numbers, paired with question–answer data in which a good share of questions carry a **false
247
+ premise whose correct answer is "No, it says …"**.
248
+ 5. **Fix the measurement.** Report a diacritic error rate and mark recall separately from CER/ANLS, never strip
249
+ accents during evaluation, and add Yoruba and Igbo (ị, ọ, ụ, ṅ) slices to OCR leaderboards.
250
+ As long as the metric scores *ọkọ̀ → ọkọ* at 0.75, no one will optimise for it.
251
+
252
+ ### 4.2 Fine-tuning paradigm
253
+ 1. **Stage 1 — supervised fine-tuning that reaches the vision side.** LoRA on the language model *plus* unfreezing the
254
+ vision–language merger and the top vision blocks (for Qwen3-VL, including the DeepStack fusion paths), trained on
255
+ transcription and document QA from 4.1. If the probes show a perception limit, adapting only the LLM will not fix it.
256
+ 2. **Mark-weighted loss.** Combining marks are a small share of output tokens, so plain cross-entropy barely notices them.
257
+ Up-weight the loss on tokens containing tone marks or under-dots (e.g. 3–5×).
258
+ 3. **Stage 2 — preference optimisation.** DPO (or an image-conditioned variant such as mDPO) with pairs
259
+ *chosen = correct marks* vs *rejected = stripped or wrong tone*, and *chosen = "No, the total is ₦13,200"*
260
+ vs *rejected = "Yes"*. This targets exactly the two behaviours measured here: flattening and sycophancy.
261
+ 4. **Keep everything else intact.** Mix in ≥50% general replay data and re-run OCRBench and the known controls after
262
+ each stage so that fixing Yoruba does not break English.
263
+
264
+ ### 4.3 Architectural adjustments
265
+ 1. **Resolution where the text is.** A tone mark on 28 px text is 2–3 pixels; after patching and 2×2 token merging
266
+ one visual token covers roughly a 32×32 px area, so the mark is a small fraction of one token. Detect text regions and re-encode them at higher resolution
267
+ (a learned "zoom" pass), rather than paying for high resolution everywhere.
268
+ 2. **Character-level grounding head.** Add an auxiliary CTC OCR head on the vision features, trained on
269
+ diacritic-exact targets, so the model has pixel-grounded evidence for each mark that the decoder can attend to.
270
+ 3. **Tokenizer.** Byte-level BPE splits `ọ̀` into several rare tokens, which gives the decoder a strong prior toward
271
+ the ASCII spelling. Adding tokens for frequent Yoruba vowel-plus-mark clusters (initialised from the mean of their
272
+ pieces) lowers that prior.
273
+ 4. **Calibrated abstention.** When the evidence for a mark is weak — a heavily compressed photo — the model should say
274
+ the tone is unreadable instead of guessing; this is cheap to train with the hard negatives above.
275
+
276
+ **Cheapest test of this plan:** LoRA-tune Qwen3-VL-4B on ~50k synthetic renders from 4.1 (stage 1 + mark-weighted
277
+ loss), then re-run this notebook. Success = Yoruba exact match reaches the Vietnamese control on held-out fonts and
278
+ real photos, with no drop on OCRBench and the known controls.
279
+
280
+ ---
281
+
282
+ ## Limitations
283
+ * Images are synthetic. They control variables cleanly but do not capture hand lettering, faded paint or real camera
284
+ optics; the real-photo set in 4.1 is the natural next step.
285
+ * The ambiguous-date probes have no single "correct" answer in isolation; they measure whether the model uses the
286
+ locale cues present (Ibadan address, `+234` phone, `₦` amounts), and are reported separately from unambiguous dates.
287
+ * Yoruba orthography follows standard written Yoruba and the minimal-pair glosses were reviewed by the author;
288
+ please open an issue if you spot an error.
289
+ * Greedy decoding on one prompt wording per probe; prompt sensitivity is not measured here.
290
+
291
+ ## Licence and citation
292
+ Dataset (images + metadata): CC-BY-4.0. Code: MIT. Model weights: see the original model licence (Apache-2.0).
293
+
294
+ ```
295
+ @misc{olaleye2026ibadanvisiongap,
296
+ title = {Ìbàdàn Vision Gap: tone marks, naira and locale priors in small vision-language models},
297
+ author = {Olaleye, Isaac},
298
+ year = {2026},
299
+ note = {Hugging Face Bucket}
300
+ }
301
+ ```
vision-gap/build_dataset.py ADDED
@@ -0,0 +1,401 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ build_dataset.py — generates the "Ìbàdàn Vision Gap" evaluation set.
4
+
5
+ Every image is rendered synthetically so that ground truth is exact
6
+ (no annotation noise), and every probe has a matched control that changes
7
+ exactly one variable. Output:
8
+
9
+ data/images/*.png|*.jpg
10
+ data/metadata.jsonl one JSON object per probe
11
+ data/metadata.csv same, flattened for spreadsheets
12
+
13
+ Requirements: Pillow built with libraqm (needed to stack Yoruba tone marks on
14
+ dotted vowels such as ọ̀ correctly), plus DejaVu / FreeFont / Liberation fonts
15
+ (Debian/Ubuntu: fonts-dejavu fonts-freefont-ttf fonts-liberation).
16
+ The images shipped in the bucket were rendered with Pillow 12.3 + raqm, so you
17
+ only need this script if you want to regenerate or extend the set.
18
+
19
+ python build_dataset.py --out data --seed 7
20
+ """
21
+ import argparse, json, os, random, unicodedata as ud, csv, io
22
+ from PIL import Image, ImageDraw, ImageFont, ImageFilter, features
23
+
24
+ NFC = lambda s: ud.normalize("NFC", s)
25
+
26
+ def strip_marks(s):
27
+ return NFC("".join(c for c in ud.normalize("NFD", s) if not ud.combining(c)))
28
+
29
+ FONT_DIRS = {
30
+ "DejaVuSans": "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",
31
+ "DejaVuSans-Bold": "/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf",
32
+ "DejaVuSerif": "/usr/share/fonts/truetype/dejavu/DejaVuSerif.ttf",
33
+ "FreeSans": "/usr/share/fonts/truetype/freefont/FreeSans.ttf",
34
+ "LiberationSans": "/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf",
35
+ }
36
+ MONO = "/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf"
37
+ MONO_B = "/usr/share/fonts/truetype/dejavu/DejaVuSansMono-Bold.ttf"
38
+ SANS_B = FONT_DIRS["DejaVuSans-Bold"]
39
+ SANS = FONT_DIRS["DejaVuSans"]
40
+
41
+ def font(path, size):
42
+ return ImageFont.truetype(path, size, layout_engine=ImageFont.Layout.RAQM)
43
+
44
+ # --------------------------------------------------------------------------
45
+ # Lexicons
46
+ # --------------------------------------------------------------------------
47
+ # Yoruba minimal sets: identical letters, meaning carried only by tone marks
48
+ # and the dot under ẹ/ọ/ṣ. (Orthography: standard Yoruba; verify with a
49
+ # native speaker before extending.)
50
+ YO_GROUPS = {
51
+ "oko": [("ọkọ", "husband"), ("ọkọ̀", "vehicle / boat"), ("ọ̀kọ̀", "spear"), ("ọkọ́", "hoe")],
52
+ "igba": [("igbá", "calabash"), ("ìgbà", "time / period"), ("igba", "two hundred"), ("ìgbá", "garden egg")],
53
+ "ile": [("ilé", "house"), ("ilẹ̀", "land / ground")],
54
+ "oro": [("ọ̀rọ̀", "word / speech"), ("ọrọ̀", "wealth")],
55
+ }
56
+ YO_PLACES = [("Ìbàdàn", "Ibadan"), ("Ọ̀yọ́", "Oyo"), ("Èkó", "Lagos"),
57
+ ("Abẹ́òkúta", "Abeokuta"), ("Ọ̀ṣun", "Osun"), ("Bódìjà", "Bodija")]
58
+ YO_PHRASES = [("Ẹ kú àárọ̀", "good morning"), ("Ẹ kú iṣẹ́", "well done (greeting at work)"),
59
+ ("Ẹ ṣé", "thank you"), ("Ọjà Bódìjà", "Bodija Market"),
60
+ ("Ilé-ìwé", "school"), ("Àṣẹ", "authority / so be it")]
61
+ # High-resource controls with comparable marks. Vietnamese is the key one:
62
+ # it uses the same dot-below (ọ, ạ) and grave/acute marks, often stacked.
63
+ FR_WORDS = ["café", "élève", "crème brûlée", "à bientôt", "garçon", "Noël", "fenêtre", "déjà vu"]
64
+ VI_WORDS = ["Việt Nam", "phở", "cảm ơn", "Hà Nội", "chợ Bến Thành", "người", "học sinh", "đọc sách"]
65
+
66
+ # Sign colour schemes (bg, fg) — loosely modelled on painted shop signs.
67
+ SCHEMES = [((250, 248, 240), (20, 20, 20)), ((255, 236, 150), (25, 25, 25)),
68
+ ((0, 112, 60), (255, 255, 255)), ((255, 255, 255), (150, 20, 20)),
69
+ ((20, 40, 90), (255, 255, 255))]
70
+
71
+ # --------------------------------------------------------------------------
72
+ # Rendering helpers
73
+ # --------------------------------------------------------------------------
74
+ def render_sign(text, font_path, size, scheme, W=768, H=320, sub=None):
75
+ bg, fg = scheme
76
+ img = Image.new("RGB", (W, H), bg)
77
+ d = ImageDraw.Draw(img)
78
+ f = font(font_path, size)
79
+ # shrink if too wide
80
+ while d.textlength(text, font=f) > W - 60 and size > 12:
81
+ size -= 2; f = font(font_path, size)
82
+ bbox = d.textbbox((0, 0), text, font=f)
83
+ tw, th = bbox[2] - bbox[0], bbox[3] - bbox[1]
84
+ d.text(((W - tw) / 2 - bbox[0], (H - th) / 2 - bbox[1]), text, font=f, fill=fg)
85
+ if sub:
86
+ fs = font(SANS, 18)
87
+ d.text((16, H - 30), sub, font=fs, fill=fg)
88
+ return img
89
+
90
+ def whatsapp(img, rng, scale=0.6, quality=35):
91
+ """Simulate a photo forwarded a few times on WhatsApp: slight tilt,
92
+ downscale, soft blur, heavy JPEG compression."""
93
+ bg = img.getpixel((2, 2))
94
+ img = img.rotate(rng.uniform(-2.5, 2.5), resample=Image.BICUBIC, expand=False, fillcolor=bg)
95
+ img = img.resize((int(img.width * scale), int(img.height * scale)), Image.BILINEAR)
96
+ img = img.filter(ImageFilter.GaussianBlur(0.4))
97
+ buf = io.BytesIO(); img.save(buf, "JPEG", quality=quality); buf.seek(0)
98
+ return Image.open(buf).convert("RGB")
99
+
100
+ class Writer:
101
+ def __init__(self, out):
102
+ self.out = out; self.rows = []
103
+ os.makedirs(os.path.join(out, "images"), exist_ok=True)
104
+ def add(self, id, family, sub, condition, img, prompt, answer, answer_type,
105
+ options=None, meta=None, max_new_tokens=32, jpeg=False):
106
+ rel = None
107
+ if img is not None:
108
+ ext = "jpg" if jpeg else "png"
109
+ rel = f"images/{id}.{ext}"
110
+ if jpeg: img.save(os.path.join(self.out, rel), "JPEG", quality=95)
111
+ else: img.save(os.path.join(self.out, rel))
112
+ self.rows.append(dict(id=id, family=family, subfamily=sub, condition=condition,
113
+ image=rel, prompt=prompt, answer=answer, answer_type=answer_type,
114
+ options=options, meta=meta or {}, max_new_tokens=max_new_tokens))
115
+ def save(self):
116
+ with open(os.path.join(self.out, "metadata.jsonl"), "w", encoding="utf-8") as f:
117
+ for r in self.rows: f.write(json.dumps(r, ensure_ascii=False) + "\n")
118
+ keys = ["id", "family", "subfamily", "condition", "image", "prompt", "answer",
119
+ "answer_type", "options", "meta", "max_new_tokens"]
120
+ with open(os.path.join(self.out, "metadata.csv"), "w", encoding="utf-8", newline="") as f:
121
+ w = csv.DictWriter(f, fieldnames=keys); w.writeheader()
122
+ for r in self.rows:
123
+ w.writerow({k: (json.dumps(r[k], ensure_ascii=False) if isinstance(r[k], (dict, list)) else r[k]) for k in keys})
124
+
125
+ TRANSCRIBE = ("Transcribe the text in this image exactly, character for character, "
126
+ "keeping every accent mark and every dot under a letter. Output only the text.")
127
+ LETTERS = "ABCDE"
128
+
129
+ # --------------------------------------------------------------------------
130
+ # Families
131
+ # --------------------------------------------------------------------------
132
+ def build_diacritics(W, rng):
133
+ """Family D: transcription of diacritic-bearing text under 4 conditions.
134
+ Conditions: size L (72px) / S (28px) x clean / wa (WhatsApp-degraded)."""
135
+ yo = [(w, g, "yo-minimal", grp) for grp, ws in YO_GROUPS.items() for (w, g) in ws]
136
+ yo += [(w, g, "yo-place", None) for (w, g) in YO_PLACES]
137
+ yo += [(w, g, "yo-phrase", None) for (w, g) in YO_PHRASES]
138
+ items = [("yo", NFC(w), g, kind, grp) for (w, g, kind, grp) in yo]
139
+ items += [("fr", NFC(w), None, "fr", None) for w in FR_WORDS]
140
+ items += [("vi", NFC(w), None, "vi", None) for w in VI_WORDS]
141
+ fonts = list(FONT_DIRS.items())
142
+ for i, (lang, text, gloss, kind, grp) in enumerate(items):
143
+ fname, fpath = fonts[i % len(fonts)]
144
+ scheme = SCHEMES[i % len(SCHEMES)]
145
+ conds = [("L", 72, False), ("L", 72, True), ("S", 28, False), ("S", 28, True)]
146
+ variants = [(text, lang, c) for c in conds]
147
+ if lang == "yo": # same word with marks stripped: isolates the marks
148
+ variants += [(strip_marks(text), "yo-ascii", ("L", 72, False)),
149
+ (strip_marks(text), "yo-ascii", ("S", 28, True))]
150
+ for (t, l, (sz, px, wa)) in variants:
151
+ cond = f"{sz}_{'wa' if wa else 'clean'}"
152
+ img = render_sign(t, fpath, px, scheme)
153
+ if wa: img = whatsapp(img, rng)
154
+ id = f"D_{l}_{i:02d}_{cond}"
155
+ W.add(id, "diacritics", l, cond, img, TRANSCRIBE, t, "transcribe",
156
+ meta=dict(lang=l, kind=kind, group=grp, gloss=gloss, font=fname, px=px,
157
+ degraded=wa, source_word=text),
158
+ max_new_tokens=40, jpeg=wa)
159
+
160
+ def mc_options(word, members, rng):
161
+ opts = list(dict.fromkeys([w for w, _ in members] + [strip_marks(word)]))
162
+ if len(opts) < 4: # add a plausible wrong-mark distractor
163
+ extra = {"ilé": "ìlé", "ilẹ̀": "ìlé", "ọ̀rọ̀": "ọ̀rọ", "ọrọ̀": "ọ̀rọ"}
164
+ opts.append(NFC(extra.get(word, word + "̀")))
165
+ opts = [NFC(o) for o in dict.fromkeys(opts)]
166
+ rng.shuffle(opts)
167
+ return opts
168
+
169
+ def build_minimal_pairs(W, rng):
170
+ """Family P: perception (multiple choice), meaning from image, meaning from
171
+ text only. Splits 'can't see the mark' from 'can't write it' from 'doesn't
172
+ know the word'."""
173
+ fonts = list(FONT_DIRS.values())
174
+ k = 0
175
+ for grp, members in YO_GROUPS.items():
176
+ for (w, gloss) in members:
177
+ w = NFC(w)
178
+ fpath = fonts[k % len(fonts)]; scheme = SCHEMES[k % len(SCHEMES)]; k += 1
179
+ opts = mc_options(w, [(NFC(a), b) for a, b in members], rng)
180
+ letter = LETTERS[opts.index(w)]
181
+ optstr = " ".join(f"{LETTERS[j]}) {o}" for j, o in enumerate(opts))
182
+ q = ("Which option exactly matches the word in the image, including all tone marks "
183
+ f"and dots under letters? {optstr}. Answer with the letter only.")
184
+ for cond, px, wa in [("L_clean", 72, False), ("S_wa", 28, True)]:
185
+ img = render_sign(w, fpath, px, scheme)
186
+ if wa: img = whatsapp(img, rng)
187
+ W.add(f"P_mc_{grp}_{k:02d}_{cond}", "minimal_pairs", "mc_spelling", cond, img, q,
188
+ letter, "mc", options=opts,
189
+ meta=dict(group=grp, word=w, gloss=gloss, chance=1 / len(opts)),
190
+ max_new_tokens=8, jpeg=wa)
191
+ if grp in ("oko", "igba"):
192
+ glosses = [g for _, g in members]
193
+ gl = glosses[:]; rng.shuffle(gl)
194
+ gletter = LETTERS[gl.index(gloss)]
195
+ gstr = " ".join(f"{LETTERS[j]}) {o}" for j, o in enumerate(gl))
196
+ img = render_sign(w, fpath, 72, scheme)
197
+ W.add(f"P_mean_img_{grp}_{k:02d}", "minimal_pairs", "meaning_from_image", "L_clean", img,
198
+ f"The image shows a Yoruba word. What does it mean? {gstr}. Answer with the letter only.",
199
+ gletter, "mc", options=gl, meta=dict(group=grp, word=w, gloss=gloss, chance=1 / len(gl)),
200
+ max_new_tokens=8)
201
+ W.add(f"P_mean_txt_{grp}_{k:02d}", "minimal_pairs", "meaning_from_text", "text_only", None,
202
+ f"What does the Yoruba word \"{w}\" mean? {gstr}. Answer with the letter only.",
203
+ gletter, "mc", options=gl, meta=dict(group=grp, word=w, gloss=gloss, chance=1 / len(gl)),
204
+ max_new_tokens=8)
205
+
206
+ def price_tag(product, price_text, ctx=None, scheme=None, W=640, H=400):
207
+ bg, fg = scheme or ((255, 255, 255), (15, 15, 15))
208
+ img = Image.new("RGB", (W, H), bg); d = ImageDraw.Draw(img)
209
+ d.rectangle([10, 10, W - 10, H - 10], outline=fg, width=4)
210
+ if ctx:
211
+ f = font(SANS, 24); tw = d.textlength(ctx, font=f)
212
+ d.text(((W - tw) / 2, 30), ctx, font=f, fill=fg)
213
+ f = font(SANS, 40); tw = d.textlength(product, font=f)
214
+ d.text(((W - tw) / 2, 110), product, font=f, fill=fg)
215
+ f = font(SANS_B, 96); tw = d.textlength(price_text, font=f)
216
+ d.text(((W - tw) / 2, 200), price_text, font=f, fill=fg)
217
+ return img
218
+
219
+ def build_currency(W, rng):
220
+ """Family C: currency symbol fidelity. ₦ vs $, £, € on identical tags."""
221
+ products = ["Bread", "Rice 5kg", "Phone charger", "Notebook"]
222
+ amounts = ["500", "1,200", "2,500", "15,000"]
223
+ cur = {"₦": "NGN", "$": "USD", "£": "GBP", "€": "EUR"}
224
+ q = ("What is the price on this tag? Reply with the currency symbol and the amount "
225
+ "exactly as written, nothing else.")
226
+ k = 0
227
+ for p, a in zip(products, amounts):
228
+ for sym, code in cur.items():
229
+ for wa in (False, True):
230
+ img = price_tag(p, f"{sym}{a}", scheme=SCHEMES[k % 2]); k += 1
231
+ if wa: img = whatsapp(img, rng, scale=0.6, quality=35)
232
+ cond = "wa" if wa else "clean"
233
+ W.add(f"C_sym_{code}_{a.replace(',', '')}_{cond}", "currency", f"symbol_{code}", cond, img, q,
234
+ dict(currency=code, amount=int(a.replace(",", ""))), "currency_amount",
235
+ meta=dict(symbol=sym, product=p), max_new_tokens=16, jpeg=wa)
236
+ # Naming the currency: the ₦ glyph alone, and the two ways Nigerians type
237
+ # naira on keyboards without ₦ — "N2,500" and "#2,500" — in a Nigerian context.
238
+ qn = "Which currency is this price in? Answer with the currency name only."
239
+ for p, a in zip(products, amounts):
240
+ W.add(f"C_name_glyph_{a.replace(',', '')}", "currency", "name_glyph", "clean",
241
+ price_tag(p, f"₦{a}"), qn, "naira", "currency_name", meta=dict(written=f"₦{a}"), max_new_tokens=8)
242
+ for pre, tag in (("N", "Nprefix"), ("#", "hash")):
243
+ img = price_tag(p, f"{pre}{a}", ctx="Bodija Market, Ibadan, Oyo State")
244
+ W.add(f"C_name_{tag}_{a.replace(',', '')}", "currency", f"name_{tag}", "ng_context", img, qn,
245
+ "naira", "currency_name", meta=dict(written=f"{pre}{a}"), max_new_tokens=8)
246
+
247
+ def fmt_money(v, sym, dec):
248
+ return f"{sym}{v:,.2f}" if dec else f"{sym}{v:,}"
249
+
250
+ def receipt(shop, addr, tel, items, sym, dec, date=None, W=560):
251
+ lines = len(items) + 9
252
+ H = 70 + lines * 34
253
+ img = Image.new("RGB", (W, H), (252, 252, 247)); d = ImageDraw.Draw(img)
254
+ fb, f = font(MONO_B, 22), font(MONO, 19)
255
+ y = 22
256
+ for t, ff in ((shop, fb), (addr, f), (tel, f)):
257
+ tw = d.textlength(t, font=ff); d.text(((W - tw) / 2, y), t, font=ff, fill=(20, 20, 20)); y += 32
258
+ if date:
259
+ d.text((24, y), f"Date: {date}", font=f, fill=(20, 20, 20)); y += 32
260
+ d.text((24, y), "-" * 44, font=f, fill=(60, 60, 60)); y += 30
261
+ total = 0
262
+ for name, qty, price in items:
263
+ total += qty * price
264
+ d.text((24, y), f"{qty} x {name}", font=f, fill=(20, 20, 20))
265
+ s = fmt_money(qty * price, sym, dec); tw = d.textlength(s, font=f)
266
+ d.text((W - 24 - tw, y), s, font=f, fill=(20, 20, 20)); y += 32
267
+ d.text((24, y), "-" * 44, font=f, fill=(60, 60, 60)); y += 30
268
+ s = fmt_money(total, sym, dec); tw = d.textlength(s, font=fb)
269
+ d.text((24, y), "TOTAL", font=fb, fill=(10, 10, 10)); d.text((W - 24 - tw, y), s, font=fb, fill=(10, 10, 10))
270
+ y += 40
271
+ d.text((24, y), "Thank you for your patronage!", font=f, fill=(40, 40, 40))
272
+ return img.crop((0, 0, W, min(H, y + 46))), total
273
+
274
+ NG_ITEMS = [("Peak Milk 400g", 3200), ("Indomie (carton)", 9500), ("Semovita 1kg", 1800),
275
+ ("Garri (paint rubber)", 2500), ("Ofada rice 1kg", 2200), ("Titus sardine", 1400),
276
+ ("Golden Penny spaghetti", 1100), ("Palm oil 1L", 2600), ("Milo 500g", 4100)]
277
+ US_ITEMS = [("Milk 1 gal", 4.29), ("Eggs dozen", 3.89), ("Bread loaf", 2.99), ("Bananas 2lb", 1.38),
278
+ ("Cereal box", 5.49), ("Coffee 12oz", 8.99), ("Apples 3lb", 4.97), ("Butter 1lb", 4.59), ("Rice 2lb", 2.79)]
279
+
280
+ def build_receipts(W, rng):
281
+ """Family R: false-premise (leading) questions on receipts.
282
+ Nigerian ₦ receipts vs US $ receipts, identical layout and question form."""
283
+ for loc in ("NG", "US"):
284
+ for k in range(6):
285
+ pool = NG_ITEMS if loc == "NG" else US_ITEMS
286
+ chosen = rng.sample(pool, 4)
287
+ items = [(n, rng.randint(1, 3), p) for n, p in chosen]
288
+ if loc == "NG":
289
+ img, total = receipt("BODIJA PROVISIONS STORE", "Bodija Market, Ibadan", "Tel: +234 803 555 0142",
290
+ items, "₦", False)
291
+ true_code, sym = "NGN", "₦"
292
+ else:
293
+ img, total = receipt("CORNER GROCERY", "Congress Ave, Austin TX", "Tel: (512) 555-0142",
294
+ items, "$", True)
295
+ true_code, sym = "USD", "$"
296
+ total = round(total, 2)
297
+ kind = "wrong_currency" if k < 3 else "wrong_amount"
298
+ if kind == "wrong_currency":
299
+ fake = fmt_money(total, "$" if loc == "NG" else "€", loc == "US")
300
+ else:
301
+ delta = rng.choice([0.8, 0.9, 1.15, 1.25])
302
+ fv = round(total * delta, 2) if loc == "US" else int(round(total * delta, -2))
303
+ fake = fmt_money(fv, sym, loc == "US")
304
+ base = f"R_{loc}_{k}"
305
+ W.add(base + "_neutral", "receipts", f"neutral_{loc}", loc, img,
306
+ "What is the total amount on this receipt? Give the currency symbol and the amount.",
307
+ dict(currency=true_code, amount=total), "currency_amount",
308
+ meta=dict(locale=loc, items=[list(x) for x in items]), max_new_tokens=24)
309
+ W.add(base + "_leading", "receipts", f"leading_{loc}", loc, img,
310
+ f"The total on this receipt is {fake}. Is that correct? Answer YES or NO first, then state the correct total.",
311
+ dict(expected="NO", currency=true_code, amount=total), "premise",
312
+ meta=dict(locale=loc, premise=fake, premise_kind=kind), max_new_tokens=48)
313
+
314
+ MONTHS = ["January", "February", "March", "April", "May", "June", "July", "August",
315
+ "September", "October", "November", "December"]
316
+
317
+ def build_dates(W, rng):
318
+ """Family T: locale-consistent date reading (DD/MM in Nigeria vs MM/DD in the US)."""
319
+ ng_amb = [(3, 4, 2026), (5, 11, 2025), (7, 2, 2026), (10, 6, 2026), (2, 9, 2025), (8, 12, 2025)]
320
+ ng_unamb = [(15, 4, 2026), (23, 11, 2025), (28, 2, 2026), (19, 7, 2026)]
321
+ q = "In which month was this invoice issued? Answer with the month name only."
322
+ def make(loc, s, k):
323
+ if loc == "NG":
324
+ items = [(n, 1, p) for n, p in rng.sample(NG_ITEMS, 3)]
325
+ return receipt("ADEYEMI & SONS VENTURES", "Ring Road, Ibadan, Oyo State, Nigeria",
326
+ "Tel: +234 802 555 0187", items, "₦", False, date=s)[0]
327
+ items = [(n, 1, p) for n, p in rng.sample(US_ITEMS, 3)]
328
+ return receipt("LONE STAR SUPPLY CO.", "Lamar Blvd, Austin, TX, USA",
329
+ "Tel: (512) 555-0187", items, "$", True, date=s)[0]
330
+ for k, (d, m, y) in enumerate(ng_amb):
331
+ s = f"{d:02d}/{m:02d}/{y}"
332
+ W.add(f"T_NG_amb_{k}", "dates", "ng_ambiguous", "NG", make("NG", s, k), q, MONTHS[m - 1], "month",
333
+ meta=dict(date=s, locale_month=MONTHS[m - 1], other_reading=MONTHS[d - 1]), max_new_tokens=8)
334
+ for k, (d, m, y) in enumerate(ng_unamb):
335
+ s = f"{d:02d}/{m:02d}/{y}"
336
+ W.add(f"T_NG_unamb_{k}", "dates", "ng_unambiguous", "NG", make("NG", s, k), q, MONTHS[m - 1], "month",
337
+ meta=dict(date=s), max_new_tokens=8)
338
+ for k, (d, m, y) in enumerate(ng_amb): # same strings, US reading = MM/DD
339
+ s = f"{d:02d}/{m:02d}/{y}"
340
+ W.add(f"T_US_amb_{k}", "dates", "us_ambiguous", "US", make("US", s, k), q, MONTHS[d - 1], "month",
341
+ meta=dict(date=s, locale_month=MONTHS[d - 1], other_reading=MONTHS[m - 1]), max_new_tokens=8)
342
+
343
+ def build_known_controls(W, rng):
344
+ """Family K: well-documented VLM weaknesses, kept as calibration so the
345
+ headline gap can be compared against known ones (from the first notebook)."""
346
+ for n in [3, 5, 8, 12, 16, 24, 32]:
347
+ for s in range(2):
348
+ img = Image.new("RGB", (512, 512), "white"); d = ImageDraw.Draw(img)
349
+ pts = []
350
+ while len(pts) < n:
351
+ x, y = rng.randint(30, 482), rng.randint(30, 482)
352
+ if all((x - a) ** 2 + (y - b) ** 2 > 34 ** 2 for a, b in pts): pts.append((x, y))
353
+ for x, y in pts: d.ellipse([x - 12, y - 12, x + 12, y + 12], fill=(220, 30, 30))
354
+ W.add(f"K_count_{n:02d}_{s}", "known_controls", "counting", f"n={n}", img,
355
+ "How many red dots are in this image? Answer with a single number.", n, "count",
356
+ meta=dict(n=n), max_new_tokens=8)
357
+ for k in range(8):
358
+ red_left = k % 2 == 0
359
+ img = Image.new("RGB", (640, 360), "white"); d = ImageDraw.Draw(img)
360
+ sz = rng.randint(50, 110); y1, y2 = rng.randint(40, 200), rng.randint(40, 200)
361
+ lx, rx = rng.randint(40, 200), rng.randint(380, 520)
362
+ cl, cr = ((220, 30, 30), (30, 60, 220)) if red_left else ((30, 60, 220), (220, 30, 30))
363
+ d.rectangle([lx, y1, lx + sz, y1 + sz], fill=cl); d.rectangle([rx, y2, rx + sz, y2 + sz], fill=cr)
364
+ W.add(f"K_spatial_{k}", "known_controls", "left_right", "clean", img,
365
+ "Is the red square on the left or the right side of the image? Answer with one word.",
366
+ "left" if red_left else "right", "leftright", max_new_tokens=6)
367
+ menus = [[("Jollof rice & chicken", "8.50"), ("Fried plantain", "3.00"), ("Pepper soup", "6.00"), ("Chapman", "2.50")],
368
+ [("Grilled fish", "12.00"), ("Caesar salad", "7.50"), ("Lemonade", "2.00"), ("Fruit cup", "3.50")],
369
+ [("Veggie wrap", "6.50"), ("Tomato soup", "4.00"), ("Iced tea", "2.25"), ("Brownie", "3.25")]]
370
+ for k, m in enumerate(menus):
371
+ img = Image.new("RGB", (560, 340), (255, 250, 235)); d = ImageDraw.Draw(img)
372
+ d.text((24, 20), "TODAY'S MENU", font=font(SANS_B, 30), fill=(60, 30, 10))
373
+ for j, (name, price) in enumerate(m):
374
+ d.text((24, 90 + j * 52), name, font=font(SANS, 26), fill=(20, 20, 20))
375
+ p = f"${price}"; tw = d.textlength(p, font=font(SANS, 26))
376
+ d.text((536 - tw, 90 + j * 52), p, font=font(SANS, 26), fill=(20, 20, 20))
377
+ W.add(f"K_menu_{k}_neutral", "known_controls", "menu_transcribe", "clean", img,
378
+ "List every item on this menu with its price, one per line.",
379
+ [n for n, _ in m], "menu_items", meta=dict(menu=m), max_new_tokens=96)
380
+ W.add(f"K_menu_{k}_leading", "known_controls", "menu_false_premise", "clean", img,
381
+ "The menu lists a Cheeseburger for $5. Is that correct? Answer YES or NO first, then explain briefly.",
382
+ dict(expected="NO"), "premise", meta=dict(premise="Cheeseburger $5"), max_new_tokens=40)
383
+
384
+ def main():
385
+ ap = argparse.ArgumentParser()
386
+ ap.add_argument("--out", default="data"); ap.add_argument("--seed", type=int, default=7)
387
+ a = ap.parse_args()
388
+ if not features.check("raqm"):
389
+ raise SystemExit("Pillow lacks libraqm: Yoruba stacked marks would render wrongly.")
390
+ rng = random.Random(a.seed)
391
+ W = Writer(a.out)
392
+ build_diacritics(W, rng); build_minimal_pairs(W, rng); build_currency(W, rng)
393
+ build_receipts(W, rng); build_dates(W, rng); build_known_controls(W, rng)
394
+ W.save()
395
+ from collections import Counter
396
+ c = Counter((r["family"], r["subfamily"]) for r in W.rows)
397
+ for k, v in sorted(c.items()): print(f"{k[0]:16s} {k[1]:22s} {v}")
398
+ print("TOTAL", len(W.rows))
399
+
400
+ if __name__ == "__main__":
401
+ main()
vision-gap/data/images/C_name_Nprefix_1200.png ADDED

Git LFS Details

  • SHA256: 3b3d79eeba331f7584f9afad953ff4238188ecd7d050387d611bc8c4a2461fe5
  • Pointer size: 130 Bytes
  • Size of remote file: 15.7 kB
vision-gap/data/images/C_name_Nprefix_15000.png ADDED

Git LFS Details

  • SHA256: 2208ab8cc6dda3425dabde2866502238c311a4330003fb63eed97c33a1fc7e0f
  • Pointer size: 130 Bytes
  • Size of remote file: 15.3 kB
vision-gap/data/images/C_name_Nprefix_2500.png ADDED

Git LFS Details

  • SHA256: 6c92a6389be0ba127e7ab89849098d85ceafe411277ec71f2582886512ab7b14
  • Pointer size: 130 Bytes
  • Size of remote file: 17.3 kB
vision-gap/data/images/C_name_Nprefix_500.png ADDED

Git LFS Details

  • SHA256: cdf39aead4d78f18c221d944b1d68a6ee53dff89ccc4c8f606491529dbabb86b
  • Pointer size: 130 Bytes
  • Size of remote file: 14.1 kB
vision-gap/data/images/C_name_glyph_1200.png ADDED

Git LFS Details

  • SHA256: 94fc3074abf5016e709f65453f2f77a199394312936308cd6d65ff8f46fbc1d6
  • Pointer size: 130 Bytes
  • Size of remote file: 10.8 kB
vision-gap/data/images/C_name_glyph_15000.png ADDED

Git LFS Details

  • SHA256: 2fa7bbb540fed55fe9c06907a0d298a7e735316622b957e0f3f3d0b7b8e70d92
  • Pointer size: 130 Bytes
  • Size of remote file: 10.4 kB
vision-gap/data/images/C_name_glyph_2500.png ADDED

Git LFS Details

  • SHA256: 94802a2b6e7cf32f39b04c2bb5fe9c865e2a478d0964db61063fd0cfd2f4809f
  • Pointer size: 130 Bytes
  • Size of remote file: 12.4 kB
vision-gap/data/images/C_name_glyph_500.png ADDED

Git LFS Details

  • SHA256: 6ac9b07eed1bcd6e263f34607e9b79a83856a2c5c9e61db7b8b59c23dc5f9090
  • Pointer size: 129 Bytes
  • Size of remote file: 9.23 kB
vision-gap/data/images/C_name_hash_1200.png ADDED

Git LFS Details

  • SHA256: 0f13a4682953f822e52be7c3d34e4cfd578f94f02649a638b93be1b01a25118e
  • Pointer size: 130 Bytes
  • Size of remote file: 15.6 kB
vision-gap/data/images/C_name_hash_15000.png ADDED

Git LFS Details

  • SHA256: d798701eea4c1da1fd18cb741d7ae07a940130609839a2bd8cda6415a892b34f
  • Pointer size: 130 Bytes
  • Size of remote file: 15.2 kB
vision-gap/data/images/C_name_hash_2500.png ADDED

Git LFS Details

  • SHA256: 9a2cd6966658051082f6c39d2ad97ff5631bfb7ce685bc56708f6cb5ac282cb8
  • Pointer size: 130 Bytes
  • Size of remote file: 17.2 kB
vision-gap/data/images/C_name_hash_500.png ADDED

Git LFS Details

  • SHA256: ea5db7588434c418c7b881c3331a0fc1ba8a80c6273a08227da669ffe9b60a2e
  • Pointer size: 130 Bytes
  • Size of remote file: 14.1 kB
vision-gap/data/images/C_sym_EUR_1200_clean.png ADDED

Git LFS Details

  • SHA256: 28eed334c9abfdd913353ba8f50eb7ba87b3d9a41bad272f985f805387045657
  • Pointer size: 130 Bytes
  • Size of remote file: 12.1 kB
vision-gap/data/images/C_sym_EUR_1200_wa.jpg ADDED

Git LFS Details

  • SHA256: 01ec043e49651b9da24366fa2bf77412a517348031d948d9c8b9a756981ab8ee
  • Pointer size: 130 Bytes
  • Size of remote file: 13.1 kB
vision-gap/data/images/C_sym_EUR_15000_clean.png ADDED

Git LFS Details

  • SHA256: a4ccbe9f6972bf33e19ca4ee0bdc05e938022a1d3cc5e658f4ac684496a6c80e
  • Pointer size: 130 Bytes
  • Size of remote file: 11.7 kB
vision-gap/data/images/C_sym_EUR_15000_wa.jpg ADDED

Git LFS Details

  • SHA256: 056f8850c6f4c11fafe352ba334db69965e2b800192ca69ecbf36230bea628a9
  • Pointer size: 130 Bytes
  • Size of remote file: 14.3 kB
vision-gap/data/images/C_sym_EUR_2500_clean.png ADDED

Git LFS Details

  • SHA256: 52ea6d908049a1c253e59bcc38e45a1893e9bca55d7bbff8c31b9fbb9ca1b153
  • Pointer size: 130 Bytes
  • Size of remote file: 13.8 kB
vision-gap/data/images/C_sym_EUR_2500_wa.jpg ADDED

Git LFS Details

  • SHA256: e73097b2a9a6c8ff801afe809d4e2cd98309742c3f13809276636b699f5417aa
  • Pointer size: 130 Bytes
  • Size of remote file: 14.2 kB
vision-gap/data/images/C_sym_EUR_500_clean.png ADDED

Git LFS Details

  • SHA256: 54d899de272ad6604b7ed89ba9960c7e50bfa001f32a26c68ff991393b977dd0
  • Pointer size: 130 Bytes
  • Size of remote file: 10.3 kB
vision-gap/data/images/C_sym_EUR_500_wa.jpg ADDED

Git LFS Details

  • SHA256: 4ec1fb1f834795a9b8e29fd0c1fa5bfcb9c04ee7e71997ca66a4d272c3b1dabb
  • Pointer size: 130 Bytes
  • Size of remote file: 11.8 kB
vision-gap/data/images/C_sym_GBP_1200_clean.png ADDED

Git LFS Details

  • SHA256: 07c88338e1e1d5c8628d311c4858b839bf6b9ffd84d6a768371eb46702acc7ef
  • Pointer size: 130 Bytes
  • Size of remote file: 11 kB
vision-gap/data/images/C_sym_GBP_1200_wa.jpg ADDED

Git LFS Details

  • SHA256: f7bb988149e06f8f0805a11f426d061b8e08b507e6ce8381324f6edd9617dfeb
  • Pointer size: 130 Bytes
  • Size of remote file: 13 kB
vision-gap/data/images/C_sym_GBP_15000_clean.png ADDED

Git LFS Details

  • SHA256: ad3288be68c69d66bb618c601da0d29605a854222d74dd9434a1a7a30d3a9438
  • Pointer size: 130 Bytes
  • Size of remote file: 10.7 kB
vision-gap/data/images/C_sym_GBP_15000_wa.jpg ADDED

Git LFS Details

  • SHA256: feeb3ab58a5554a67172873ab06e3197bc86544fd7189f6b59a7eb1a45fdd1c6
  • Pointer size: 130 Bytes
  • Size of remote file: 14.2 kB
vision-gap/data/images/C_sym_GBP_2500_clean.png ADDED

Git LFS Details

  • SHA256: 7959d4210a8937bf7d1b88c53cef9614eec5919e08846f0f357144bda69ba82b
  • Pointer size: 130 Bytes
  • Size of remote file: 12.7 kB
vision-gap/data/images/C_sym_GBP_2500_wa.jpg ADDED

Git LFS Details

  • SHA256: 3823ee97718d171d99ccb4ccb088620e86a3eb4ecbb187cc812a3c0c60da1998
  • Pointer size: 130 Bytes
  • Size of remote file: 14.2 kB
vision-gap/data/images/C_sym_GBP_500_clean.png ADDED

Git LFS Details

  • SHA256: d4c92668b60a8ca2f6c89b28fa303fae26fac9ef5947c9c48b35fe65a365818e
  • Pointer size: 129 Bytes
  • Size of remote file: 9.31 kB
vision-gap/data/images/C_sym_GBP_500_wa.jpg ADDED

Git LFS Details

  • SHA256: 241b997cd7fe70eaf25134d9be0fdcf0ffb2ab9386bb63320ebbd31cab839713
  • Pointer size: 130 Bytes
  • Size of remote file: 11.7 kB
vision-gap/data/images/C_sym_NGN_1200_clean.png ADDED

Git LFS Details

  • SHA256: 7f60a4fe382a12fd14e6c4bbef1b8008df011e9e15da36b85c82608f15b3c39a
  • Pointer size: 130 Bytes
  • Size of remote file: 11.2 kB
vision-gap/data/images/C_sym_NGN_1200_wa.jpg ADDED

Git LFS Details

  • SHA256: 4d001fbff8843274a3af160ceaf7ee39d6522b27a284322cc6d3632e84cffd93
  • Pointer size: 130 Bytes
  • Size of remote file: 13.1 kB
vision-gap/data/images/C_sym_NGN_15000_clean.png ADDED

Git LFS Details

  • SHA256: 07644c09c2f37f8960f66ef65ef7082191ae1b0812c2fe1378c72027cacabb95
  • Pointer size: 130 Bytes
  • Size of remote file: 10.9 kB
vision-gap/data/images/C_sym_NGN_15000_wa.jpg ADDED

Git LFS Details

  • SHA256: 3796bce2f357269bf2debbb56d1d564ac24211a8bda1a99e2275892e0464a3e7
  • Pointer size: 130 Bytes
  • Size of remote file: 14.4 kB
vision-gap/data/images/C_sym_NGN_2500_clean.png ADDED

Git LFS Details

  • SHA256: 0d52f40f1e00f0f938e9c745107f55b127f8d07a33c2a23d091fc6ebcd8ab4c5
  • Pointer size: 130 Bytes
  • Size of remote file: 13 kB
vision-gap/data/images/C_sym_NGN_2500_wa.jpg ADDED

Git LFS Details

  • SHA256: 78af6e43cc40ac01626011990ac7eb664a836867eee43cfffecb8f00ab532365
  • Pointer size: 130 Bytes
  • Size of remote file: 14.2 kB
vision-gap/data/images/C_sym_NGN_500_clean.png ADDED

Git LFS Details

  • SHA256: b50415d6fdbf8f983136bc977c1a795630a9fcfd951ab69092248c044578677e
  • Pointer size: 129 Bytes
  • Size of remote file: 9.58 kB
vision-gap/data/images/C_sym_NGN_500_wa.jpg ADDED

Git LFS Details

  • SHA256: fb12317f09da2c814aeacc8d22106a9b25f9f9bfa57658f9c7816afd0211f455
  • Pointer size: 130 Bytes
  • Size of remote file: 11.8 kB
vision-gap/data/images/C_sym_USD_1200_clean.png ADDED

Git LFS Details

  • SHA256: 5d208653583a3276a66f649fe803288479e3a9a53bf7274ff00e2c08829d55b0
  • Pointer size: 130 Bytes
  • Size of remote file: 12.4 kB
vision-gap/data/images/C_sym_USD_1200_wa.jpg ADDED

Git LFS Details

  • SHA256: 2060d4c9fd5b25c041ca43136415bc431e56364f801978095994ee64a8f2c1ae
  • Pointer size: 130 Bytes
  • Size of remote file: 13.1 kB
vision-gap/data/images/C_sym_USD_15000_clean.png ADDED

Git LFS Details

  • SHA256: 9af6ea5d3d8afe81202e5d9cf4afdff86d2ec48201fd4b2a161b3ac0b4b1fa84
  • Pointer size: 130 Bytes
  • Size of remote file: 11.9 kB
vision-gap/data/images/C_sym_USD_15000_wa.jpg ADDED

Git LFS Details

  • SHA256: 485bf790888a283858d0769833d7113f183e206633a6f965f0d1fad24796331f
  • Pointer size: 130 Bytes
  • Size of remote file: 14.4 kB
vision-gap/data/images/C_sym_USD_2500_clean.png ADDED

Git LFS Details

  • SHA256: cc1abe658f4c4b6550ba10ea86186ec74ee367636d470fb5de7c3568dc190b0b
  • Pointer size: 130 Bytes
  • Size of remote file: 14.1 kB
vision-gap/data/images/C_sym_USD_2500_wa.jpg ADDED

Git LFS Details

  • SHA256: 0eab8b51221733aa207438ced79304f1e54f3371dea4977f5327e4698b803b40
  • Pointer size: 130 Bytes
  • Size of remote file: 14.4 kB
vision-gap/data/images/C_sym_USD_500_clean.png ADDED

Git LFS Details

  • SHA256: 046ffe31dd77d0df26410d963242ebdba40d50587e4dc8ee0c4982fb467b85e2
  • Pointer size: 130 Bytes
  • Size of remote file: 10.6 kB
vision-gap/data/images/C_sym_USD_500_wa.jpg ADDED

Git LFS Details

  • SHA256: 06a0f37ceceb57be6f7a00c882de6ce2608390518fa29c3d87c880bedf7147ab
  • Pointer size: 130 Bytes
  • Size of remote file: 11.8 kB
vision-gap/data/images/D_fr_24_L_clean.png ADDED

Git LFS Details

  • SHA256: bf499af6fbef21409e0ab8ee1b3cac6c164031d9ac7853b58ca29cfe550c0337
  • Pointer size: 129 Bytes
  • Size of remote file: 6 kB