High Compression Ratio Document AI: A Practical Guide to Visual-Text Compression

    This guide explores how high compression ratio document recognition maps page information into a minimal number of visual tokens. It covers the encoder-decoder architecture, resolution and token budget configurations, dynamic layout reordering, the full processing pipeline from image to structured output, and evaluation and tuning practices for balancing accuracy, cost, and throughput.

    1. Why Visual-Text Compression Deserves Its Own Discussion

    Traditional document recognition assumes that an image is merely a carrier of text and can be discarded once recognition is complete. In real business scenarios, however, contracts, reports, invoices, and technical manuals often contain multi-column layouts, cross-page tables, stamps, and annotations. The layout itself is part of the semantics. This raises a more fundamental question: can we map the information on a document page into the input space of a language model without loss, using fewer visual tokens?

    This is the core of research on the visual-text compression boundary. It treats the visual encoder as a compressor with controllable loss, and uses the curve between compression ratio and recognition accuracy to measure system capability. Public industry exploration shows that at a compression ratio of about 10x, recognition accuracy can remain above 90%, while at 20x compression there is still about 60% usable accuracy. This curve determines the engineering balance point between “saving cost” and “remaining usable.”

    2. Overall Architecture: Dividing Responsibilities Between Encoder and Decoder

    These solutions generally adopt a combination of a lightweight visual encoder and a sparse mixture-of-experts decoder, with total parameters controlled at the billion level (about 3B) and only a few hundred million activated parameters. There are three key design points:

    1. The encoder handles compression: It converts fixed-size image patches into a small number of semantic vectors, with a configurable token count (for example, in the range of 256 to 1120), rather than growing linearly with resolution.
    2. The decoder handles generation: It uses a mixture-of-experts structure that activates only some pathways, enabling it to output structured text such as Markdown under limited compute.
    3. The connection layer performs semantic alignment: A projection module maps visual features into the word vector space of the language model, ensuring consistency between “seeing clearly” and “writing accurately.”

    A notable paradigm shift is worth mentioning: early solutions often chained a general-purpose visual foundation model with a segmentation model, using a “segment to extract regions, then extract features” approach to handle both global and local information. The newer approach directly uses a lightweight language model as the visual encoder, naturally preserving 2D layout information while extracting text, and eliminating the dependency on additional visual components. This shows that encoder selection is shifting from “stacking visual modules” to “using language priors to constrain visual extraction.”

    3. Resolution and Token Budget: Engineering Implications of Five Configurations

    The tiered configurations (Tiny / Small / Base / Large / Gundam) essentially turn the “total input pixels” and “output token budget” into adjustable knobs:

    • Small configurations are suitable for single-layout scenarios such as mobile devices and invoices, aiming for millisecond-level response;
    • Medium configurations cover standard A4 documents;
    • Large hybrid configurations (such as 1024×640) target professional documents with multiple columns and mixed text and images, combined with a dynamic cropping strategy that first performs coarse localization and then fine reading.

    The token budget is the cost switch. A phenomenon in public evaluations is quite revealing: with only about 100 visual tokens, the system can surpass the previous generation of end-to-end recognition solutions, while about 800 tokens outperform mainstream layout parsing tools. The engineering recommendation is to make the token budget a runtime parameter and allocate it adaptively according to page complexity.

    1. # Example: dynamically allocate visual token budget based on layout complexity
    2. def plan_tokens(page, base=256, cap=1120):
    3. blocks = page.segment() # coarse-grained layout blocks
    4. cols = page.detect_columns() # column count estimation
    5. score = 0.6 * len(blocks) + 0.4 * cols
    6. budget = min(cap, int(base * (1 + score / 10)))
    7. return budget if page.has_table() else max(base, budget // 2)

    4. Dynamic Reordering and Causal Flow Queries

    The second-generation encoder introduces “learnable causal flow queries.” Instead of scanning image patches in a fixed raster order, it dynamically reorders patch sequences based on content relevance. The benefit is that in scenarios such as cross-column reading order, header and footer interference, and interspersed illustrations, the model can read the main content first and then fill in details, reducing repeated encoding. In implementation, this can be understood as maintaining a set of trainable query vectors inside the encoder and using attention to determine the reading order of the next batch of image patches, thereby “flattening” the 2D layout into a 1D causal sequence.

    5. From Image to Structured Output: The Complete Pipeline

    1. Input adaptation: PDFs are rasterized page by page; scanned documents first undergo denoising, deskewing, and black border removal;
    2. Layout preprocessing: connected component analysis produces block-level bounding boxes; oversized pages use hybrid sizes and dynamic cropping;
    3. Batch inference: single-card throughput can reach on the order of 200,000 pages per day, with in-batch length bucketing to reduce padding waste;
    4. Post-processing: tables are restored into structured row and column lists; reading order is fused and corrected based on block coordinates and causal flow results;
    5. Output and archiving: unified Markdown output is produced, with images and tables referenced as placeholders, and original page images stored in object storage for traceability.
    1. # Example: batch task submission (pseudo-command, expressing the workflow only)
    2. pipeline run --input ./pdfs --dpi 200 \
    3. --layout hybrid --max-tokens 800 \
    4. --out-format markdown --concurrency 16

    6. Evaluation and Tuning Essentials

    • Metric selection: In addition to character-level accuracy, attention should be paid to table structure restoration, reading order correctness, and formula retention;
    • Compression ratio scanning: With a fixed sample set, gradually increase compression from a low ratio, plot the accuracy curve, and find the acceptable inflection point for the business;
    • Failure sample attribution: Distinguish between “caused by image quality” and “caused by insufficient token budget”; the former is addressed by preprocessing, the latter by increasing the budget;
    • Cost control: Reserve the high budget only for pages containing tables or formulas, and route the rest through the low-budget channel.

    7. Implementation Recommendations and Extended Value

    For cloud implementation, container platforms can host inference services, object storage can save original and result files, message queues can smooth out traffic peaks, and logging, monitoring, and alerting can track throughput and failure rates, forming an elastic document processing platform. In the longer term, this technical route offers new ideas for long-text compression and large model memory mechanisms: compressing “pages that have been read” into a small number of tokens for long-term residency is equivalent to attaching a retrievable visual memory to the model.

    In summary, the key to high compression ratio document recognition lies not in the capability of a single model, but in the coordinated design of “resolution—token budget—layout reordering—structured output.” Mastering this methodology enables explainable and reproducible engineering trade-offs among accuracy, cost, and throughput.