Skip to content

Commit aa9bf29

Browse files
davanstrienclaude
andauthored
Write a minimal provenance card from the saturate recipes (#210)
* Write a dataset card from the saturate recipes The seven saturate recipes that write to a Hub dataset repo pushed only data/part-*.parquet, so their outputs had no README: no uv-script or hf_jobs tag and no Reproduction section (AGENTS.md provenance stamp). Each now inlines jobs_flavor() (verbatim from ocr/glm-ocr.py), reproduce_options(args) and write_card(...), following embeddings/generate-embeddings-saturate.py. The card is uploaded after the main pump and any repair pass, with row counts from the pump stats. The Jobs claim and the hf_jobs tag are gated on HF_JOB_ID. The reproduce command is `hf jobs uv run --flavor {jobs_flavor() or <header flavor>}` with the raw uv-scripts URL and only the non-default options. unlimited-ocr2 and nemotron-transcribe skip the card for a bucket or folder output, and for --repair-only (unlimited-ocr2). With --endpoint they do not stamp this Job's flavor, because the GPU is the server's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Cards: keep --serve-args as one token; note mounted inputs A --serve-args value without a space (e.g. --disable-log-requests) was printed as two tokens, which argparse rejects. Print --serve-args=VALUE. A local or mounted input path cannot be rebuilt in a new Job (the mount source is not visible inside the Job), so the card now says to add the -v mount. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Slim the saturate cards to a minimal provenance card Replace jobs_flavor(), reproduce_options() and the long write_card() with one ~25-line write_card(args): tags (model tags, uv-script, generated, hf_jobs on Jobs), one origin line, and the command as run (sys.argv with the output id swapped for <output-dataset>). The flavor comes from HF_JOB_FLAVOR, which Jobs now sets. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Cards: build metadata with DatasetCardData, push with DatasetCard The frontmatter now comes from huggingface_hub's DatasetCardData, and DatasetCard.push_to_hub validates it before upload. Adds task_categories (image-to-text / automatic-speech-recognition) and source_datasets when the input is a Hub dataset. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Cards: mask HF tokens; replace only the output positional A token passed in any argument (e.g. --serve-args "--hf-token hf_...") was published verbatim in the reproduce command; mask hf_ tokens. When the input and output ids matched, both were replaced by <output-dataset>; replace only the first match after the input. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent cd4e7bf commit aa9bf29

7 files changed

Lines changed: 238 additions & 8 deletions

‎ocr/hpd-parsing-saturate.py‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,14 @@
9999
import math
100100
import os
101101
import re
102+
import shlex
102103
import shutil
103104
import subprocess
104105
import sys
105106
import zlib
106107

108+
SCRIPT_URL = "https://huggingface.co/datasets/uv-scripts/ocr/raw/main/hpd-parsing-saturate.py"
109+
107110
# Serving starting values for PaddlePaddle/HPD-Parsing. Per-value provenance:
108111
# - serve_args: the vendor image's own /home/hpd/entrypoint.sh, verbatim, except
109112
# for the speculative head path (see serve_command) and an added --revision pin.
@@ -453,6 +456,33 @@ def serve_command(vllm: str, max_model_len: int) -> list[str]:
453456
] # fmt: skip
454457

455458

