Add NemotronParseBBox.to_original_coordinates for raw nemotron-parse output#1335
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a first-class conversion utility for consumers of raw nemotron-parse outputs by inverting the model’s resize + centered-padding preprocessing, so canvas-normalized bounding boxes can be mapped back into original image pixel coordinates (matching NVIDIA’s reference behavior). This complements the existing to_page_coordinates path (used for NIM, which already returns input-image coordinates).
Changes:
- Add
NEMOTRON_PARSE_TARGET_HEIGHT/WIDTHconstants for Nemotron-Parse’s native input canvas size. - Add
NemotronParseBBox.to_original_coordinates()to convert padded-canvas normalized bboxes to original-image pixel coordinates. - Add tests asserting parity with NVIDIA’s reference transform across multiple resize/padding regimes and a round-trip recovery check.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/paper-qa-nemotron/src/paperqa_nemotron/api.py | Introduces target canvas constants and to_original_coordinates() bbox back-projection. |
| packages/paper-qa-nemotron/tests/test_api.py | Adds parity and round-trip tests for the new coordinate transform. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
jamesbraza
force-pushed
the
fix/nemotron-to-original-coordinates
branch
from
June 5, 2026 02:03
45d07cb to
a80f1d8
Compare
jamesbraza
requested review from
Eddie-MG,
MicPie,
mdelmar-edison,
mskarlin,
sidnarayanan and
whitead
June 5, 2026 02:05
MicPie
approved these changes
Jun 5, 2026
…e output nemotron-parse emits bounding boxes normalized to its target 2048x1648 (HxW) canvas, which it builds by an aspect-preserving resize followed by centered white padding. NVIDIA's hosted NIM maps coordinates back to the input image before returning, so PaperQA's existing decode is correct against NIM. Consumers of the model's raw output (e.g. a self-hosted vLLM or HuggingFace transformers endpoint) instead receive canvas-space coordinates and must invert that mapping themselves, as NVIDIA's example.py does. Add NemotronParseBBox.to_original_coordinates (companion to to_page_coordinates) plus the NEMOTRON_PARSE_TARGET_HEIGHT/WIDTH constants: a faithful port of NVIDIA's postprocessing.transform_bbox_to_original, validated against that reference with parity, round-trip, and low-DPI tests. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
jamesbraza
force-pushed
the
fix/nemotron-to-original-coordinates
branch
from
June 5, 2026 22:14
a80f1d8 to
59dd96d
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.
Why
nemotron-parsepredicts bounding boxes in the space of its preprocessed input: each page is resized (aspect-preserving) and centered onto a target2048x1648(HxW) canvas with white padding, so the boxes are normalized to that padded canvas rather than to the page.NVIDIA's hosted NIM undoes that and returns input-image coordinates, which is why PaperQA's current decode is correct against NIM. A consumer of the model's raw output, though, e.g. a self-hosted vLLM or HuggingFace
transformersendpoint, receives canvas-space coordinates and draws every box shifted inward and compressed, worst at low DPI where the padding dominates. This adds a first-class way for such consumers to recover original-image coordinates, mirroring what NVIDIA'spostprocessing.transform_bbox_to_originalandexample.pydo.Notes
to_original_coordinatessits alongsideto_page_coordinatesfor the raw-output case only.nemotron-parsetraining data #1271: that (closed) PR addressed the same mismatch from the input side, upsizing/pre-fitting pages to the training aspect ratio before sending. This is the complementary output side, and leaves the request path untouched.🤖 Generated with Claude Code