-
Notifications
You must be signed in to change notification settings - Fork 817
Upsizing PDF pages to match nemotron-parse training data
#1271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR updates the nemotron-based PDF reader to resize rendered pages to Nemotron-Parse’s native aspect ratio/dimensions before calling the API, and to correctly map bounding boxes back into original PDF coordinates. This is intended to avoid invalid bounding boxes (e.g., negative coordinates) and improve robustness when parsing PDFs like the cited Neuron article.
Changes:
- Introduced
NEMOTRON_PARSE_TARGET_WIDTH/HEIGHTand a new helperfit_image_to_target_aspect_ratioto scale and center page images onto a canvas matching Nemotron-Parse’s training aspect ratio. - Extended
parse_pdf_to_pagesto optionally apply this aspect-ratio optimization (enabled by default) for both media and non-media parsing paths, and adjusted bounding box coordinate transformations to account for aspect and border padding. - Added unit tests for
fit_image_to_target_aspect_ratiocovering scaling, aspect-ratio preservation, and mode preservation, and wired these constants/functions into existing tests.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
packages/paper-qa-nemotron/src/paperqa_nemotron/reader.py |
Adds Nemotron-Parse target dimensions, aspect-ratio fitting helper, and integrates aspect-ratio optimization and updated bbox back-projection into the PDF parsing pipeline. |
packages/paper-qa-nemotron/tests/test_paperqa_nemotron.py |
Imports the new constants/helper and adds focused tests validating fit_image_to_target_aspect_ratio behavior across image sizes and modes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
MicPie
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, nice fix based on the training
d6cadbd to
ddfa4d0
Compare
ddfa4d0 to
472da8c
Compare
On DOI 10.1016/j.neuron.2011.12.023 "Encoding of luminance and contrast by linear and nonlinear synapses in the retina"
Without this PR at temperature of 0, we fail to resolve a valid bounding box (e.g. we hit a negative xmin below on page 11) and get blown up with:
This PR moves the
nemotron-parsedriver to resize the image to 2048-px height x 1648-px width, matchingnemotron-parse's training regime. After this PR, we can successfully read in the PDF.Note
Aligns input preprocessing with Nemotron-Parse training and corrects bbox -> original image coordinate mapping.
NEMOTRON_PARSE_TARGET_WIDTH/HEIGHTandfit_image_to_target_aspect_ratio()to scale/center pages onto a minimal canvas with the model’s aspect ratioparse_pdf_to_pages: newoptimize_aspect_ratioflag (default True); apply aspect-ratio fit before border padding for both bbox and no-bbox flowsfit_image_to_target_aspect_ratio()Written by Cursor Bugbot for commit 3ebfbd6. Configure here.