459+
def write_card(args):
460+
"""Push a minimal card: the uv-script / hf_jobs tags and the command that made this dataset."""
461+
from huggingface_hub import DatasetCard, DatasetCardData
462+
463+
on_jobs = os.environ.get("HF_JOB_ID") is not None
464+
flavor = os.environ.get("HF_JOB_FLAVOR")
465+
origin = (
466+
"Produced on [Hugging Face Jobs](https://huggingface.co/docs/huggingface_hub/guides/jobs)"
467+
+ (f" (`{flavor}`)" if flavor else "")
468+
) if on_jobs else "Generated"
469+
argv = sys.argv[1:]
470+
argv[argv.index(args.output_dataset, argv.index(args.input_dataset) + 1)] = "<output-dataset>" # the output positional only
471+
command = re.sub(r"hf_[A-Za-z0-9]{20,}", "hf_***", shlex.join(argv)) # never publish a token
472+
data = DatasetCardData(
473+
tags=["ocr", "document-processing", "hpd-parsing", "uv-script", "generated"] + (["hf_jobs"] if on_jobs else []),
474+
task_categories=["image-to-text"], source_datasets=[args.input_dataset],
475+
)
476+
card = DatasetCard(
477+
f"---\n{data.to_yaml()}\n---\n\n"
478+
f"# {args.output_dataset}\n\n"
479+
f"{origin} with the [`hpd-parsing-saturate.py`]({SCRIPT_URL}) recipe "
480+
f"from [uv-scripts](https://huggingface.co/uv-scripts). Run it yourself:\n\n"
481+
+ f"```bash\nhf jobs uv run{' --flavor ' + flavor if flavor else ''} {SCRIPT_URL} {command}\n```\n"
482+
)
483+
card.push_to_hub(args.output_dataset)
484+
485+
456486
def main():
457487
ap = argparse.ArgumentParser(
458488
description="HPD-Parsing document parsing via saturate (vendor vLLM fork image only)"
@@ -549,6 +579,7 @@ def parse(row, body):
549579
prepare_workers=int(float(os.environ.get("CPU_CORES") or "4")),
550580
retry_errors=args.retry_errors, schema=schema)
551581

582+
write_card(args)
552583
print(f"https://huggingface.co/datasets/{args.output_dataset} "
553584
f"({stats.rows_processed} ok, {stats.rows_failed} error rows)", file=sys.stderr)
554585
print("HPD_PARSING_SATURATE " + stats.to_json(), flush=True)

‎ocr/lighton-ocr2-saturate.py‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,13 @@
5858
import argparse
5959
import base64
6060
import io
61+
import os
62+
import re
63+
import shlex
6164
import sys
6265

66+
SCRIPT_URL = "https://huggingface.co/datasets/uv-scripts/ocr/raw/main/lighton-ocr2-saturate.py"
67+
6368
# Serving starting values for lightonai/LightOnOCR-2-1B. Per-value provenance:
6469
# - serve_args: the model card's own `vllm serve` command, verbatim (the three
6570
# cache/mm flags; OCR never reuses images, so those caches only cost memory).
@@ -117,6 +122,33 @@ def encode_image(value, target_size: int) -> str:
117122
return base64.b64encode(buf.getvalue()).decode()
118123

119124

125+
def write_card(args):
126+
"""Push a minimal card: the uv-script / hf_jobs tags and the command that made this dataset."""
127+
from huggingface_hub import DatasetCard, DatasetCardData
128+
129+
on_jobs = os.environ.get("HF_JOB_ID") is not None
130+
flavor = os.environ.get("HF_JOB_FLAVOR")
131+
origin = (
132+
"Produced on [Hugging Face Jobs](https://huggingface.co/docs/huggingface_hub/guides/jobs)"
133+
+ (f" (`{flavor}`)" if flavor else "")
134+
) if on_jobs else "Generated"
135+
argv = sys.argv[1:]
136+
argv[argv.index(args.output_dataset, argv.index(args.input_dataset) + 1)] = "<output-dataset>" # the output positional only
137+
command = re.sub(r"hf_[A-Za-z0-9]{20,}", "hf_***", shlex.join(argv)) # never publish a token
138+
data = DatasetCardData(
139+
tags=["ocr", "document-processing", "lighton-ocr-2", "uv-script", "generated"] + (["hf_jobs"] if on_jobs else []),
140+
task_categories=["image-to-text"], source_datasets=[args.input_dataset],
141+
)
142+
card = DatasetCard(
143+
f"---\n{data.to_yaml()}\n---\n\n"
144+
f"# {args.output_dataset}\n\n"
145+
f"{origin} with the [`lighton-ocr2-saturate.py`]({SCRIPT_URL}) recipe "
146+
f"from [uv-scripts](https://huggingface.co/uv-scripts). Run it yourself:\n\n"
147+
+ f"```bash\nhf jobs uv run{' --flavor ' + flavor if flavor else ''} {SCRIPT_URL} {command}\n```\n"
148+
)
149+
card.push_to_hub(args.output_dataset)
150+
151+
120152
def main():
121153
ap = argparse.ArgumentParser(description="LightOnOCR-2 batch OCR via saturate")
122154
ap.add_argument("input_dataset", help="Input dataset repo id (rows with an image column)")
@@ -180,6 +212,7 @@ def parse(row, body):
180212
window=Auto(initial=8, max_limit=48),
181213
retry_errors=args.retry_errors, schema=schema)
182214

