LLM-Based OCR Error Detection
Welcome to the documentation for Codexis's LLM-based OCR error detection system. This system uses locally-hosted Large Language Models (LLMs) via Ollama to detect and correct OCR errors (scannos) in digitized manuscripts.
What is Scanno Detection?
"Scannos" are OCR (Optical Character Recognition) errors that occur during the digitization process. Common examples include:
- Character substitutions:
rn→m,cl→d - Merged words:
oftheinstead ofof the - Split words:
be causeinstead ofbecause - Punctuation errors:
,→.or:→;
Traditional pattern-matching approaches catch many errors, but LLMs excel at detecting context-dependent errors that rule-based systems miss.
System Overview
Our LLM-based scanno detection system:
- Uses locally-hosted models via Ollama (no external API calls)
- Processes LaTeX manuscripts with special handling for mathematical content
- Provides interactive review interface for corrections
- Integrates seamlessly with the Codexis build pipeline
- Supports parallel processing for large documents
Documentation Structure
- Overview - System architecture and prerequisites
- Ollama Client - Interface for interacting with local LLMs
- LaTeX Processor - Extracts and prepares content for analysis
- Scanno Detector - Core detection engine
- Specialized Detectors - Handles math, LaTeX commands, bibliography
- Pattern Filter - Pre-filtering with known error patterns
- Result Aggregator - Combines and validates corrections
- Human Review - Interactive review interface
- Build Integration - Pipeline integration and automation
- Configuration - System configuration options
- Testing - Testing strategies and examples
- Troubleshooting - Common issues and solutions
- Product Requirement Document - Product plan
Quick Start
Prerequisites
-
Install Ollama:
# macOS brew install ollama # Linux curl -fsSL https://ollama.ai/install.sh | sh -
Pull required models:
ollama pull qwen3.0:8b ollama pull deepseek-r1:8b -
Add dependencies to
mix.exs:defp deps do [ {:req, "~> 0.5.0"}, {:jason, "~> 1.4"}, {:nimble_pool, "~> 1.0"}, {:flow, "~> 1.2"} ] end
Basic Usage
# Check a manuscript for OCR errors
{:ok, result} = Codexis.BuildManager.ScannoIntegration.check_manuscript_for_scannos(
"manuscript.tex",
model: "qwen3.0:8b",
interactive: true
)
IO.puts("Corrections applied: #{result.corrections_applied}")
CLI Usage
# Check a manuscript with interactive review
mix codexis.check_scannos manuscript.tex
# Use specific model
mix codexis.check_scannos manuscript.tex --model deepseek-r1:8b
# Non-interactive mode
mix codexis.check_scannos manuscript.tex --no-interactive
Key Features
1. Multi-Model Support
- General text: Qwen2.5 models (3B, 7B, 14B)
- Mathematical content: DeepSeek-R1 8B
- Code and technical: CodeLlama 7B
2. Parallel Processing
- Processes text blocks concurrently
- Configurable concurrency limits
- Efficient handling of large documents
3. Pattern-Based Pre-filtering
- Known OCR error patterns
- Custom pattern support
- Learning from corrections
4. Interactive Review
- Confidence-based grouping
- Context visualization
- Keyboard navigation
- Progress saving
5. Build Pipeline Integration
- Automated detection during builds
- CI/CD integration
- Caching for improved performance
Performance Considerations
- Model Selection: Balance accuracy vs. speed
- Parallel Processing: Adjust concurrency based on hardware
- Caching: Enable for repeated processing
- Batch Size: Optimize for your content type
Best Practices
- Start with default configuration
- Test on small documents first
- Adjust confidence thresholds based on results
- Use interactive review for critical documents
- Enable caching for better performance
- Monitor resource usage
Next Steps
- Read the Overview to understand the system architecture
- Configure your system with optimal settings
- Integrate with your build pipeline
- Set up testing for your use case
Support
If you encounter issues:
- Check the Troubleshooting Guide
- Review Common Issues below
- Contact the development team
Common Issues
- Ollama connection errors: Ensure Ollama is running
- Model not found: Pull required models with
ollama pull - Slow performance: Use smaller models or reduce concurrency
- Memory issues: Process in smaller chunks
Contributing
To contribute to the scanno detection system:
- Read the architecture documentation
- Follow Elixir coding standards
- Add comprehensive tests
- Update documentation
License
This system is part of the Codexis project and is licensed under the same terms.