llm_aided_ocr
Enhances Tesseract OCR output using LLMs (local or API) for error correction, smart chunking, and markdown formatting of scanned PDFs
What is llm_aided_ocr?
Enhances Tesseract OCR output using LLMs (local or API) for error correction, smart chunking, and markdown formatting of scanned PDFs
Overview of llm_aided_ocr
What it is
LLM-Aided OCR is an open-source system that enhances Tesseract OCR output using large language models (LLMs). It corrects OCR errors, applies smart text chunking, and formats the result as Markdown. The project supports both local LLMs (via llama.cpp) and cloud-based API providers (OpenAI, Anthropic). It processes scanned PDFs by converting pages to images, running Tesseract OCR, then feeding the raw text through an LLM pipeline for correction and formatting. The system includes asynchronous processing, token management, duplicate content removal, and optional header/page number suppression. A quality assessment step compares the original OCR text with the final output.
Key features
- PDF to image conversion and OCR using Tesseract with image preprocessing (grayscale, Otsu thresholding, dilation).
- Error correction and Markdown formatting via LLMs (local or API-based: OpenAI, Anthropic).
- Smart text chunking with sentence-boundary splits and overlap to maintain context.
- Duplicate content removal and optional header/page number suppression.
- Asynchronous concurrent processing of chunks when using API-based LLMs.
- Quality assessment that compares original OCR text with processed output and provides a score.
- Support for both local LLM inference (GPU-accelerated) and cloud API providers.
Use cases
This project is suited for anyone who needs to convert scanned PDFs into clean, well-formatted Markdown or text documents. Typical use cases include digitizing books, historical documents, research papers, and legal or financial records where OCR accuracy is critical. It can be used in archival workflows, data extraction pipelines, or any scenario where raw Tesseract output requires significant correction and structuring. The optional offline mode (no LLM) provides deterministic cleanup for users who cannot or prefer not to use an LLM.
Getting started
bashgit clone https://github.com/Dicklesworthstone/llm_aided_ocrcd llm_aided_ocrpyenv local 3.12python -m venv venvsource venv/bin/activatepython -m pip install --upgrade pippython -m pip install wheelpython -m pip install --upgrade setuptools wheelpip install -r requirements.txtInstall Tesseract OCR engine (e.g., sudo apt-get install tesseract-ocr on Ubuntu). Set up a .env file with your LLM provider and API keys. Then run:bashpython llm-aided-ocr-cli.py your_document.pdf
License and pricing
The license is not stated in the repository metadata or README. The project is listed as open source.
Based on the project's public README and repository metadata.