Upsizing PDF pages to match nemotron-parse training data#1271
Open
jamesbraza wants to merge 2 commits intomainfrom
Open
Upsizing PDF pages to match nemotron-parse training data#1271jamesbraza wants to merge 2 commits intomainfrom
nemotron-parse training data#1271jamesbraza wants to merge 2 commits intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
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.
d7060a7 to
839774a
Compare
433f6ca to
94395cf
Compare
94395cf to
49546eb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.