BUCKYVERSE

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

  1. Privacy: All processing happens locally
  2. Cost-effective: No API costs after initial setup
  3. Customizable: Can fine-tune models for specific content types
  4. Context-aware: Better understanding of domain-specific terminology
  5. Offline operation: Works without internet connectivity

Prerequisites

  1. Ollama Installation:

    # macOS
    brew install ollama
    
    # Linux
    curl -fsSL https://ollama.ai/install.sh | sh
    
  2. 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
    
  3. 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