Sync from GitHub via hub-sync
Browse files- nanonets-ocr2.py +24 -1
- olmocr2-vllm.py +48 -24
nanonets-ocr2.py
CHANGED
|
@@ -277,6 +277,8 @@ def main(
|
|
| 277 |
output_column: str = "markdown",
|
| 278 |
overwrite: bool = False,
|
| 279 |
verbose: bool = False,
|
|
|
|
|
|
|
| 280 |
):
|
| 281 |
"""Process images from HF dataset through Nanonets-OCR2-3B model."""
|
| 282 |
|
|
@@ -406,7 +408,15 @@ def main(
|
|
| 406 |
|
| 407 |
# Push to hub
|
| 408 |
logger.info(f"Pushing to {output_dataset}")
|
| 409 |
-
dataset.push_to_hub(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 410 |
|
| 411 |
# Calculate processing time
|
| 412 |
end_time = datetime.now()
|
|
@@ -436,6 +446,8 @@ def main(
|
|
| 436 |
logger.info(
|
| 437 |
f"Dataset available at: https://huggingface.co/datasets/{output_dataset}"
|
| 438 |
)
|
|
|
|
|
|
|
| 439 |
|
| 440 |
if verbose:
|
| 441 |
import importlib.metadata
|
|
@@ -559,6 +571,15 @@ Examples:
|
|
| 559 |
parser.add_argument(
|
| 560 |
"--private", action="store_true", help="Make output dataset private"
|
| 561 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 562 |
parser.add_argument(
|
| 563 |
"--shuffle",
|
| 564 |
action="store_true",
|
|
@@ -607,4 +628,6 @@ Examples:
|
|
| 607 |
output_column=args.output_column,
|
| 608 |
overwrite=args.overwrite,
|
| 609 |
verbose=args.verbose,
|
|
|
|
|
|
|
| 610 |
)
|
|
|
|
| 277 |
output_column: str = "markdown",
|
| 278 |
overwrite: bool = False,
|
| 279 |
verbose: bool = False,
|
| 280 |
+
config: str = None,
|
| 281 |
+
create_pr: bool = False,
|
| 282 |
):
|
| 283 |
"""Process images from HF dataset through Nanonets-OCR2-3B model."""
|
| 284 |
|
|
|
|
| 408 |
|
| 409 |
# Push to hub
|
| 410 |
logger.info(f"Pushing to {output_dataset}")
|
| 411 |
+
commit_info = dataset.push_to_hub(
|
| 412 |
+
output_dataset,
|
| 413 |
+
private=private,
|
| 414 |
+
token=HF_TOKEN,
|
| 415 |
+
**({"config_name": config} if config else {}),
|
| 416 |
+
create_pr=create_pr,
|
| 417 |
+
commit_message=f"Add {model} OCR results ({len(dataset)} samples)"
|
| 418 |
+
+ (f" [{config}]" if config else ""),
|
| 419 |
+
)
|
| 420 |
|
| 421 |
# Calculate processing time
|
| 422 |
end_time = datetime.now()
|
|
|
|
| 446 |
logger.info(
|
| 447 |
f"Dataset available at: https://huggingface.co/datasets/{output_dataset}"
|
| 448 |
)
|
| 449 |
+
if create_pr and getattr(commit_info, "pr_url", None):
|
| 450 |
+
logger.info(f"Pull request created: {commit_info.pr_url}")
|
| 451 |
|
| 452 |
if verbose:
|
| 453 |
import importlib.metadata
|
|
|
|
| 571 |
parser.add_argument(
|
| 572 |
"--private", action="store_true", help="Make output dataset private"
|
| 573 |
)
|
| 574 |
+
parser.add_argument(
|
| 575 |
+
"--config",
|
| 576 |
+
help="Config/subset name when pushing to Hub (for benchmarking multiple models in one repo)",
|
| 577 |
+
)
|
| 578 |
+
parser.add_argument(
|
| 579 |
+
"--create-pr",
|
| 580 |
+
action="store_true",
|
| 581 |
+
help="Create a pull request instead of pushing directly (for parallel benchmarking)",
|
| 582 |
+
)
|
| 583 |
parser.add_argument(
|
| 584 |
"--shuffle",
|
| 585 |
action="store_true",
|
|
|
|
| 628 |
output_column=args.output_column,
|
| 629 |
overwrite=args.overwrite,
|
| 630 |
verbose=args.verbose,
|
| 631 |
+
config=args.config,
|
| 632 |
+
create_pr=args.create_pr,
|
| 633 |
)
|
olmocr2-vllm.py
CHANGED
|
@@ -316,6 +316,8 @@ def main(
|
|
| 316 |
private: bool = False,
|
| 317 |
shuffle: bool = False,
|
| 318 |
seed: int = 42,
|
|
|
|
|
|
|
| 319 |
):
|
| 320 |
"""
|
| 321 |
Process a dataset of document images through olmOCR-2 to extract markdown.
|
|
@@ -461,36 +463,41 @@ def main(
|
|
| 461 |
ds = ds.remove_columns([metadata_column_name])
|
| 462 |
ds = ds.add_column(metadata_column_name, all_metadata)
|
| 463 |
|
| 464 |
-
# Add inference information
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
|
|
|
| 476 |
|
| 477 |
-
# Handle existing inference_info column
|
| 478 |
if inference_info_column in ds.column_names:
|
| 479 |
-
|
|
|
|
| 480 |
def update_inference_info(example):
|
| 481 |
try:
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
|
| 485 |
-
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
|
|
|
|
| 490 |
|
| 491 |
ds = ds.map(update_inference_info)
|
| 492 |
else:
|
| 493 |
-
|
|
|
|
|
|
|
| 494 |
|
| 495 |
# Calculate processing time
|
| 496 |
elapsed_time = time.time() - start_time
|
|
@@ -515,9 +522,13 @@ def main(
|
|
| 515 |
|
| 516 |
# Push to hub
|
| 517 |
logger.info(f"Pushing to HuggingFace Hub: {output_dataset}")
|
| 518 |
-
ds.push_to_hub(
|
| 519 |
output_dataset,
|
| 520 |
private=private,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 521 |
)
|
| 522 |
|
| 523 |
# Update dataset card
|
|
@@ -528,6 +539,8 @@ def main(
|
|
| 528 |
logger.info(f"✓ Dataset: https://huggingface.co/datasets/{output_dataset}")
|
| 529 |
logger.info(f"✓ Processing time: {processing_time}")
|
| 530 |
logger.info(f"✓ Samples processed: {len(ds):,}")
|
|
|
|
|
|
|
| 531 |
|
| 532 |
|
| 533 |
if __name__ == "__main__":
|
|
@@ -649,6 +662,15 @@ Examples:
|
|
| 649 |
action="store_true",
|
| 650 |
help="Make output dataset private",
|
| 651 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 652 |
parser.add_argument(
|
| 653 |
"--shuffle",
|
| 654 |
action="store_true",
|
|
@@ -681,4 +703,6 @@ Examples:
|
|
| 681 |
private=args.private,
|
| 682 |
shuffle=args.shuffle,
|
| 683 |
seed=args.seed,
|
|
|
|
|
|
|
| 684 |
)
|
|
|
|
| 316 |
private: bool = False,
|
| 317 |
shuffle: bool = False,
|
| 318 |
seed: int = 42,
|
| 319 |
+
config: str = None,
|
| 320 |
+
create_pr: bool = False,
|
| 321 |
):
|
| 322 |
"""
|
| 323 |
Process a dataset of document images through olmOCR-2 to extract markdown.
|
|
|
|
| 463 |
ds = ds.remove_columns([metadata_column_name])
|
| 464 |
ds = ds.add_column(metadata_column_name, all_metadata)
|
| 465 |
|
| 466 |
+
# Add inference information — standard schema: a JSON-string LIST of entries, each carrying
|
| 467 |
+
# model_id (used as the leaderboard label) and column_name (the output text column). The
|
| 468 |
+
# script's own extras (version, timestamp, sampling params) ride along as extra keys.
|
| 469 |
+
inference_entry = {
|
| 470 |
+
"model_id": model,
|
| 471 |
+
"column_name": output_column,
|
| 472 |
+
"script": "olmocr2-vllm.py",
|
| 473 |
+
"version": "1.0.0",
|
| 474 |
+
"timestamp": datetime.now().isoformat(),
|
| 475 |
+
"batch_size": batch_size,
|
| 476 |
+
"max_tokens": max_tokens,
|
| 477 |
+
"temperature": temperature,
|
| 478 |
+
}
|
| 479 |
|
| 480 |
+
# Handle existing inference_info column (append to the list; create a fresh list otherwise)
|
| 481 |
if inference_info_column in ds.column_names:
|
| 482 |
+
logger.info("Updating existing inference_info column")
|
| 483 |
+
|
| 484 |
def update_inference_info(example):
|
| 485 |
try:
|
| 486 |
+
existing_info = (
|
| 487 |
+
json.loads(example[inference_info_column])
|
| 488 |
+
if example[inference_info_column]
|
| 489 |
+
else []
|
| 490 |
+
)
|
| 491 |
+
except (json.JSONDecodeError, TypeError):
|
| 492 |
+
existing_info = []
|
| 493 |
+
existing_info.append(inference_entry)
|
| 494 |
+
return {inference_info_column: json.dumps(existing_info)}
|
| 495 |
|
| 496 |
ds = ds.map(update_inference_info)
|
| 497 |
else:
|
| 498 |
+
logger.info("Creating new inference_info column")
|
| 499 |
+
inference_list = [json.dumps([inference_entry])] * len(ds)
|
| 500 |
+
ds = ds.add_column(inference_info_column, inference_list)
|
| 501 |
|
| 502 |
# Calculate processing time
|
| 503 |
elapsed_time = time.time() - start_time
|
|
|
|
| 522 |
|
| 523 |
# Push to hub
|
| 524 |
logger.info(f"Pushing to HuggingFace Hub: {output_dataset}")
|
| 525 |
+
commit_info = ds.push_to_hub(
|
| 526 |
output_dataset,
|
| 527 |
private=private,
|
| 528 |
+
**({"config_name": config} if config else {}),
|
| 529 |
+
create_pr=create_pr,
|
| 530 |
+
commit_message=f"Add {model} OCR results ({len(ds)} samples)"
|
| 531 |
+
+ (f" [{config}]" if config else ""),
|
| 532 |
)
|
| 533 |
|
| 534 |
# Update dataset card
|
|
|
|
| 539 |
logger.info(f"✓ Dataset: https://huggingface.co/datasets/{output_dataset}")
|
| 540 |
logger.info(f"✓ Processing time: {processing_time}")
|
| 541 |
logger.info(f"✓ Samples processed: {len(ds):,}")
|
| 542 |
+
if create_pr and getattr(commit_info, "pr_url", None):
|
| 543 |
+
logger.info(f"✓ Pull request created: {commit_info.pr_url}")
|
| 544 |
|
| 545 |
|
| 546 |
if __name__ == "__main__":
|
|
|
|
| 662 |
action="store_true",
|
| 663 |
help="Make output dataset private",
|
| 664 |
)
|
| 665 |
+
parser.add_argument(
|
| 666 |
+
"--config",
|
| 667 |
+
help="Config/subset name when pushing to Hub (for benchmarking multiple models in one repo)",
|
| 668 |
+
)
|
| 669 |
+
parser.add_argument(
|
| 670 |
+
"--create-pr",
|
| 671 |
+
action="store_true",
|
| 672 |
+
help="Create a pull request instead of pushing directly (for parallel benchmarking)",
|
| 673 |
+
)
|
| 674 |
parser.add_argument(
|
| 675 |
"--shuffle",
|
| 676 |
action="store_true",
|
|
|
|
| 703 |
private=args.private,
|
| 704 |
shuffle=args.shuffle,
|
| 705 |
seed=args.seed,
|
| 706 |
+
config=args.config,
|
| 707 |
+
create_pr=args.create_pr,
|
| 708 |
)
|