LLM-Based OCR Error Detection with Ollama
This document describes how to implement Large Language Model (LLM) based OCR error detection (scanno detection) in the Codexis book digitization system using locally-hosted models via Ollama.
Overview
OCR errors, commonly called "scannos," are a persistent challenge in book digitization. While traditional pattern-matching approaches catch many errors, LLMs excel at detecting context-dependent errors that rule-based systems miss. This implementation uses Ollama with open-source models like Qwen2.5 or DeepSeek-R1 to provide high-quality scanno detection without relying on external APIs.
Key Benefits
- Privacy: All processing happens locally
- Cost-effective: No API costs after initial setup
- Customizable: Can fine-tune models for specific content types
- Context-aware: Better understanding of domain-specific terminology
- Offline operation: Works without internet connectivity
Prerequisites
-
Ollama Installation:
# macOS brew install ollama # Linux curl -fsSL https://ollama.ai/install.sh | sh -
Model Installation:
# For general text and code understanding ollama pull qwen3.0:8b # For reasoning-heavy tasks ollama pull deepseek-r1:8b # Optional: Smaller model for faster processing ollama pull qwen2.5:3b -
Elixir Dependencies:
# In mix.exs defp deps do [ {:req, "~> 0.5.0"}, # HTTP client for Ollama API {:jason, "~> 1.4"}, # JSON parsing {:nimble_pool, "~> 1.0"}, # Connection pooling {:flow, "~> 1.2"} # Parallel processing ] end
Architecture
graph TD
A[LaTeX Manuscript] --> B[Text Extractor]
B --> C[Content Segmenter]
C --> D[Parallel LLM Processors]
D --> E[Result Aggregator]
E --> F[Correction Validator]
F --> G[Human Review Interface]
G --> H[Applied Corrections]
subgraph "Ollama Local Models"
D --> I[Qwen2.5 7B]
D --> J[DeepSeek-R1 8B]
D --> K[Specialized Models]
end