High-Compression Visual-Text OCR Architecture and Engineering Practices

    This article explores the architecture and engineering practices of high-compression visual-text OCR systems, addressing traditional challenges such as layout loss and high inference costs. It details how to balance compression ratio and readability, implements a lightweight visual encoder with a sparse expert decoder, and utilizes multi-tier configurations with dynamic cropping. Additionally, the article covers the end-to-end inference pipeline, batch processing, and practical evaluation and tuning strategies for real-world deployment.

    High-Compression Visual-Text OCR Architecture and Engineering Practices

    In document recognition and image-to-text scenarios, traditional solutions often face three major challenges: first, pure text pipelines tend to lose reading order and table structures in complex layouts; second, high-resolution pages generate a massive number of visual tokens, causing inference costs to scale rapidly with resolution; third, when long documents are fed into large language models (LLMs), context length and memory mechanisms become bottlenecks. The core concept of high-compression visual-text OCR is to treat “rendering long text into images” and “restoring images back to text” as a learnable compression-decompression process. This redefines the role of the visual encoder from an LLM perspective: it must not only extract text but also preserve layout, reading order, and structural clues.

    1. Core Objective: Balancing Compression Ratio and Readability

    These solutions typically render document pages into highly compressed images, extract visual tokens via a visual encoder, and finally generate structured text through a decoder. The key is not to pursue the single highest compression ratio, but to establish an adjustable curve of “compression ratio—token count—recognition accuracy.” In engineering, the compression ratio can be understood as the ratio of page information density to the visual token budget. When the compression ratio is low, text strokes, table lines, and small-font annotations are well preserved, leading to higher recognition accuracy. As the compression ratio increases, the number of visual tokens decreases, and the model must rely on language priors to complete the information, causing accuracy to gradually decline. Therefore, a sound approach is to provide multi-tier configurations, allowing users to dynamically choose based on document type, hardware budget, and accuracy requirements.

    In public document parsing benchmarks, an upgraded approach uses improved visual encoding and query rearrangement mechanisms, enabling fewer visual tokens to cover common documents. When the token count increases to the hundreds, it can further outperform traditional pipeline-based parsing methods. It is important to emphasize that specific values will vary with datasets, resolutions, and post-processing strategies. In real-world deployment, an evaluation set should be built using your own business samples rather than directly applying a single metric.

    2. Layered Architecture: Lightweight Visual Encoder and Sparse Expert Decoder

    A typical high-compression OCR architecture consists of a visual encoder and a text decoder. The visual encoder can adopt a lightweight language model as its backbone, replacing traditional contrastive learning visual components. The advantage is that language models already possess certain capabilities regarding character morphology, typography rules, and semantic correlations during pre-training, which helps preserve the original image’s layout information while extracting text content. The decoder can adopt a sparse Mixture-of-Experts (MoE) structure, keeping the total parameter count at a few billion while controlling the active parameters per inference to a sub-billion level, thereby reducing inference costs.

    A schematic configuration is as follows:

    1. pipeline:
    2. encoder:
    3. type: lightweight_language_vision
    4. input_resolution: adaptive
    5. decoder:
    6. type: sparse_moe
    7. total_params: few_billion
    8. active_params: sub_billion
    9. visual_tokens:
    10. min: 256
    11. max: 1120
    12. adaptive: true
    13. output:
    14. - plain_text
    15. - layout_boxes
    16. - markdown
    17. compression:
    18. render_scale: adaptive
    19. crop: dynamic

    The key to this structure is “the encoder preserves layout, and the decoder restores structure.” The encoder outputs visual tokens with spatial and sequential clues. The decoder, through causal queries or learnable query mechanisms, dynamically rearranges image fragments, ensuring that reading order, table rows and columns, and paragraph hierarchies are explicitly modeled during the generation phase.

    3. Multi-Tier Configurations and Dynamic Cropping: Covering Diverse Scenarios with One Model

    To accommodate edge devices, standard servers, and complex layouts, engineering practices often provide multiple tiers such as compact, small, base, large, and mixed-size. Among them, the mixed-size tier targets complex documents, using non-square mixed-size inputs like 1024×640, and features built-in bounding box detection and dynamic cropping strategies: it first detects areas like titles, body text, tables, and images, then crops them into several fragments based on information density, and finally feeds these fragments into the encoder in reading order. This prevents token inflation from high-resolution full pages while reducing the over-compression of small-text regions.

    Dynamic cropping needs to be linked with the token budget. A recommended strategy is to first establish a layout skeleton using a low-resolution full-page image, then perform local high-resolution cropping on text-dense regions. Table and formula areas should be marked separately to avoid being fragmented by standard text cropping strategies. Headers, footers, and page numbers can be given lower priority to save tokens. For batch processing, documents can be grouped by type to standardize compression ratios and output formats, reducing repetitive parameter tuning.

    4. Inference Pipeline and Batch Processing

    A deployable inference pipeline can be abstracted as: document parsing, page rendering, layout detection, dynamic cropping, visual encoding, structured decoding, post-processing, and output. The output can simultaneously include plain text, bounding boxes, and Markdown, facilitating downstream retrieval, archiving, and LLM consumption. The premise for a single mainstream accelerator card to process hundreds of thousands of pages daily is batch scheduling, pipeline parallelism, and cache reuse. Actual throughput is affected by page complexity, resolution, token limits, and post-processing rules.

    Schematic pseudocode is as follows:

    1. def ocr_page(page, config):
    2. image = render(page, scale=config.render_scale)
    3. regions = detect_layout(image)
    4. crops = dynamic_crop(image, regions, token_budget=config.visual_tokens)
    5. visual_tokens = encode_vision(crops)
    6. visual_tokens = reorder_by_causal_query(visual_tokens)
    7. text, boxes = decode_structured(visual_tokens, max_tokens=config.max_tokens)
    8. return postprocess(text, boxes, format=config.output_format)
    9. def batch_ocr(pages, config):
    10. results = []
    11. for batch in make_batches(pages, size=config.batch_size):
    12. results.extend(map(lambda p: ocr_page(p, config), batch))
    13. return results

    In cloud deployment, general object storage can be used to save page images and results, container platforms can handle elastic scaling, and logging services with monitoring alerts can track throughput, failure rates, and token consumption. For sensitive documents, access control and data masking strategies should be implemented during rendering, caching, and output phases.

    5. Evaluation and Tuning Recommendations

    Evaluation should not focus solely on character accuracy; it should also cover reading order, table structure, formula restoration, layout box accuracy, and long-document consistency. It is recommended to build a tiered evaluation set: simple single-column, complex multi-column, table-dense, scanned noise, handwritten annotations, etc. The tuning sequence can start by determining the acceptable accuracy floor for the business, then gradually reducing the visual token budget to find the cost inflection point. Retain high-resolution tiers for high-value documents, while using high-compression tiers for bulk archived documents supplemented by post-processing verification. Only by binding compression ratio, token budget, and business accuracy can high-compression visual-text OCR consistently deliver value in real-world systems.