215+
write_card(args)
183216
print(f"https://huggingface.co/datasets/{args.output_dataset} "
184217
f"({stats.rows_processed} ok, {stats.rows_failed} error rows)", file=sys.stderr)
185218
print("LIGHTON_OCR2_SATURATE " + stats.to_json(), flush=True)

‎ocr/lighton-ocr3-saturate.py‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,13 @@
115115
import io
116116
import json
117117
import os
118+
import re
118119
import shlex
119120
import sys
120121
import tempfile
121122

123+
SCRIPT_URL = "https://huggingface.co/datasets/uv-scripts/ocr/raw/main/lighton-ocr3-saturate.py"
124+
122125
# Serving starting values for LightOnOCR-3 (0.8B and 4B). Per-value provenance:
123126
# - image: vLLM 0.30.0, the version LightOn's client pins and tests (0.27.1 makes the
124127
# models loop, per the LightOnOCR README).
@@ -294,6 +297,33 @@ def postprocess(raw: str, mode: str, fix_dollars: bool):
294297
return to_markdown(blocks), json.dumps([b.to_dict() for b in blocks], ensure_ascii=False)
295298

296299

300+
def write_card(args):
301+
"""Push a minimal card: the uv-script / hf_jobs tags and the command that made this dataset."""
302+
from huggingface_hub import DatasetCard, DatasetCardData
303+
304+
on_jobs = os.environ.get("HF_JOB_ID") is not None
305+
flavor = os.environ.get("HF_JOB_FLAVOR")
306+
origin = (
307+
"Produced on [Hugging Face Jobs](https://huggingface.co/docs/huggingface_hub/guides/jobs)"
308+
+ (f" (`{flavor}`)" if flavor else "")
309+
) if on_jobs else "Generated"
310+
argv = sys.argv[1:]
311+
argv[argv.index(args.output_dataset, argv.index(args.input_dataset) + 1)] = "<output-dataset>" # the output positional only
312+
command = re.sub(r"hf_[A-Za-z0-9]{20,}", "hf_***", shlex.join(argv)) # never publish a token
313+
data = DatasetCardData(
314+
tags=["ocr", "document-processing", "lighton-ocr-3", "uv-script", "generated"] + (["hf_jobs"] if on_jobs else []),
315+
task_categories=["image-to-text"], source_datasets=[args.input_dataset],
316+
)
317+
card = DatasetCard(
318+
f"---\n{data.to_yaml()}\n---\n\n"
319+
f"# {args.output_dataset}\n\n"
320+
f"{origin} with the [`lighton-ocr3-saturate.py`]({SCRIPT_URL}) recipe "
321+
f"from [uv-scripts](https://huggingface.co/uv-scripts). Run it yourself:\n\n"
322+
+ f"```bash\nhf jobs uv run{' --flavor ' + flavor if flavor else ''} {SCRIPT_URL} {command}\n```\n"
323+
)
324+
card.push_to_hub(args.output_dataset)
325+
326+
297327
def main():
298328
ap = argparse.ArgumentParser(description="LightOnOCR-3 batch OCR via saturate")
299329
ap.add_argument("input_dataset", help="Input dataset repo id (rows with an image column)")
@@ -442,6 +472,7 @@ def with_ids(source):
442472
print(f"server: --api-server-count {SERVING['api_servers']} ({cores} CPU cores)", file=sys.stderr)
443473

