How a 0.9B Small Model Solves Irregular Polygon Detection in Document Parsing
This article explains why irregular polygon localization is the first major hurdle in document parsing, and how a 0.9B-parameter vision-language model handles it. It covers unified multi-task modeling, polygon detection instead of axis-aligned boxes, evaluation under real-world distortions, and long-document structuring. It also compares a specialized small model with general-purpose multimodal LLMs across latency, distorted inputs, layout and table structure, and on-premises cost, then outlines .NET integration, production practices, and a model selection and tuning checklist.
1. Why Inaccurate Boxes Are the First Hurdle in Document Parsing
In real business scenarios, document parsing rarely deals with clean, upright, perfectly scanned pages. Much of the input comes from mobile phone photos, faxes, paper archives that have been photocopied many times, screen re-captures, and on-site photos with uneven lighting. In this situation, the traditional pipeline of “detect a rectangle first, then crop, then recognize” produces cascading distortion: page skew causes the rectangle to include content from neighboring columns, paper warping makes text on the same line bend non-linearly, and perspective distortion makes font sizes vary greatly between the top and bottom of the image. In the end, recognition errors are often not caused by insufficient model capability, but by upstream localization that has already cut away the correct pixel region.
For this reason, irregular shape localization has become the key dividing line for measuring document parsing capability. The common approach in the industry is shifting from “axis-aligned bounding box + perspective correction” to “polygon contour regression per character or per line,” so that detection output directly corresponds to the real text orientation after deformation.
2. Breaking Down the Technical Approach: Balancing Accuracy and Efficiency with a Small Parameter Budget
1. Unified Multi-Task Modeling Instead of Serial Pipelines
Consolidating capabilities such as text recognition, table structure reconstruction, formula transcription, chart-to-table conversion, seal recognition, and text line localization into a single vision-language model shares the visual encoder and semantic representations and reduces cascading errors. The downside is task conflict and capacity competition. With a parameter budget at the 0.9B level, engineering practice typically relies on task instruction (distinguishing tasks with a unified prompt), sampling ratio tuning, and staged freezing strategies to mitigate conflicts.
2. Polygon Detection Instead of Bounding Boxes
Polygons, rather than four-point boxes, can represent curved lines, arc-shaped seals, and perspective-distorted table lines. Three points need attention in practice: balancing the number of contour points against post-processing overhead, maintaining stable recall for thin and elongated targets, and handling boundary adhesion between dense small targets. A common practice is to jointly train contour regression with confidence filtering and orientation classification, avoiding cases where “the box is correct but the direction is reversed.”
3. Evaluation with Real Physical Distortion Augmentation
Achieving high accuracy on a single clean benchmark does not reflect field performance. A more reliable approach is to build an evaluation set covering five types of distortion: scanning artifacts, skew, warping, screen capture, and lighting changes, and to report metrics by dimension separately. Only then can you pinpoint whether the model fails because it “cannot see clearly” or because it “boxes inaccurately.”
4. Long-Document Structuring Capability
Cross-page table merging and cross-page continuation of paragraphs and headings address content fragmentation. In engineering, this typically involves introducing an inter-page context window and structural consistency checks to align “an unclosed table on the previous page” with a “continued table on the next page.”
3. Comparison with General-Purpose LLM OCR Solutions
When comparing the OCR capability of a 0.9B specialized document parsing model with that of a general-purpose large-parameter multimodal model, do not look only at single-page printed-text accuracy. It is better to evaluate across four dimensions:
| Dimension | Specialized Small Model | General-Purpose LLM |
|---|---|---|
| Single-page latency and throughput | Better, easy to run on CPU | Usually requires stronger compute |
| Irregular boxes / distorted scenes | Strong structural priors, stable contours | Relies on prompts and post-processing |
| Layout and table structure | Task-specific, well-formed output | Structural stability varies |
| On-premises cost | Low memory and bandwidth pressure | Higher deployment barrier |
The conclusion is not about which one is comprehensively stronger, but rather: scenarios with high concurrency, low latency, on-premises requirements, and strict structural demands are better suited to small-parameter specialized models; scenarios that need cross-modal reasoning and open-ended question answering can be paired with general-purpose LLMs, forming a layered architecture where “the specialized model handles parsing and the general model handles understanding.”
4. Deployment Form and Sample Code
In the .NET ecosystem, integration can be done through a wrapper library using local inference, with model weights and the vision projector file loaded separately for easy on-demand replacement and canary upgrades. Sample code:
using System;using System.IO;var modelDir = Path.Combine(AppContext.BaseDirectory, "models");var engine = new DocParseEngine();engine.Load(weightPath: Path.Combine(modelDir, "doc-vlm.gguf"),projectorPath: Path.Combine(modelDir, "doc-vlm-mmproj.gguf"));var result = engine.Parse("input_page.jpg", tasks: new[] { "text", "table", "formula", "seal" });Console.WriteLine(result.Markdown);
Production recommendations:
- Store the model and projector files in object storage and pull them by version at startup to avoid bloated images;
- Containerize the inference service and use a queue for peak shaving, routing long documents to asynchronous tasks;
- Use logging services and monitoring alerts to track per-dimension accuracy, timeout rate, and memory usage;
- Send low-confidence results to a human review queue, forming a data feedback loop.
5. Selection and Tuning Checklist
- Build a distortion evaluation set first, then discuss model selection, to avoid being misled by a single high score;
- Define the output contract (Markdown, structured JSON, coordinate polygons) clearly so downstream consumers can rely on it;
- Fine-tune specifically for rare characters, ancient texts, and multilingual tables, expanding language coverage as needed;
- Keep original region coordinates for tables and formulas to enable traceability and verification;
- Set separate thresholds for weakly semantic targets such as seals, checkboxes, and underlines.
Overall, the breakthrough in irregular box localization shows that document parsing is moving from “recognizing text” to “reconstructing structure.” The value of a 0.9B-level model lies in holding both high accuracy and low-cost on-premises deployment at the same time.
