Skip to content

Building the document record and grading its text lines

The ocr-postprocess workflow. Tool: atrium-ocr-postprocess.

Purpose

Every document in the AMČR pipeline reaches this tool as docproc, the layout format of digital-convert and the ATR (AIS CR's text-recognition service). The ATR's docproc holds what it read from the scans; digital-convert's holds the text layer of a born-digital file. This workflow builds the ATRIUM document record from that layout: a row for every page of the original, the text lines in reading order with their boxes, and the document's text. For a mixed document it merges the two docprocs and keeps the born-digital lines where the text layer is good. It then labels every line with its language, a quality score and one of five categories. Later stages work on the readable lines, and an archive can see which pages are legible. For research collections, the same labelling runs as a batch pipeline over OCR output, ALTO first, and over text-bearing files such as PDF or DOCX.

At a glance

In docproc (atr/docproc-json): the ATR's, digital-convert's, or both for a mixed document; optionally AMČR's seed (the document's identifier and the SHA-512 of its original) or a record page-classification already wrote; for scoring alone, an existing ATRIUM document record (JSON). For research batches: ALTO XML (v2–v4), PAGE XML, hOCR, ABBYY FineReader XML, DjVuXML, Tesseract TSV, OCR JSON, PDF text layers, office, e-mail and plain-text files, as listed in the tool's input-format reference
Out the ATRIUM document record (JSON), every line scored; the run's paradata (JSON). For research batches: page texts, per-document tables of text lines with their language, quality score and category (CSV), per-page category counts and ratios (CSV), a report of what was read (CSV), paradata logs (JSON), optionally records
Runs as an HTTP service image, atrium-ocr-postprocess-api (POST /build_record, the pipeline's call; POST /score_record; POST /process for research uploads); the same from the command line (build_record.py, score_record.py); a batch pipeline (run_pipeline.py, or one script per step) and its container image; an Agent Skill
Compute the published images run on the CPU, and building a record needs no GPU; the batch classification and the layout-aware reading order are faster on a GPU, from a local CUDA build of the same Dockerfile; the batch's GLM method needs about 48 GB of GPU memory
Network the Hugging Face Hub when the service first starts, for Qwen2.5-0.5B and LayoutReader at the Hub's current revision; without that access it stops at startup. The images already hold the language-identification model
Code licence MIT; the vendored alto-tools are Apache-2.0
Component licences the language-identification model (CC BY-NC 4.0) on every run; Qwen2.5-0.5B (Apache-2.0) when lines are scored; the layout-aware reading-order model (CC BY-NC-SA 4.0) when it orders ALTO lines; the full list is below. No licence of an output is computed: Licences and paradata
Record SSH Open Marketplace tool YParYU

Steps

Building the record, as the AMČR pipeline calls it (POST /build_record):

# Step What happens In → out Activity
1 Read the docproc Pages by number, blocks in reading order. A block's own lines keep their boxes; a block without lines is split at its line breaks, and a table gives one line per row. An image block without text gives no line. A page the docproc neither lists nor marks empty, or a block whose text could not be read, fails the job. docproc → pages and lines Extracting
2 Merge a mixed document A page digital-convert sent to the ATR takes the ATR's lines. Every other page keeps digital-convert's exact lines, each linked to the ATR block that holds it, and an ATR block that received no kept line adds its own lines. The order is the ATR's. Two docprocs that disagree on the pages, the forced pages or the page sizes fail the job. two docprocs → pages and lines Merging
3 Classify every text line A pre-filter labels blank lines Empty, and numbers, dates, codes and stamps Non-text, with no model. Every other line gets its language, a quality score from structural checks, character-level measures and a language model's perplexity, and one of the other three categories. Passes over the whole document then correct isolated mistakes. lines → scored lines Text Categorization
4 Write the record source (the seed's identity, the origin, the page count and the language); a row in pages for every page of the original, with its size; the lines, each with its block, text source and box; content; every line's category, score and language; each page's score and band; and quality_summary. The record is validated before it is written; a failed step writes nothing. → the record (JSON), paradata —

Research batches (run_pipeline.py):

# Step What happens In → out Activity
1 Split into pages ALTO and OCR JSON documents are split into one file per page, named after the document and the page number. Any other file is recognised by its content and read into pages of lines, with a report of what was read and what was refused. ALTO, JSON, other formats → ALTO, JSON, TXT Segmenting
2 Build page statistics For every page: its text lines, illustrations, graphics and words, in one table per collection. ALTO, JSON, TXT → CSV —
3 Extract the text The text of each page is extracted by one of five methods: in reading order by a layout-aware model (LayoutReader, the default for ALTO), in ALTO's own order (alto-tools; the service's reading_order=alto), from the page image by a vision-language model (GLM), from the text keys of OCR JSON (json-keys), or line by line from any other format (text-lines). ALTO, JSON, TXT → TXT Extracting
4 Classify every text line As step 3 above, with the same function, then the same passes over each document. TXT → CSV Text Categorization
5 Aggregate The line categories are counted per page, with each category's share and the page averages, in one table for the collection and one per document, so a collection can be judged at a glance. CSV → CSV Aggregating

The five categories:

Category What it means for the line In the pipeline
Clear legible; nobody needs the page image to read it goes on to language processing and keywords
Noisy readable, with recognition errors to correct goes on as well
Trash illegible left out of language processing and keywords
Non-text not language — numbers, codes, stamps, dates goes on; worth checking for identifiers
Empty only whitespace left out

No step sends a Trash page back for another recognition pass; re-processing is a later, separate campaign.

Lines, blocks and boxes. digital-convert's blocks carry their own lines, so a born-digital line keeps the box digital-convert measured (bbox_precision: measured, text_source: text-layer). The ATR's blocks carry none: each is split at its line breaks, and every line takes the block's box (derived, text_source: atr). A block without a line break becomes one line marked unit: block, because a one-line heading cannot be told from a paragraph that lost its breaks. Such a line is scored, but it counts toward neither its page's score nor its band.

Whole documents and single uploads. Every path runs the same pre-filter and scores a line with the same function. Building or re-scoring a record, and the batch pipeline, run the passes over the whole document. POST /process answers each line of an upload on its own, so its categories can differ on the same document.

Perplexity in batches. The language model scores lines in batches: 128 lines at a time in the batch pipeline, 32 in the service (PPL_BATCH_LINES). A batch that runs out of memory is split in halves and retried, down to a single line. A line longer than the model's window, or one it cannot score, fails its document, in the batch as in the service.

Two side workflows use the same tool: measuring which rules and constants drive the categories (Pipelines → W9), and reading PDF, office files and other OCR exports into per-line tables (Pipelines → W11).

What you get

  • The record — <doc_id>.document.json from build_record.py, or document_json in the service's answer. Every line has its category (categ), quality score and language. A page with text has a band (quality_band) and, when it holds Clear or Noisy lines, a score. quality_summary counts the pages and the lines per category.
  • A provenance record — <run_id>-<8 hex>_ocr-postprocess.json, the paradata of the run; the service returns the same record in its answer (paradata).
  • Tables for a research collection — DOC_LINE_CATEG/<doc>.csv, one row per line with its measurements; DOC_LINE_STATS/stats_<doc>.csv and samples_page_stats.csv, one row per page with its category counts and ratios; the page texts; and pages_report.csv, what was read and what was refused.
  • Answers for single uploads — POST /process returns every line of a page or a document with its language, score and category (cleaned_lines).

How to read them. The category, not the score, is the decision. A page's score is the mean of its Clear and Noisy lines, block units left out, so read it together with the page's Trash lines. Every column is described in Reference → Outputs, and every record field in Reference → The document record.

In the AMČR pilot the record is atrium/document-json, built from the docproc AMČR stores. The later steps add to it, and AMČR stores it with the job's other outputs.

Limits

  • The rules are Czech-first. They were calibrated on Czech archaeological reports with German and English passages, and several act on every line whatever its language. A clean English, German or French line can read Noisy, a German compound Trash, and an upper-case word Non-text. A language outside the expected and trusted ones is stored as Czech: ces_Latn in the batch tables, cs in the record, which states every line's language as ISO 639-1 and leaves it out for a language without a two-letter code. The categorisation reference lists the foreign-language cases.
  • A short Clear is less certain. On a line of one to three words without Czech diacritics, Clear is less certain than it looks: about 26,000 genuine garbage lines over both AMČR collections read Clear.
  • Measured, not validated. The category rules are frozen for the AMČR pilot. Their accuracy has been measured on 2,067 hand-labelled lines and on corpus diffs, not validated in full; the tests pin the rules, not their accuracy (what was measured).
  • Not every page has a score. An empty page has neither score nor band. A page with no Clear or Noisy line outside block units has no score.
  • Lines without their own box share their block's. The ATR's lines carry their block's box, so positions derived from them later, such as word boxes, are estimates.
  • A failed step fails the job. A record build that cannot finish writes nothing: there is no partial output. The batch pipeline writes nothing for a file, page or line it cannot read or score whole, processes the others, then stops at that step. From 2.0.2-beta (on test), a stage that crashes, or an extractor given a page list without a page, records failed in its paradata, and the run summary says failed with the reason. POST /process refuses an upload whose reading lost content; the parts it leaves out by design, such as headers and footers, are recorded in the paradata's limits. The outputs of both are for research collections, not for writing to AMČR.
  • A limit refuses rather than trims. An upload over MAX_UPLOAD_MB (25 MB a part) is refused with 413. A limit that would trim, skip or stop content refuses the request instead of returning part of a result. The runbook's Limits lists every setting.
  • Two models are fetched at start. The service downloads Qwen2.5-0.5B and LayoutReader on its first start, at the Hub's current revision; staging them once is the runbook's advice for a host without that access.

Provenance and licence

Every run records paradata: what it read and wrote, as AMČR distributions by name and SHA-512, and the components it used, each with its own licence, as declared in the tool's setup/para_config.txt. The service returns them with every response as one Process Run Crate action (CreateAction) and writes no file. build_record.py writes <run_id>-<8 hex>_ocr-postprocess.json; each batch step writes its own log, and a whole-pipeline run merges them into one run summary (<run_id>-<8 hex>_ocr-postprocess_pipeline-run.json).

Component Licence Used when
alto-tools, vendored (alto_tools) Apache-2.0 listed by every run; it splits pages, counts the statistics and extracts text by ALTO's own order
FastText language identification (fasttext) CC BY-NC 4.0 listed by every run; it identifies the language of each line
Qwen2.5-0.5B (qwen2.5_0.5b) Apache-2.0 the default perplexity model scored lines
distilgpt2 (distilgpt2) Apache-2.0 the English-only perplexity model scored lines instead
LayoutLMv3 through LayoutReader (layoutlmv3) CC BY-NC-SA 4.0 LayoutReader ordered ALTO lines: the batch's default method, and POST /process on ALTO
GLM-4v-9b (glm4v_9b) GLM-4 licence the batch's GLM method read text from page images
pypdfium2 (pypdfium2) Apache-2.0 a PDF text layer was read (the text-lines method, POST /process)
charset-normalizer (charset_normalizer) MIT plain text that is not UTF-8 was read

pypdfium2 is licensed Apache-2.0 or BSD-3-Clause. Each run lists the components it used, each with its own licence or terms. No licence of an output is computed: the rights in an output follow the source document (Licences and paradata).

In the document record the tool is the record builder. It writes source, pages, lines and content, and, as the only scorer, every line's categ, quality_score and lang, every page's quality_score and quality_band, and quality_summary. That summary holds page-score statistics and line counts per category, recomputed whenever the tool writes or scores pages and lines. It is numbers only, with no band or threshold, and nothing in the pipeline routes on it. The record carries no run data.

Where it sits

  • The record builder of the AMČR pipeline, after digital-convert and the ATR and before nlp-enrich and keyword-extract; page-classification's categories join the page rows it writes — Pipelines → The route through the pipeline and W1.
  • Born-digital and mixed documents: the record of a born-digital document is built from digital-convert's docproc, and that of a mixed document from both docprocs — Pipelines → W2 and W3.
  • ALTO post-processing and OCR quality control step of the AMČR text workflow 0xSpVP.
  • Also used in W4 (as a service), W5 (from a coding agent), W6 (both end-to-end lanes), W9 (the rule sweep) and W11 (format adaptation).

On other platforms

SSH Open Marketplace. Tool record YParYU.

Galaxy sheet. The Galaxy wrappers were handed to DARIAH for testing; further Galaxy work is parked during the AMČR pilot. The sheet describes the wrapper as the hub's galaxy/ folder holds it, at 2.0.1-beta+galaxy0.

Workflow inputs one OCR document per job — ALTO as xml (DARIAH's Galaxy has alto only as an alias of xml), OCR JSON — json, or a text-bearing file: txt, csv/tsv with a text column, html (hOCR), xml (PAGE), pdf, docx, xlsx, markdown; optionally a document record to add to — json
Parameters the reading method (text-lines, the default, for ALTO and the text-bearing formats; alto-tools for ALTO; json-keys for OCR JSON); line quality only: the expected languages (ces,deu,eng) and the perplexity model (downloaded or staged)
Workflow outputs the document record — json; paradata — json; page statistics — csv; page texts — a list of txt; with text-lines, the line table — csv (file,page_num,line_num,text,page_label) and the pages report — csv; with alto-tools, per-page ALTO — a list of xml; line quality only: lines with their category and the categories per page — csv
Container ghcr.io/ufal/atrium-ocr-postprocess:<version> — the batch image (run_pipeline.py); it runs the job script Galaxy hands it (the hub-canonical container_entrypoint.py). The pipeline starts its stages by name from /app, so a job script runs it there, with a config of absolute paths. The service image -api is not used
Galaxy tool atrium_ocr_postprocess (CPU: split, statistics, extract) and atrium_ocr_line_quality (GPU: the same, then classify and aggregate), 2.0.1-beta+galaxy0, with the data manager ATRIUM Hugging Face models for Qwen2.5-0.5B, in the hub's galaxy/ folder. It is a step of two workflows: ATRIUM OCR to keywords, and ATRIUM born-digital documents to keywords, where its text-lines method reads the original documents and builds their records. For DARIAH's test Galaxy (https://galaxy.acdh-dev.oeaw.ac.at/galaxy/), the line-quality tool needs an instance with GPUs
Compute CPU for splitting, statistics and text extraction. The batch line classifier (Qwen2.5-0.5B) needs a CUDA GPU; on a CPU, score_record.py scores records with the service's models
Network or reference data the fastText language-identification model is in the image; Qwen2.5-0.5B and LayoutReader come from the Hugging Face Hub, or are staged once
Test data three of the synthetic data_samples/ — an ALTO page, a CSV and OCR JSON — under CC BY-NC 4.0, and an XML file that is not ALTO for the error test
Credit the authors in the tool's CITATION.cff, with their ORCIDs; licence MIT
Closest Galaxy tools the OCR tools that write ALTO and come before this step: Tesseract (IUC, installed on DARIAH's instance, ALTO as xml) and Kraken; none classifies OCR quality line by line

Sources

Read from ufal/atrium-ocr-postprocess at release v2.0.1-beta (tagged 2 December 2026), from its last pull request, on 2026-12-02; what is marked "from 2.0.2-beta" was read from its test of 3 December 2026 (the v2-beta-d13 pull request). Earlier readings were at v2.0.0-beta (6008e0c, 2026-11-29), of test before that release (2026-11-21), and at v1.15.0-beta (2026-10-29), v1.13.1-beta (2026-10-27) and v1.12.0-beta (2026-10-16). The tool was named alto-postprocess until 1 October 2026; the repository continues ufal/atrium-alto-postprocess, archived on 2026-10-19. The Galaxy sheet (2026-12-02) follows 2.0.1-beta+galaxy0 and the hub's galaxy/ folder. This table records provenance, not a build instruction.

Source What was taken from it
README.md, docs/usage.md purpose, the entry points, the step order, the categories, what the command line and the service do differently
service/README.md §§ Building the record, Limits, Partial results, Known limits, Models and caches the service, the merge and its refusals, the limits, the models fetched at start
build_record.py, docproc.py, docproc_merge.py, record_scoring.py, service/text_api.py building the record from docproc, block units, page scores and bands, the failures
docs/reference/outputs.md, docs/reference/paradata.md the outputs, the record fields, the paradata and their file names
docs/text_inputs.md; docs/categorization_logic.md; docs/reference/categorization_rules.md § Foreign-language lines the research input formats; the pre-filter, the language tiers, the known limits
docs/evaluation/categorization.md, docs/decisions/2026-10-categorization.md what was measured; the frozen rules
text_util.py (calculate_perplexity_batch), tool_limits.py, atrium_limits.py, setup/config.txt perplexity in batches, the limits, the default method and batch size
page_split.py, text_split.py, extract_LLM_ALTO_2_TXT.py, classify_TEXT.py, aggregate_STAT.py the inputs and outputs of the batch steps
atrium_document.py (BLOCK_OWNERS, BLOCK_FIELD_OWNERS) the record fields the tool writes
setup/para_config.txt, para_licenses.py the licence components and when each is listed
Dockerfile, docker-compose.gpu.yml the images, their CPU build, the model inside them
data_samples/README.md, data_samples/LICENSE, CITATION.cff test data; credit
SSH Open Marketplace YParYU the record identifier
the hub's galaxy/tools/atrium_ocr_postprocess/ and galaxy/workflows/atrium_ufal/ (workflows 0.5.0) the Galaxy sheet
usegalaxy-eu/usegalaxy-eu-tools; galaxyproject/tools-iuc; bgruening/galaxytools the Galaxy datatypes and analogues