444474
output = f"hf://datasets/{args.output_dataset}/data"
475+
repair_stats = None
445476
with Engine(args.model, engine="vllm", extra_args=extra) as endpoint:
446477
stats = pump(with_ids(rows) if repair_dir else rows, to_request, make_parse(bool(repair_dir)),
447478
endpoint, output, window=window, prepare_workers=workers,
@@ -466,6 +497,7 @@ def repair_request(row):
466497
retry_errors=args.retry_errors, schema=schema)
467498
print("LIGHTON_OCR3_SATURATE_REPAIR " + repair_stats.to_json(), flush=True)
468499

500+
write_card(args)
469501
print(f"https://huggingface.co/datasets/{args.output_dataset} "
470502
f"({stats.rows_processed} ok, {stats.rows_failed} error rows, "
471503
f"{len(truncated) if repair_dir else 'n/a'} truncated pages re-sent to repair/)", file=sys.stderr)

‎ocr/ovis-ocr2-saturate.py‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,13 @@
6767
import base64
6868
import io
6969
import math
70+
import os
71+
import re
72+
import shlex
7073
import sys
7174

75+
SCRIPT_URL = "https://huggingface.co/datasets/uv-scripts/ocr/raw/main/ovis-ocr2-saturate.py"
76+
7277
# Serving starting values for ATH-MaaS/OvisOCR2. Per-value provenance:
7378
# - The card documents OFFLINE inference only — no `vllm serve` command exists
7479
# upstream. The whole server arrangement here (incl. serve_args) is the
@@ -179,6 +184,33 @@ def filter_image_tags(text: str) -> str:
179184
)
180185

181186

187+
def write_card(args):
188+
"""Push a minimal card: the uv-script / hf_jobs tags and the command that made this dataset."""
189+
from huggingface_hub import DatasetCard, DatasetCardData
190+
191+
on_jobs = os.environ.get("HF_JOB_ID") is not None
192+
flavor = os.environ.get("HF_JOB_FLAVOR")
193+
origin = (
194+
"Produced on [Hugging Face Jobs](https://huggingface.co/docs/huggingface_hub/guides/jobs)"
195+
+ (f" (`{flavor}`)" if flavor else "")
196+
) if on_jobs else "Generated"
197+
argv = sys.argv[1:]
198+
argv[argv.index(args.output_dataset, argv.index(args.input_dataset) + 1)] = "<output-dataset>" # the output positional only
199+
command = re.sub(r"hf_[A-Za-z0-9]{20,}", "hf_***", shlex.join(argv)) # never publish a token
200+
data = DatasetCardData(
201+
tags=["ocr", "document-processing", "ovis-ocr2", "uv-script", "generated"] + (["hf_jobs"] if on_jobs else []),
202+
task_categories=["image-to-text"], source_datasets=[args.input_dataset],
203+
)
204+
card = DatasetCard(
205+
f"---\n{data.to_yaml()}\n---\n\n"
206+
f"# {args.output_dataset}\n\n"
207+
f"{origin} with the [`ovis-ocr2-saturate.py`]({SCRIPT_URL}) recipe "
208+
f"from [uv-scripts](https://huggingface.co/uv-scripts). Run it yourself:\n\n"
209+
+ f"```bash\nhf jobs uv run{' --flavor ' + flavor if flavor else ''} {SCRIPT_URL} {command}\n```\n"
210+
)
211+
card.push_to_hub(args.output_dataset)
212+
213+
182214
def main():
183215
ap = argparse.ArgumentParser(description="OvisOCR2 batch OCR via saturate")
184216
ap.add_argument("input_dataset", help="Input dataset repo id (rows with an image column)")
@@ -245,6 +277,7 @@ def parse(row, body):
245277
window=Auto(initial=8, max_limit=48),
246278
retry_errors=args.retry_errors, schema=schema)
247279

280+
write_card(args)
248281
print(f"https://huggingface.co/datasets/{args.output_dataset} "
249282
f"({stats.rows_processed} ok, {stats.rows_failed} error rows)", file=sys.stderr)
250283
print("OVIS_OCR2_SATURATE " + stats.to_json(), flush=True)

‎ocr/unlimited-ocr2-saturate.py‎

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,16 @@
8282
import os
8383
import pickle
8484
import re
85+
import shlex
8586
import shutil
8687
import subprocess
8788
import sys
8889
import threading
8990
import types
9091
import zlib
9192

