File size: 12,906 Bytes
35a8678
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
"""Write the phase 1 data report: what was fetched and verified, what is inside,

and how that compares with what the reference engines trained on.



usage: python data/report.py



Reads data/manifests/phase1/*.json (fetch.py) and

data/reports/phase1/profile/*.json (profile.py); writes

data/reports/phase1/REPORT.md and summary.json.

"""
import json
from datetime import datetime, timezone
from pathlib import Path

from sources import SOURCES

HERE = Path(__file__).resolve().parent
MANIFESTS = HERE / "manifests" / "phase1"
PROFILES = HERE / "reports" / "phase1" / "profile"
OUT = HERE / "reports" / "phase1"

# What the reference engines trained on, with sources.
REFERENCES = {
    "synthetic text": [
        ("Tesseract 4/5", "about 400 k rendered lines in about 4,500 fonts (Latin)",
         "https://tesseract-ocr.github.io/tessdoc/tess4/TrainingTesseract-4.00.html"),
        ("PP-OCRv3", "11.5 M synthetic recognition lines (of 18.5 M)", "https://arxiv.org/abs/2206.03001"),
        ("TrOCR", "17.9 M synthetic handwritten lines in 5,427 fonts; MJ + ST", "https://arxiv.org/abs/2109.10282"),
        ("Nemotron OCR v2", "about 11 M synthetic pages in 6 languages",
         "https://huggingface.co/nvidia/nemotron-ocr-v2"),
    ],
    "born-digital PDFs": [
        ("TrOCR", "684 M printed lines from 2 M digital-born PDF pages", "https://arxiv.org/abs/2109.10282"),
        ("PP-OCRv5", "labels parsed from PDFs and e-books", "https://arxiv.org/abs/2507.05595"),
        ("olmOCR 2", "268 k PDF pages with VLM transcriptions", "https://arxiv.org/abs/2510.19817"),
    ],
    "real text in images": [
        ("PARSeq", "3.3 M real scene-text crops", "https://arxiv.org/abs/2207.06966"),
        ("PP-OCRv3", "7 M real recognition lines; 68 k real detection images", "https://arxiv.org/abs/2206.03001"),
        ("Nemotron OCR v2", "about 680 k real images", "https://huggingface.co/nvidia/nemotron-ocr-v2"),
    ],
    "layout and reading order": [
        ("PP-DocLayout", "30 k images, 23 classes (incl. DocLayNet, PubLayNet)", "https://arxiv.org/abs/2503.17213"),
        ("Nemotron OCR v2", "a reading-order graph on its synthetic pages",
         "https://huggingface.co/datasets/nvidia/OCR-Synthetic-Multilingual-v1"),
    ],
    "handwriting": [
        ("TrOCR", "17.9 M synthetic lines, then IAM (6,161 lines)", "https://arxiv.org/abs/2109.10282"),
        ("PP-OCRv5", "handwriting auto-labelled with ERNIE-4.5-VL", "https://arxiv.org/abs/2507.05595"),
    ],
}


def load(dirpath):
    out = {}
    for p in sorted(dirpath.glob("*.json")):
        out[p.stem] = json.loads(p.read_text(encoding="utf-8"))
    return out


def gb(n):
    return f"{n / 2 ** 30:.1f}"


def fmt(n):
    if n is None:
        return "?"
    if n >= 1e9:
        return f"{n / 1e9:.2f} B"
    if n >= 1e6:
        return f"{n / 1e6:.1f} M"
    if n >= 1e3:
        return f"{n / 1e3:.1f} k"
    return str(n)


def get(d, *keys, default=None):
    for k in keys:
        if not isinstance(d, dict) or k not in d:
            return default
        d = d[k]
    return d


