How a 4B Small Model Solves Cross-Page OCR Recognition

    This article explains why conventional OCR pipelines lose context at page boundaries and how a small, billions-scale parameter model can handle cross-page understanding as a lightweight sequence task. It covers the three capabilities such a model needs, sliding-window context strategies, evaluation metrics, deployment and cost considerations, and common pitfalls to avoid. Readers will learn how to combine mature detection and recognition modules with a compact cross-page model and rule-based validation in a staged pipeline.

    1. Background: Why Multi-Page Document Recognition Suffers from “Cross-Page Amnesia”

    In enterprise document digitization, scanned files, faxes, contract attachments, and financial reports rarely appear as single pages. They often run to dozens or even hundreds of consecutive pages. Most general-purpose optical character recognition (OCR) solutions assume that each page is independent: every page is sent through the recognition pipeline separately, producing text blocks and coordinates for that page, and an upper layer stitches the pages together. This assumption works well enough for single-page receipts, but with multi-page documents it exposes a typical problem known as cross-page amnesia.

    Cross-page amnesia means that recognition results lose contextual consistency at page boundaries. It shows up in four ways:

    • Broken tables: a table spanning two pages is split into two unrelated headers, the second page has no column names, and the key-value pairs parsed afterward cannot be aligned.
    • Paragraph drift: the sentence at the end of one page and the sentence at the start of the next are treated as two separate paragraphs, semantics are cut, and summary and retrieval quality drop.
    • Numbering errors: multi-level lists and clause numbers restart or lose their hierarchy after a page break, breaking cross-references in contract clauses.
    • Reading order errors: with two-column layouts, headers and footers, and watermarks mixed with body text, block order after a page break no longer matches how a human would read.

    From an engineering perspective, the root cause is not insufficient single-page accuracy. It is the absence of a global state that spans the whole document. If the model does not remember the previous page’s table header, the previous paragraph’s meaning, or the previous numbering level, it cannot make the right decision on the next page.

    2. A Shift in Approach: Modeling Cross-Page Understanding as a Lightweight Sequence Task

    There are two common routes to solving cross-page amnesia. The first is post-processing repair: a rule engine inherits table headers and backfills numbering at the stitching stage. The rules keep multiplying and fail quickly when layouts change. The second is scaling up the model: a larger multimodal model ingests the entire document at once. The results are good, but inference cost is high and throughput is low, which makes it hard to deploy in batch archiving scenarios.

    The technical trend of the past two years points to a third route: use a model with a few billion parameters, or even fewer, dedicated to cross-page context modeling, and leave character-level recognition to mature detection and recognition modules. The key to this division of labor is task abstraction. Cross-page understanding is essentially a sequence-to-sequence modeling problem: the input is a sequence of blocks from several adjacent pages together with their relative positions, and the output is a structured result carrying global numbering, hierarchy, and ownership relations.

    Once the problem is abstracted clearly, the advantages of a small model become apparent. Its input is not high-resolution images but already structured block descriptions. Its output space is constrained to a limited set of labels. Its context window only needs to cover a few pages rather than the whole document. With the task narrowed this way, the model does not need to be large.

    3. Core Breakdown: Three Capabilities That Let a Small Model Handle Cross-Page Understanding

    3.1 Cross-Page State Memory

    The model must maintain an implicit document state within a sliding window: what the current table header is, what the current paragraph’s semantic topic is, and which level the current list is at. In practice, each page’s block sequence is augmented with relative position encodings for page order and block order, so the model can distinguish “adjacent on the same page” from “adjacent across pages.” During training, cross-page samples are deliberately constructed, for example by randomly splitting a complete table across two pages, so the model learns to complete the severed header and ownership relations.

    3.2 Joint Layout and Semantic Judgment

    Cross-page decisions cannot rely on text alone; they also need geometric and style cues. Column width ratios, border continuity, font size hierarchy, and indentation are all evidence for deciding whether something is a continuation of the same table or a new table. Lightweight models generally take structured layout descriptions rather than raw pixels, fusing text semantics with geometric features at a lower computational cost and outputting association probabilities between blocks.

    3.3 Constrained Structured Output

    So that results can be consumed directly by business systems, model output must be constrained to a predefined schema, such as a chapter–clause–table–cell hierarchy. A common approach is to add constrained decoding or post-validation at the decoding stage: if the output violates hierarchy rules, it falls back and retries. This significantly improves structural validity without enlarging the model.

    4. Engineering Practice: Chunking, Context, and Evaluation

    4.1 Context Window and Chunking Strategy

    Cross-page modeling has to balance seeing enough against computing fast enough. In practice, an overlapping sliding window is common: the window covers three to five pages, and adjacent windows overlap by one page to avoid losing boundary information. Illustrative pseudocode:

    1. def build_windows(pages, window=4, overlap=1):
    2. step = window - overlap
    3. for start in range(0, len(pages), step):
    4. yield pages[start:start + window]

    For each window, the model outputs the structural relations inside it, and an upper layer deduplicates and merges them into a consistent structure for the whole document.

    4.2 Key Evaluation Metrics

    Evaluating cross-page capability cannot rely on single-page character accuracy alone. At least three kinds of metrics are recommended: table header inheritance accuracy for cross-page tables, merge correctness for cross-page paragraphs, and the Kendall correlation coefficient for whole-document reading order. The “boundary page” subset should also be measured separately, because overall averages tend to hide degradation at boundaries.

    4.3 Deployment and Cost

    The most direct value of a small model is on the deployment side: it supports on-premises deployment, uses few resources per inference, and scales horizontally for batch archiving tasks. In engineering terms, detection and recognition, cross-page modeling, and structure validation are usually split into three pipeline stages, decoupled through a message queue, and scaled independently. Original files sit in object storage, intermediate results go to a cache, and logs plus monitoring and alerting track failure rates and latency distribution throughout.

    If an enterprise wants to build similar capabilities on Baidu AI Cloud, it can reuse the container platform to host inference services, object storage to hold original and result files, and a message queue to decouple the pipeline, with monitoring and alerting closing the loop. This combination is not tied to any specific vendor and is a general cloud-native practice.

    5. Common Pitfalls and Practical Recommendations

    • Pitfall 1: assuming that higher single-page recognition accuracy will solve cross-page problems. In reality, errors at boundaries mainly come from missing context and require a dedicated cross-page modeling stage.
    • Pitfall 2: blindly scaling up the model. Once the task is narrowed, a small model often already meets structural validity requirements, and the returns from a larger model diminish.
    • Pitfall 3: neglecting evaluation set construction. Without real cross-page samples, a model looks good on lab metrics but still fails at boundaries after launch.

    The practical recommendation is to first map the layout distribution of the business documents and build an evaluation set covering typical cross-page forms; then define the structural schema and validation rules; and finally adopt a combination of a mature recognition module, a lightweight cross-page model, and rule-based validation, rolled out gradually as a pipeline with boundary-page metrics as the gate for wider release.