Skip to content

fix(prompts): include real page number in figure/chart image tags - #475

Open
SomSamantray wants to merge 2 commits into
allenai:mainfrom
SomSamantray:feat/page-number-image-tags
Open

fix(prompts): include real page number in figure/chart image tags#475
SomSamantray wants to merge 2 commits into
allenai:mainfrom
SomSamantray:feat/page-number-image-tags

Conversation

@SomSamantray

Copy link
Copy Markdown

Fixes #384

Changes proposed in this pull request:

  • Figures/charts extracted from multi-page documents were labeled with a filename that carried no page number (page_startx_starty_width_height.png), so a caller couldn't tell which page a figure came from. The model was also never told the actual page number anywhere in its prompt or image input, so the originally-proposed fix (renaming the placeholder to literal page_number) wouldn't have worked — there was nothing for it to substitute.
  • build_no_anchoring_v4_yaml_prompt (the live-pipeline prompt) now takes page_num and interpolates the real value into the instructed tag: <page_num>_startx_starty_width_height.png.
  • Updated the three call sites that already have a real per-page number in scope to pass it explicitly: olmocr/pipeline.py, olmocr/bench/runners/run_server.py, olmocr/train/grpo_train.py.
  • Left olmocr/train/dataloader.py and scripts/hf_local_test.py unchanged — they only ever process an isolated single page, so the new page_num=1 default already matches this repo's existing single-page convention there.
  • Added a unit test for build_no_anchoring_v4_yaml_prompt's interpolation, and strengthened test_grpo.py's existing mocked test to assert the grpo_train.py call site actually passes page_num through (previously the mock accepted any/no arguments silently).

Before submitting

  • I've read and followed all steps in the Making a pull request
    section of the CONTRIBUTING docs.
  • I've updated or added any relevant docstrings following the syntax described in the
    Writing docstrings section of the CONTRIBUTING docs.
  • If this PR fixes a bug, I've added a test that will fail without my fix.
  • If this PR adds a new feature, I've added tests that sufficiently cover my new functionality.

Compound Engineering

Threads the actual page number into build_no_anchoring_v4_yaml_prompt's
instructed image tag (page_startx... -> <page_num>_startx...) instead of
asking the model to invent a page number it has no way to know. Updates
the three call sites that already have a real per-page number in scope
(pipeline.py, bench run_server.py, grpo_train.py); the two remaining
callers that only ever process an isolated single page keep the new
default of page_num=1, matching this repo's existing single-page
convention.
Adds a direct unit test for build_no_anchoring_v4_yaml_prompt's new
page_num parameter, and strengthens test_grpo.py's existing mocked
test to assert the grpo_train.py call site actually passes page_num
through (previously the mock accepted any/no arguments silently).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adding page number in image tags

1 participant