Egyptian receipts to JSON (Arabic Nougat, full fine-tune)
masterofaudio2077/arabic-nougat-base-books-ocr fine-tuned on
masterofaudio2077/egyptian-receipts-ocr (CC-BY-4.0) to turn a receipt image into JSON:
merchant, merchant_en, address, receipt_no, date, total and items[{name, qty, unit_price, amount}],
every value copied as printed (Indic digits stay Indic).
Versions
This card describes version 2 (main). Version 1 is kept on the branch v1-invents-header:
VisionEncoderDecoderModel.from_pretrained("masterofaudio2077/arabic-nougat-egyptian-receipts-json", revision="v1-invents-header").
Version 1 was trained for 1,356 steps on complete receipts only. On the one real photo tried (a close-up of a bill with no header) it invented a merchant and an address, repeated the address key three times, returned 2 of 5 items and gave a total of 366.45 for a printed 296.46. Cutting lines off that photo showed the cause: the merchant it returned was always the first printed line, because every training receipt had a header.
Version 2 trains for 2000 steps and cuts the header and/or footer off 40% of the training receipts at random, rewriting the target to the fields still visible. Its "json valid" is stricter (a repeated key is invalid), so it is not directly comparable with the 97.5% of version 1.
Real-photo check (one REAL photo, not synthetic)
Every number further down this card is measured on synthetic receipts. This is the one real photo tried so far: a close-up of a restaurant bill (items and totals only, no header). It is a single image, so it shows what happens on one real receipt; it is not a measurement.

Version 2 (this version), output as generated (greedy decoding, fp32 on CPU):
{"total":"296.46","items":[{"name":"بطاطس محمرة","qty":"1","amount":"57.8"},{"name":"كوفير","qty":"2","amount":"67.5"}]}
Against what the photo prints (read by hand) and against version 1 (branch v1-invents-header):
| field | printed | version 1 | version 2 |
|---|---|---|---|
| merchant | not in the photo | أرز البضرة (invented) | absent |
| address | not in the photo | invented, key repeated 3 times | absent |
| total | 296.46 | 366.45 | 296.46 |
| items returned | 5 | 2 | 2 |
| أرز أبيض, qty 1, 51.7 | missing | missing | |
| ملوخية سادة, qty 1, 57.8 | missing | missing | |
| بامية سادة, qty 1, 67.5 | missing | missing | |
| بطاطس محمرة, qty 1, 47.3 | بطاطس معمرة, 1, 47.3 | بطاطس محمرة, 1, 57.8 (name right, amount wrong) | |
| كوفير, qty 2, 0.00 | كوفير-بيت, 2, 0.00 | كوفير, 2, 67.5 (name right, amount wrong) |
Fixed: the invented merchant and address. Version 2 returned neither in any of 4 runs on this photo (the full photo and 3 crops with the top lines cut off). Version 1 turned the first printed line into the merchant every time. The total on the full photo is exact.
Not fixed: the items. Three of five are missing, and the two it returned carry amounts that belong to other rows (57.8 is the amount of
ملوخية سادة, 67.5 the amount of بامية سادة). With the top lines cut off, the totals came back as 295.46 and 296.45, one digit off. On a crop that
shows no total at all, it returned 67.3 as the total, which is invented. Item names are spelled better than in version 1, but the numbers
are attached to the wrong rows. Do not rely on item amounts from real photos without checking them.
The synthetic results below do not predict this: this bill uses a POS bitmap font, -.- marks after the names and English Total / Discount / Service / Tax labels,
none of which the synthetic data has.
Results on SYNTHETIC test receipts (greedy decoding)
| test rows | n | json valid | numbers exact | item-name CER | page CER | total exact | date exact | receipt_no exact | merchant invented | address invented |
|---|---|---|---|---|---|---|---|---|---|---|
| all | 433 | 98.2% | 87.0% | 0.367 | 0.096 | 86.2% | 78.0% | 74.8% | 0.0% | n/a |
| legible (>= 8 px) | 409 | 98.8% | 89.7% | 0.284 | 0.072 | 89.6% | 81.4% | 78.2% | 0.0% | n/a |
| cut: header/footer removed | 160 | 98.1% | 85.0% | 0.429 | 0.132 | 87.5% | 73.9% | 69.2% | 1.6% | 1.0% |
json valid: parses, has an items list and repeats no key. invented: on receipts whose target has no merchant (or address), the share of
outputs that have one anyway; only the cut rows can show it.
All training and test data is synthetic and unverified (annotation_source: synthetic_exact). There are no real photos in the test set above.
Examples from the SYNTHETIC test set (the first 3 test receipts, then the first 2 cut ones; none selected)
clothing-0000044: valid JSON, page CER 0.015