def measured(prof):
    """The handful of numbers the comparison needs, from the profiles."""
    p = {k: v.get("profile", {}) for k, v in prof.items()}
    m = {}
    nv = p.get("nvidia-ocr-synthetic", {})
    m["nvidia_pages"] = sum(v.get("samples", 0) for v in nv.values())
    m["nvidia_lines"] = sum(v.get("lines_total", 0) for v in nv.values())
    m["nvidia_order_share"] = min((v.get("with_reading_order_share", 0) for v in nv.values()), default=None)
    g = p.get("fonts-google", {})
    m["google_families"] = g.get("families")
    m["google_by_category"] = g.get("by_category")
    m["latin_cov"] = g.get("latin_full_coverage_share")
    m["noto_families"] = get(p, "fonts-noto", "families")
    m["text_chars"] = sum(get(p, k, "characters", default=0) or 0 for k in ("wikipedia", "fineweb-2", "finepdfs"))
    m["text_docs"] = sum(get(p, k, "documents", default=0) or 0 for k in ("wikipedia", "fineweb-2", "finepdfs"))
    m["doclaynet_pages"] = get(p, "doclaynet", "pages")
    m["doclaynet_cells"] = get(p, "doclaynet", "text_cells")
    m["hiertext_lines"] = sum(get(p, "hiertext", s, "lines", default=0) or 0 for s in ("train", "validation"))
    m["hiertext_words"] = sum(get(p, "hiertext", s, "words", default=0) or 0 for s in ("train", "validation"))
    m["textocr_words"] = sum((get(p, "textocr", s, "words", default=0) or 0) - (get(p, "textocr", s, "illegible",
                             default=0) or 0) for s in ("train", "val"))
    m["gt4_lines"] = get(p, "gt4histocr", "lines")
    m["gnhk_pages"] = get(p, "gnhk", "rows")
    pdf_pages = 0
    for k in ("pmc-oa", "arxiv"):
        pdf_pages += get(p, k, "pages_total_in_read_docs", default=0) or 0
    m["pdfa_pages"] = get(p, "pdfa-eng", "pages_total")
    m["pdfa_docs"] = get(p, "pdfa-eng", "documents")
    m["pmc_pdfs"] = get(p, "pmc-oa", "pdfs")
    m["arxiv_pdfs"] = get(p, "arxiv", "pdfs")
    m["govdocs_files"] = get(p, "govdocs1", "files_in_piece")
    m["sampled_pdf_pages"] = pdf_pages
    return m


