Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add Cohere Parse v5 provider, pipeline - #111

Draft
violetd1 wants to merge 1 commit into
run-llama:mainfrom
violetd1:cohere/parse-v5
Draft

Add Cohere Parse v5 provider, pipeline#111
violetd1 wants to merge 1 commit into
run-llama:mainfrom
violetd1:cohere/parse-v5

Conversation

@violetd1

Copy link
Copy Markdown

Adds a provider calling Cohere's /v2/parse endpoint (parse-v5.0 model, raw_generation output format). Registers cohere_parse_v5 pipeline with layout cross-eval adapter and label mapper for layout-detection scoring.

To run evals, please register for an API Key from https://dashboard.cohere.com/api-keys

Adds a provider calling Cohere's /v2/parse endpoint (parse-v5.0 model,
raw_generation output format). Registers cohere_parse_v5 pipeline with
layout cross-eval adapter and label mapper for layout-detection scoring.

Co-authored-by: Cursor <[email protected]>
HTTP request timeout in seconds (default 660).
"""

COST_PER_PAGE_USD = 0.001

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find on your website: $1.50 per 1,000 pages
Could you please fix this?

@boyang-zhang1 boyang-zhang1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout bboxes are normalized by the wrong denominator — the layout cross-eval scores ~0 as a result.

In _build_layout_pages, the visual-element coordinates are divided by the rendered image size (img_w/img_h, e.g. 1275×1650). But Cohere Parse emits VE bounding boxes on a normalized 0–1000 grid, not in image pixels. Dividing by the pixel dimensions places every predicted box in the wrong location (and distorts it, since the image isn't square), so CohereParseLayoutAdapter feeds mislocated boxes to the layout-detection eval and IoU collapses.

I checked this by computing IoU of the predicted boxes against layout ground truth for a page:

divide by 1000 → IoU ≈ 0.94 vs the GT boxes
divide by image dimensions (current code) → IoU ≈ 0.18, below the 0.5 match threshold

The raw coordinates also confirm the space directly: the max component stays under 1000 regardless of the rendered resolution (e.g. a box comes back as 500,95,920,375 on a 1275×1650 render).

Fix — normalize by the grid size, not the pixel size:

        x1, y1, x2, y2 = li["bbox_px"]
        # Cohere Parse emits bbox coords on a normalized 0-1000 grid,
        # not image pixels — normalize by 1000, not img_w/img_h.
        nx = max(0.0, min(1.0, x1 / 1000.0))
        ny = max(0.0, min(1.0, y1 / 1000.0))
        nw = max(0.0, min(1.0, (x2 - x1) / 1000.0))
        nh = max(0.0, min(1.0, (y2 - y1) / 1000.0))

(img_w/img_h are still needed for the zero-guard and the stored page dimensions, so leave those as-is. Worth hoisting 1000.0 to a module-level _COORD_SCALE constant for clarity.)

One caveat so the expectation is right: this only fixes the placement of the boxes Cohere emits. Cohere only emits VE boxes for visual elements (tables/figures/charts), not for text/headers/lists, so the layout element pass rate will still be modest — that's a model output-coverage limit, not something to fix in this adapter.

@boyang-zhang1
boyang-zhang1 marked this pull request as draft September 10, 2026 03:14
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.

2 participants