Target
{"merchant":"محل شريف","address":"سوق العبور التجاري، حي شرق شبرا الخيمة، القليوبية","receipt_no":"426/41259","date":"2025-01-17","total":"810","items":[{"name":"طقم داخلي حريمي كود ST-900 مقاس XL","qty":"1","unit_price":"680","amount":"680"},{"name":"بوكسر رجالي كود BX-12 مقاس L","qty":"2","unit_price":"65","amount":"130"}]}
Model output
{"merchant":"محل شريف","address":"سوق العبور التجاري، حي شرق شبرا الخيمة، القليوبية","receipt_no":"426/41259","date":"2025-01-17","total":"816","items":[{"name":"طقم داخلي حريمي كود B-900 مقاس XL","qty":"1","unit_price":"680","amount":"680"},{"name":"بوكسر رجالي كود M-12 مقاس L","qty":"2","unit_price":"65","amount":"130"}]}
clothing-0000175: valid JSON, page CER 0.027

Target
{"merchant":"أزياء باب الشعرية","merchant_en":"Bab El Shaaria Menswear","address":"شارع الجيش، بجوار مسجد الشعراني، باب الشعرية، القاهرة","receipt_no":"213/12076","date":"17.12.2024","total":"1949.40","items":[{"name":"جاكيت جلد رجالي مستورد","qty":"1","unit_price":"1250.00","amount":"1250.00"},{"name":"تيش رجالي قطن L","qty":"2","unit_price":"85.00","amount":"170.00"},{"name":"شراب رجالي 3 قطع","qty":"1","unit_price":"35.00","amount":"35.00"},{"name":"كاب رجالي","qty":"1","unit_price":"55.00","amount":"55.00"},{"name":"بوك رجالي جلد","qty":"1","unit_price":"90.00","amount":"90.00"},{"name":"حزام رجالي 120سم","qty":"1","unit_price":"110.00","amount":"110.00"}]}
Model output
{"merchant":"أزياء باب الشعرية","merchant_en":"El Baraka El Eman Heirs","address":"شارع الجيش، بجوار مسجد الشعراني، باب الشعرية، القاهرة","receipt_no":"213/12076","date":"17.12.2024","total":"1949.40","items":[{"name":"جاكيت جلد رجالي مستورد","qty":"1","unit_price":"1250.00","amount":"1250.00"},{"name":"تيش رجالي قطن L","qty":"2","unit_price":"85.00","amount":"170.00"},{"name":"شراب رجالي 3 قطع","qty":"1","unit_price":"35.00","amount":"35.00"},{"name":"كاب رجالي","qty":"1","unit_price":"55.00","amount":"55.00"},{"name":"بوك رجالي جلد","qty":"1","unit_price":"90.00","amount":"90.00"},{"name":"حزام رجالي 120سم","qty":"1","unit_price":"110.00","amount":"110.00"}]}
clothing-0000203: valid JSON, page CER 0.009

Target
{"merchant":"ستايل بوينت","address":"شارع المحكمة، بجوار موقف الأتوبيس، كفر الدوار، البحيرة","receipt_no":"8134947","date":"22/05/2025","total":"232.56","items":[{"name":"بوكسر رجالي قطن أبيض مقاس XL ماركة محلية","qty":"1","unit_price":"95","amount":"95"},{"name":"فانلة حريمي حمالات قطن مقاس L لون بيج","qty":"1","unit_price":"85","amount":"85"},{"name":"شراب رجالي قطن أسود مقاس 41-44","qty":"2","unit_price":"30","amount":"60"}]}
Model output
{"merchant":"ستايل بوينت","address":"شارع المحكمة، بجوار مؤقف الأتوبيس، كفر الدوار، البحيرة","receipt_no":"8134947","date":"22/05/2025","total":"232.56","items":[{"name":"بوكسر رجالي قطن أبيض مقاس XL ماركة محلية","qty":"1","unit_price":"95","amount":"95"},{"name":"فانلة حريمي حمالات قطن مقاس 1 لون بيج","qty":"1","unit_price":"85","amount":"85"},{"name":"شراب رجالي قطن أسود مقاس 44-41","qty":"2","unit_price":"30","amount":"60"}]}
clothing-0000044 (header/footer cut off): valid JSON, page CER 0.016