def main():
    man, prof = load(MANIFESTS), load(PROFILES)

    rows, total_plan, total_got, files, verified, unverified, failed = [], 0, 0, 0, 0, 0, []
    for s in SOURCES:
        mf = man.get(s["name"])
        total_plan += s["expected_bytes"]
        if not mf:
            rows.append(f"| `{s['name']}` | {s['group']} | {s['use']} | {gb(s['expected_bytes'])} | not fetched | | | |")
            continue
        total_got += mf["bytes"]
        files += mf["file_count"]
        verified += mf["verified_files"]
        unverified += mf["unverified_files"]
        failed += [(s["name"], f) for f in mf["failed_files"]]
        checks = sorted({next(iter(f.get("upstream") or {"none": 0})) for f in mf["files"]} - {"none"}) or \
            sorted({f.get("check", "") for f in mf["files"]})
        state = "error: " + mf["error"][:60] if mf.get("error") else \
            f"{mf['verified_files']}/{mf['file_count']} verified" + (
                f", {mf['unverified_files']} slices" if mf["unverified_files"] else "")
        rows.append(f"| `{s['name']}` | {s['group']} | {s['use']} | {gb(s['expected_bytes'])} | {gb(mf['bytes'])} | "
                    f"{mf['file_count']:,} | {state} | {', '.join(checks)} |")

    m = measured(prof)
    summary = dict(generated_at=datetime.now(timezone.utc).isoformat(timespec="seconds"),
                   sources=len(SOURCES), fetched=len(man), planned_bytes=total_plan, fetched_bytes=total_got,
                   files=files, verified_files=verified, unverified_files=unverified, failed_checks=failed,
                   measured=m)
    (OUT / "summary.json").write_text(json.dumps(summary, indent=1), encoding="utf-8")

    cov = m.get("latin_cov") or {}
    cats = m.get("google_by_category") or {}
    L = []
    L.append("# Phase 1 data: verification and profile\n")
    L.append(f"Generated {summary['generated_at']} by `scripts/report.py` from the manifests "
             f"(`manifests/phase1/`) and profiles (`reports/phase1/profile/`). "
             "The manifest lists every file's URL, size and SHA-256, so the set can be fetched again and "
             "checked byte for byte.\n")
    L.append("## 1. What was fetched\n")
    L.append(f"- **Sources:** {len(man)} of {len(SOURCES)}")
    L.append(f"- **Size:** {gb(total_got)} GB fetched, against {gb(total_plan)} GB planned")
    L.append(f"- **Files:** {files:,} in all")
    L.append(f"  - {verified:,} match the checksum or size their source publishes")
    L.append(f"  - {unverified:,} are re-encoded slices of larger files, with no upstream checksum to compare")
    L.append(f"  - {len(failed)} failed a check" + (": " + ", ".join(f"{a}/{b}" for a, b in failed[:10]) if failed else ""))
    L.append("\n| source | kind | use | planned GB | fetched GB | files | state | checked against |")
    L.append("|---|---|---|---|---|---|---|---|")
    L += rows
    L.append("\nUse: T trains shipped weights, E evaluation only (never trained or tuned on), "
             "check licence to be confirmed before training.\n")

    L.append("## 2. What is inside\n")
    L.append("| kind | measured |")
    L.append("|---|---|")
    L.append(f"| fonts | {fmt(m['google_families'])} Google Fonts families "
             f"({', '.join(f'{k.lower()} {v}' for k, v in sorted(cats.items(), key=lambda x: -x[1]))}); "
             f"{fmt(m['noto_families'])} Noto families |")
    if cov:
        L.append(f"| Latin glyph coverage (Google Fonts with Latin) | full Latin-1 {cov.get('latin1', 0):.0%}, "
                 f"Latin Extended-A {cov.get('latin_ext_a', 0):.0%}, Vietnamese {cov.get('vietnamese', 0):.0%}, "
                 f"Yoruba {cov.get('yoruba', 0):.0%} of families |")
    L.append(f"| text corpora | {fmt(m['text_docs'])} documents, {fmt(m['text_chars'])} characters |")
    L.append(f"| NVIDIA synthetic (en, ru) | {fmt(m['nvidia_pages'])} pages, {fmt(m['nvidia_lines'])} lines with boxes |")
    L.append(f"| DocLayNet | {fmt(m['doclaynet_pages'])} pages with layout labels; {fmt(m['doclaynet_cells'])} PDF text cells "
             f"inside the boxes |")
    L.append(f"| HierText | {fmt(m['hiertext_lines'])} lines, {fmt(m['hiertext_words'])} words |")
    L.append(f"| TextOCR | {fmt(m['textocr_words'])} legible words |")
    L.append(f"| GT4HistOCR | {fmt(m['gt4_lines'])} historical print lines |")
    L.append(f"| GNHK | {fmt(m['gnhk_pages'])} handwritten pages |")
    L.append(f"| born-digital PDFs | PDFA {fmt(m['pdfa_docs'])} documents ({fmt(m['pdfa_pages'])} pages); "
             f"PMC {fmt(m['pmc_pdfs'])} PDFs; arXiv {fmt(m['arxiv_pdfs'])} PDFs; govdocs1 {fmt(m['govdocs_files'])} "
             "files in the first piece |")
    L.append("\nPer-source detail (character sets, scripts, line geometry, text-layer coverage) is in "
             "`profile/<source>.json`.\n")

    L.append("## 3. Against what the reference engines trained on\n")
    ours = {
        "synthetic text": f"{fmt(m['nvidia_pages'])} synthetic pages with {fmt(m['nvidia_lines'])} lines (NVIDIA, en "
                          f"and ru); {fmt(m['google_families'])} + {fmt(m['noto_families'])} font families and "
                          f"{fmt(m['text_chars'])} characters of text to render without limit",
        "born-digital PDFs": f"{fmt(m['pdfa_pages'])} PDFA pages with text-layer boxes; {fmt(m['pmc_pdfs'])} PMC and "
                             f"{fmt(m['arxiv_pdfs'])} arXiv PDFs; govdocs1",
        "real text in images": f"{fmt(m['hiertext_words'])} HierText and {fmt(m['textocr_words'])} TextOCR words",
        "layout and reading order": f"{fmt(m['doclaynet_pages'])} DocLayNet pages; reading-order graphs on "
                                    f"{(m['nvidia_order_share'] or 0):.0%} of the NVIDIA pages",
        "handwriting": f"{fmt(m['gnhk_pages'])} GNHK pages (IAM is evaluation only)",
    }
    L.append("| data kind | reference engines | Fullerene's training data (measured) |")
    L.append("|---|---|---|")
    for kind, refs in REFERENCES.items():
        L.append(f"| {kind} | " + "<br>".join(f"{n}: {d}" for n, d, _ in refs) + f" | {ours[kind]} |")
    L.append("")
    L.append("## 4. Gaps and what to do about them\n")
    L.append("- **Handwriting is the thinnest kind.** GNHK alone is hundreds of pages, against TrOCR's 17.9 M synthetic "
             "lines and the real handwritten sets the other engines name. What closes the gap: handwriting-style "
             "fonts for pretraining, permissively licensed handwriting sets, VLM transcription with alignment, and "
             "hand labels.")
    L.append("- **Synthetic lines are unlimited.** The fonts and text fetched here are rendered into as many lines as training needs, 10 to 20 M, so those lines need no download.")
    L.append("- **Born-digital pages are plentiful.** One PDFA shard holds thousands of documents, and the 1,800 shards "
             "reach millions of pages, the same kind of data that gave TrOCR its 684 M lines.")
    L.append("- **Real text in images is close to PARSeq's real set in kind, smaller in count.** HierText and TextOCR "
             "together give the real words the detector and recognizer need for photographed pages.")
    L.append("- **Reading order** comes from NVIDIA's graphs, the PDF text layer and DocLayNet's layout. Human-labelled "
             "order (ReadingBank) needs its license checked first.")
    (OUT / "REPORT.md").write_text("\n".join(L) + "\n", encoding="utf-8")
    print(f"wrote {OUT / 'REPORT.md'}")
    print(json.dumps({k: v for k, v in summary.items() if k != "measured"}, indent=1))


if __name__ == "__main__":
    main()