Repository navigation
feat(backends): carry positioned spans out of the backends and measure their reading order - #77
Merged
Merged
Conversation
…them vision, easyocr, easyocr-hy and paddle each compute a box per recognised region and then flattened it to a string, because the registry contract is `ocr_image(path) -> str`. They now return `layout.Transcript`, a str subclass carrying one TextSpan per region in pixels from the top-left corner, so the contract holds and every caller -- the batch pipeline, the quality gate, the harness, auto-local's winner selection -- is unchanged. Backends without boxes still return a plain str. The batch pipeline and the `ocr` subcommand take the spans off the transcript with `layout.spans_of` and pass them to every output writer as the `spans` and `page_spans` options, beside `page_transcripts`. The text writers ignore them; the PDF writer deliberately does not use them. EasyOCR asks `readtext` for detail=1 instead of detail=0, and Paddle reads the `rec_polys` that were already in its result dict. Both texts are byte-identical to before, checked against the real engines on a corpus image. Tesseract is left out: pytesseract's image_to_string exposes no boxes, and getting them means a second engine pass or a newer floor. Closes #55 Co-authored-by: Yvette Mankerian <yvettekm@gmail.com> Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Deploying tetrak with
|
| Latest commit: |
266998b
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://26701f28.tetrak.pages.dev |
| Branch Preview URL: | https://feat-positioned-spans.tetrak.pages.dev |
…oned layer's
Issue 54 asked whether the column-aware pass in tetrak_ocr.layout is good
enough to carry positioned output, measured before any ALTO or hOCR is
written. evaluation/ocr/reading_order.py serialises each span-carrying
backend's spans four ways on every raster fixture -- engine order, a line
sort (what a word-positioned layer reads back as), layout.reading_order,
and the shipped transcript -- and scores each against the ground truth,
with word recall beside every score as the tripwire that the pass
reorders text rather than losing any.
The result is evaluation/ocr/reading_order.csv, rendered on the research
page through a {{< reading-order >}} shortcode so the page holds no copy
of the figures, with the write-up: on the multi-column fixtures the pass
lifts EasyOCR and PaddleOCR from the line sort's interleaving to the best
local reading order measured there, Vision gains on one page and loses on
the cover, and the single-column control is near neutral on average but
costs similarity where side-by-side regions are not columns. Good enough
to ship positioned output with; the cut needs a guard for pages without
columns before the plain transcripts take the same route.
Closes #54
Co-authored-by: Yvette Mankerian <yvettekm@gmail.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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.
Closes #55. Closes #54.
Companion: scattercode/tetrak-product#153 records the measurement in brief 008's decision log and the roadmap.
Carry positioned spans (#55)
Four backends compute a box per recognised region and then threw it away, because the registry contract returns a string. They now keep it:
layout.Transcriptis astrsubclass carrying oneTextSpanper region (pixels, top-left origin, the engine's own order).ocr_image(path) -> strstill holds, so the batch pipeline, the quality gate, the harness and auto-local's winner selection are untouched, and auto-local hands back the winner's spans without knowing they are there.vision,easyocr,easyocr-hyandpaddlereturn aTranscript.marker,claude,paddle-vlandtesseractreturn a plainstras before.layout.spans_of(text)is the one accessor: the spans, orNonefor a plain string.batch.process_fileand theocrsubcommand take them off before any strip or join and pass them to every writer asspansandpage_spans, besidepage_transcripts.layout.polygon_extentturns EasyOCR's and Paddle's four-point polygons into an axis-aligned box;easyocr-hyuses it too.Measure the reading order (#54)
evaluation/ocr/reading_order.pyserialises each span-carrying backend's spans four ways on every raster fixture and scores each against the ground truth: engine order, a line sort (what a word-positioned layer reads back as, the construction brief 008 measured),layout.reading_order, and the shipped transcript. Word recall sits beside every score as the tripwire: identical across the first three by construction.evaluation/ocr/reading_order.{csv,md}hold the result, with mean rows per backend over the three multi-column fixtures (both Inside Facts pages, the Kinema ad) and the thirteen single-column controls. PDFs are out of reach because the three backends read none.{{< reading-order >}}shortcode (summary and per-backend tables) and carries the write-up; a Playwright test checks the table against the CSV, as the register tables are checked.easyocrandpaddletranscripts take the same route: a guard for pages without columns, measured on that control set. Vision's own line tolerance also trails the layout default and is a second measured change waiting.pdf_outputandlayoutdocstrings point at the harness beside the figures brief 008 recorded.Done when
TextSpans in pixels with a top-left origin alongside the transcript; backends without still return a string and the text outputs are byte-identical; writers receive the spans through the shared options; fast tests cover a backend with spans and one without.Verified
pytest -m "not slow": 419 passed (380 before).ruff checkandruff format --checkclean; Sphinx-Wbuild clean;npm run lint,npm run buildand all 32 Playwright tests pass.detail=0join and Paddle's to the oldrec_textsjoin, so the benchmark columns do not move. The harness ran over all sixteen raster fixtures with Vision, EasyOCR and PaddleOCR installed.Left out, deliberately
Tesseract.
image_to_stringnever exposes boxes. Getting them means either a second engine pass, doubling the cost of the default backend, orrun_and_get_multiple_output, which needs a pytesseract floor above the declared>=0.3. Worth its own issue once a positioned writer exists to need it.Applying the pass to the transcripts. It would move the published
easyocrandpaddlebenchmark columns, so it is a separate, measured change, and the write-up names the guard it needs first.🤖 Generated with Claude Code