Target
{"receipt_no":"426/41259","date":"2025-01-17","total":"810","items":[{"name":"طقم داخلي حريمي كود ST-900 مقاس XL","qty":"1","unit_price":"680","amount":"680"},{"name":"بوكسر رجالي كود BX-12 مقاس L","qty":"2","unit_price":"65","amount":"130"}]}
Model output
{"receipt_no":"426/41259","date":"2025-01-17","total":"810","items":[{"name":"طقم داخلي حريمي كود B-900 مقاس XL","qty":"1","unit_price":"680","amount":"680"},{"name":"بوكسر رجالي كود M-12 مقاس L","qty":"2","unit_price":"65","amount":"130"}]}
clothing-0000175 (header/footer cut off): valid JSON, page CER 0.031

Target
{"merchant":"أزياء باب الشعرية","merchant_en":"Bab El Shaaria Menswear","address":"شارع الجيش، بجوار مسجد الشعراني، باب الشعرية، القاهرة","receipt_no":"213/12076","date":"17.12.2024","total":"1949.40","items":[{"name":"جاكيت جلد رجالي مستورد","qty":"1","unit_price":"1250.00","amount":"1250.00"},{"name":"تيش رجالي قطن L","qty":"2","unit_price":"85.00","amount":"170.00"},{"name":"شراب رجالي 3 قطع","qty":"1","unit_price":"35.00","amount":"35.00"},{"name":"كاب رجالي","qty":"1","unit_price":"55.00","amount":"55.00"},{"name":"بوك رجالي جلد","qty":"1","unit_price":"90.00","amount":"90.00"},{"name":"حزام رجالي 120سم","qty":"1","unit_price":"110.00","amount":"110.00"}]}
Model output
{"merchant":"أزياء باب الشعرية","merchant_en":"El Hagg Ragabry & Retail","address":"شارع الجيش، بجوار مسجد الشعراني، باب الشعرية، القاهرة","receipt_no":"213/12076","date":"17.12.2024","total":"1949.40","items":[{"name":"جاكيت جلد رجالي مستورد","qty":"1","unit_price":"1250.00","amount":"1250.00"},{"name":"تيش رجالي قطن L","qty":"2","unit_price":"85.00","amount":"170.00"},{"name":"شراب رجالي 3 قطع","qty":"1","unit_price":"35.00","amount":"35.00"},{"name":"كاب رجالي","qty":"1","unit_price":"55.00","amount":"55.00"},{"name":"بوك رجالي جلد","qty":"1","unit_price":"90.00","amount":"90.00"},{"name":"حزام رجالي 120سم","qty":"1","unit_price":"110.00","amount":"110.00"}]}
Training
All 349M parameters trained with Seq2SeqTrainer, 2000 steps, effective batch 16,
Lion (bitsandbytes lion_32bit) lr 1.5e-05, weight decay 0.1. Mixed FP8 through Accelerate (torchao Float8Linear
Linear layers over fp32 master weights with bf16 autocast), one NVIDIA L4. Training receipts with a median
text-line height under 8 px at 896x672 were dropped. 40% of the training receipts were cut at random
(header and/or footer removed, target reduced to the fields still visible) so the model does not invent fields that are not printed.
Use
import torch
from PIL import Image
from transformers import NougatProcessor, VisionEncoderDecoderModel
processor = NougatProcessor.from_pretrained("masterofaudio2077/arabic-nougat-egyptian-receipts-json")
model = VisionEncoderDecoderModel.from_pretrained("masterofaudio2077/arabic-nougat-egyptian-receipts-json", dtype=torch.float16).to("cuda").eval()
pv = processor(images=Image.open("receipt.jpg").convert("RGB"), return_tensors="pt").pixel_values.to("cuda", torch.float16)
out = model.generate(pixel_values=pv, max_new_tokens=1152)
print(processor.tokenizer.batch_decode(out, skip_special_tokens=True)[0])