"""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/.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} | " + "
".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()