93+
SCRIPT_URL = "https://huggingface.co/datasets/uv-scripts/ocr/raw/main/unlimited-ocr2-saturate.py"
94+
9295
# Per-value provenance:
9396
# - image lmsysorg/sglang:v0.5.20-cu130: the SGLang release whose pins match
9497
# Baidu's wheel exactly (torch 2.13.0, transformers 5.12.1, flashinfer 0.6.18
@@ -375,6 +378,35 @@ def find_server_python(candidates) -> str:
375378
)
376379

377380

381+
def write_card(args):
382+
"""Push a minimal card: the uv-script / hf_jobs tags and the command that made this dataset."""
383+
from huggingface_hub import DatasetCard, DatasetCardData
384+
385+
on_jobs = os.environ.get("HF_JOB_ID") is not None
386+
flavor = os.environ.get("HF_JOB_FLAVOR")
387+
origin = (
388+
"Produced on [Hugging Face Jobs](https://huggingface.co/docs/huggingface_hub/guides/jobs)"
389+
+ (f" (`{flavor}`)" if flavor else "")
390+
) if on_jobs else "Generated"
391+
argv = sys.argv[1:]
392+
argv[argv.index(args.output, argv.index(args.input) + 1)] = "<output-dataset>" # the output positional only
393+
command = re.sub(r"hf_[A-Za-z0-9]{20,}", "hf_***", shlex.join(argv)) # never publish a token
394+
data = DatasetCardData(
395+
tags=["ocr", "document-processing", "unlimited-ocr-2", "uv-script", "generated"] + (["hf_jobs"] if on_jobs else []),
396+
task_categories=["image-to-text"],
397+
)
398+
card = DatasetCard(
399+
f"---\n{data.to_yaml()}\n---\n\n"
400+
f"# {args.output}\n\n"
401+
f"{origin} with the [`unlimited-ocr2-saturate.py`]({SCRIPT_URL}) recipe "
402+
f"from [uv-scripts](https://huggingface.co/uv-scripts). Run it yourself:\n\n"
403+
+ (f"The input `{args.input}` was a local or mounted path: add the `-v` mount that provides it.\n\n"
404+
if not args.input.startswith("hf://") else "")
405+
+ f"```bash\nhf jobs uv run{' --flavor ' + flavor if flavor else ''} {SCRIPT_URL} {command}\n```\n"
406+
)
407+
card.push_to_hub(args.output)
408+
409+
378410
def main():
379411
ap = argparse.ArgumentParser(description="Unlimited-OCR-2 document OCR via saturate")
380412
ap.add_argument("input", help="Folder/glob of page images or PDFs: hf://buckets/..., a mounted dir, ...")
@@ -532,18 +564,21 @@ def parse_repair(row, body):
532564
def run_passes(endpoint, headers=None):
533565
common = {"retry_errors": args.retry_errors, "headers": headers,
534566
"prepare_workers": args.prepare_workers, "read_timeout": 3600}
567+
stats = rstats = None
535568
if not args.repair_only:
536569
stats = pump(rows, to_request, parse, endpoint, output, window=window, flush_every=4, **common)
537570
print(f"{output} ({stats.rows_processed} ok, {stats.rows_failed} error rows)", file=sys.stderr)
538571
print("UNLIMITED_OCR2_SATURATE " + stats.to_json(), flush=True)
539-
if args.no_repair:
540-
return
541-
targets = list(repair_rows(rows, output))
542-
print(f"repair pass: {len(targets)} pages to re-OCR alone (gundam) -> {repairs_out}", file=sys.stderr)
543-
if targets:
544-
rstats = pump(targets, to_request, parse_repair, endpoint, repairs_out,
545-
window=Auto(initial=32, max_limit=64), flush_every=16, **common)
546-
print("UNLIMITED_OCR2_REPAIR " + rstats.to_json(), flush=True)
572+
if not args.no_repair:
573+
targets = list(repair_rows(rows, output))
574+
print(f"repair pass: {len(targets)} pages to re-OCR alone (gundam) -> {repairs_out}", file=sys.stderr)
575+
if targets:
576+
rstats = pump(targets, to_request, parse_repair, endpoint, repairs_out,
577+
window=Auto(initial=32, max_limit=64), flush_every=16, **common)
578+
print("UNLIMITED_OCR2_REPAIR " + rstats.to_json(), flush=True)
579+
# A card only for a dataset repo, and not from --repair-only (the main run wrote it).
580+
if is_repo_id and stats is not None:
581+
write_card(args)
547582

