File size: 5,046 Bytes
494a44d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
---
pretty_name: OCR Eval (Arabic synthetic documents)
task_categories:
- image-to-text
language:
- ar
tags:
- ocr
- arabic
- synthetic
- webdataset
- eval
configs:
- config_name: original
  data_files:
  - split: test
    path: data/*.tar
- config_name: augmented
  data_files:
  - split: test
    path: data_aug/*.tar
---

# OCR Eval

A small, fixed **evaluation** set of synthetic Arabic document images with layout
annotations — the held-out companion to [OCR-Data/ocr_data](https://huggingface.co/datasets/OCR-Data/ocr_data).

**Do not train on this.** It exists so OCR models trained on `ocr_data` can be scored on
unseen pages from the same generator.

| | |
|---|---|
| Originals | **1500** (lossless PNG + JSON) |
| Augmented | **1500** — exactly one variant per original (lossless PNG + JSON) |
| Shards | 2 (`data/shard_001.tar`, `data_aug/shard_001_aug1.tar`) |
| Templates | the same 14 document genres as `ocr_data` |
| Augmentations | the same 10 transforms as `ocr_data`, same weighting |
| Language | Arabic (RTL) |

## Loading

```python
from datasets import load_dataset

clean = load_dataset("OCR-Data/ocr_eval", "original",  split="test")
noisy = load_dataset("OCR-Data/ocr_eval", "augmented", split="test")
```

Both configs are WebDataset shards: files sharing a basename are one sample, so the image
arrives as the `image` column and the annotation as `json`.

## Pairing originals with their variants

A variant's key is its original's key plus a two-digit slot:

```
sample_0000042      ->  data/shard_001.tar
sample_0000042_01   ->  data_aug/shard_001_aug1.tar
```

**The shared stem is the only linkage** — there is no field inside the annotation pointing
back at the original. Strip the `_NN` suffix to join the two configs:

```python
original_key = variant_key.rsplit("_", 1)[0]
```

## Text is unique per image

This is the one place the eval set deliberately departs from how `ocr_data` was generated,
and the reason it can be used for independent measurements.

In the training set, workers share a pool of 3000 consecutive corpus pages and draw from it
at random, so the same page renders into many images. Here, **every image is given its own
private set of 10 corpus pages that no other image may use**, drawn from a shuffled read
across the whole 4.6M-page source corpus rather than one contiguous window. A document
consumes several pages (a page runs out and the next is pulled), so the guarantee is
enforced over the whole set a page may come from, not over a single page.

`meta.corpus_pages` lists the pages each document actually consumed, as truncated SHA-1
digests of the page text, so the property is checkable rather than merely claimed:

```python
pages = [p for r in clean for p in r["json"]["meta"]["corpus_pages"]]
assert len(pages) == len(set(pages))   # no corpus page used by two images
```

## Annotation schema

```json
{
  "markdown": "...",
  "dimensions": {"dpi": 96, "width": 0, "height": 0},
  "blocks": [{"type": "title|text|table|image|header|footer",
              "content": "...", "reading_index": 0,
              "top_left_x": 0, "top_left_y": 0,
              "bottom_right_x": 0, "bottom_right_y": 0}],
  "images": [{"top_left_x": 0, "...": 0}],
  "tables": [],
  "header": null,
  "footer": null,
  "meta": {"template": "a4_report", "hybrid": null,
           "page_font": "...", "title_font": "...",
           "language": "ar", "script": "arabic", "direction": "rtl",
           "corpus_pages": ["a1b2c3d4e5f6", "..."],
           "augmentation": null}
}
```

`meta.augmentation` is `null` throughout the `original` config and
`{"name": ..., "params": {...}}` throughout `augmented`. Coordinates are pixels in the
image's own space; `rotation` is the only augmentation that changes dimensions, and its
boxes are transformed to match.

Augmentation counts are the training weighting applied to 1500 draws — roughly 160 samples
for each of `gaussian_blur`, `bad_photocopy`, `bleed_through`, `color_shift`, `letterpress`,
`rotation`, `reflected_light`, `shadow_cast`, `gaussian_noise`, and ~37 `watermark`. Group
by `meta.augmentation.name` to report per-transform robustness.

## Caveats

- **Not deduplicated against the training set.** Corpus *text* is unique per image and
  scattered across the whole source corpus, but the generator does no content hashing, so
  an eval layout can coincidentally resemble a training layout. This is a synthetic
  in-distribution eval, not a contamination-proof benchmark.
- **Not reproducible.** The generator does not seed its RNG, so this exact set of 1500
  cannot be regenerated. These shards are the only copy of the ground truth. Each variant's
  parameters are recorded in `meta.augmentation.params` and each page's text provenance in
  `meta.corpus_pages`.
- Ground truth is **synthetic**, not human-annotated: boxes and reading order come from the
  renderer's own DOM, so they are exact by construction rather than by agreement.

To get loose files back out of a shard, use `unpack_shard.py` from the generator repo.