Daejeon, July 27–31
1. Background
The Optical Character Recognition (OCR) technology has been improving in accuracy for historical documents, even enhanced by AI technology in recent years. However, it is still impossible to ensure full accuracy of the output. To encourage engagement with historical collections, organizations need to ensure high-quality of the OCRed output to allow users to easily access, search, and analyze. Therefore, the raw OCR’ed outputs always require human manual post-correction to leverage their quality, which requires a large time and human resources investment.
Many digitization projects use HTML-based Optical Character Recognition (hOCR) file as the OCR output format to preserve layout, reading order, and spatial relationships between text and page images, which cannot be captured by plain text files. However, most existing workflows and tools that assist manual correction focus on plain text files, but not on hOCR files. In recent years, Large Language Models (LLMs) have also been introduced to facilitate corrections of OCR outputs, but also with a focus on generic plain text improvement (Kanerva et al., 2024; Thomas et al., 2024). Therefore, librarians, archivists, and researchers are forced to choose between higher textual quality and preservation of structural metadata, or to preserve both at considerable cost.
Currently, there are no complete workflows or tools that automate the full post-correction process from the original hOCR input through a LLM-assisted correction to a valid hOCR output, facilitating text correction within hOCR files while preserving their hierarchical structure. This paper introduces a work in progress in the University of Toronto Scarborough Library's Digital Scholarship Unit that addresses this gap: a cost-effective and LLM-assisted hOCR correction workflow for historical documents situated in an executable Jupyter Notebook (.ipynb). The current experimentation uses the Google Gemini API with multiple model configurations and The Quebec Gazette in the University of Toronto Scarborough Library's Early Canadian Newspapers digital collection for testing. We argue that this workflow greatly accelerates the process of hOCR file manual correction and largely lowers the barrier to clean text within hOCR files, which is a critical first step to enable engagement with historical documents.
2. Method: Jupyter Notebook Workflow Overview
The Jupyter Notebook (.ipynb) workflow, implemented in Python, has three main stages:
Stage 1: Parsing and Batching
The initial steps include setting up the LLM API key and uploading an hOCR file and the associated page image. The system parses the raw hOCR file to extract word-level bounding boxes while maintaining the unique ID and coordinate integrity of every element (bbox). Then, it batches the extracted text and image into small batches for LLM-based correction in the later stage, which helps reduce token usage, process time, and hallucination rates compared to sending them as a full page.
Stage 2: LLM-Correction Pipeline
Both visual and raw OCR textual data in each batch are fed into selected Gemini model configurations via the API with a specific prompt that instructs the model to perform collection-specific correction, providing rules on hallucination, preservation, and how to fix common historical OCR errors, ensuring that historical orthography is preserved rather than aggressively modernized by the model.
Stage 3: Reintegration
After all batches are complete, the corrected text is mapped back into the original hOCR XML structure, which ensures the final output is a structurally valid hOCR file for human final review. The script also prints a summary that covers the total number of corrected words and processing time.
3. Case Study: The Quebec Gazette
This workflow is applied to a bilingual historical newspaper collection, The Quebec Gazette. This historical dataset can effectively test LLMs’ capability in performing corrections on multilingual text and typographical archaisms. Before applying the workflow, samples of the original hOCR files are selected for analysis to identify common correction patterns to facilitate prompt designing. Among the configurations tested, Gemini 3 Flash (medium thinking) provided the best performance for this workflow.
For evaluation, we compare the original hOCR file, the LLM-corrected hOCR file, the manually corrected hOCR file, and the image file to compare and evaluate the correction accuracy of the LLM-assisted hOCR Correction Workflow.
In the initial experiment results, several major successes and limitations had been identified:
Successes:
Limitations (focusing on the 3% errors):
While the original OCR frequently introduced hyphenation errors or "shattered" words (e.g., Coin- vs Com-), the AI correction showed a capability to reassemble split tokens when visually appropriate.
4. Conclusion and Future Refinement
This proposed workflow provides an open-source, cost-effective, and LLM-assisted alternative for libraries and archives to accelerate the process of correcting hOCR files of their historical document collections, which makes the processing cost of high-quality hOCR files more manageable and high-quality digitization more accessible to institutions with different scopes, encouraging engagement with historical documents that previously were less accessible, searchable, and analyzable for users.
While results varies as models and costs evolve, this study demonstrates the workflow’s practical viability. Continuous experiment, evaluation, and refinement will be done to improve correction accuracy by refining prompts and rules based on result analysis.