548583
if args.endpoint:
549584
run_passes(args.endpoint, {"Authorization": f"Bearer {os.environ['HF_TOKEN']}"}

‎ocr/xiaomi-ocr-0-saturate.py‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@
7979
import io
8080
import os
8181
import re
82+
import shlex
8283
import sys
84+
85+
SCRIPT_URL = "https://huggingface.co/datasets/uv-scripts/ocr/raw/main/xiaomi-ocr-0-saturate.py"
8386
from dataclasses import dataclass
8487

8588
# Serving starting values for xiaomi-research/Xiaomi-OCR-0. Per-value provenance:
@@ -493,6 +496,34 @@ def finalize_document(text: str) -> str:
493496
return postprocess_otsl_tables(postprocess_math_delimiters(_clean_truncated_repeats(text)))
494497

495498

499+
def write_card(args):
500+
"""Push a minimal card: the uv-script / hf_jobs tags and the command that made this dataset."""
501+
from huggingface_hub import DatasetCard, DatasetCardData
502+
503+
on_jobs = os.environ.get("HF_JOB_ID") is not None
504+
flavor = os.environ.get("HF_JOB_FLAVOR")
505+
origin = (
506+
"Produced on [Hugging Face Jobs](https://huggingface.co/docs/huggingface_hub/guides/jobs)"
507+
+ (f" (`{flavor}`)" if flavor else "")
508+
) if on_jobs else "Generated"
509+
image = f" --image {SERVING['images']['sglang']}" if args.engine == "sglang" else ""
510+
argv = sys.argv[1:]
511+
argv[argv.index(args.output_dataset, argv.index(args.input_dataset) + 1)] = "<output-dataset>" # the output positional only
512+
command = re.sub(r"hf_[A-Za-z0-9]{20,}", "hf_***", shlex.join(argv)) # never publish a token
513+
data = DatasetCardData(
514+
tags=["ocr", "document-processing", "xiaomi-ocr-0", "uv-script", "generated"] + (["hf_jobs"] if on_jobs else []),
515+
task_categories=["image-to-text"], source_datasets=[args.input_dataset],
516+
)
517+
card = DatasetCard(
518+
f"---\n{data.to_yaml()}\n---\n\n"
519+
f"# {args.output_dataset}\n\n"
520+
f"{origin} with the [`xiaomi-ocr-0-saturate.py`]({SCRIPT_URL}) recipe "
521+
f"from [uv-scripts](https://huggingface.co/uv-scripts). Run it yourself:\n\n"
522+
+ f"```bash\nhf jobs uv run{' --flavor ' + flavor if flavor else ''}{image} {SCRIPT_URL} {command}\n```\n"
523+
)
524+
card.push_to_hub(args.output_dataset)
525+
526+
496527
def main():
497528
ap = argparse.ArgumentParser(description="Xiaomi-OCR-0 batch OCR via saturate")
498529
ap.add_argument("input_dataset", help="Input dataset repo id (rows with an image column)")
@@ -586,6 +617,7 @@ def parse(row, body):
586617
prepare_workers=int(float(os.environ.get("CPU_CORES") or "4")),
587618
retry_errors=args.retry_errors, schema=schema)
588619

620+
write_card(args)
589621
print(f"https://huggingface.co/datasets/{args.output_dataset} "
590622
f"({stats.rows_processed} ok, {stats.rows_failed} error rows)", file=sys.stderr)
591623
print("XIAOMI_OCR_0_SATURATE " + stats.to_json(), flush=True)

0 commit comments

Comments
 (0)