How to Build an End-to-End OCR Pipeline with Baidu’s Unlimited-OCR for High-Resolution Images and Multi-Page PDF Parsing
MarkTechPost Sana Hassan
A new tutorial shows how to run Baidu's Unlimited-OCR model on documents and multi-page PDFs, no separate layout tool needed. It's a single 3B-parameter model reading whole pages in one pass, tables and all.
Based on reporting by MarkTechPost, Sana Hassan — read the original for the full story.
Summary, retelling and take written by AI under human oversight; images are AI-generated illustrations. How we work · Report an error
Most OCR setups still feel like a Rube Goldberg machine: one model finds the layout, another reads the text, a third stitches it back together. Baidu's Unlimited-OCR, paired with a hands-on Colab workflow from MarkTechPost, skips that entirely. The 3B-parameter vision-language model reads an entire page in a single decoding pass, headings, paragraphs and tables included, and it does the same trick across multi-page PDFs.
The setup itself is refreshingly boring, which is a compliment. Install transformers 4.57.1, Pillow, PyMuPDF and a handful of other packages, confirm a CUDA GPU is present, and let the script pick bfloat16 or float16 depending on what the hardware supports. The model downloads at roughly 6GB in BF16, then loads onto the GPU in eval mode. From there the tutorial builds its own test material rather than relying on scanned samples, generating three synthetic report pages with PIL, complete with titles, body text, revenue tables and footnotes, so there's something layout-rich to actually stress-test.
The interesting part is the comparison between Unlimited-OCR's two inference modes. Gundam mode tiles the image into crops on top of a global view, using a 640-pixel tile size, and it's built for dense or small text where detail matters. Base mode processes a single 1024-pixel view with cropping switched off, trading some fidelity for speed on cleaner, well-printed pages. Both runs keep max_length at 32768 tokens and lean on no_repeat_ngram_size and ngram_window settings to stop the model from degenerating into repetitive loops during long generations, a real risk once you're asking a model to transcribe an entire page in one shot.
Multi-page handling is where the pipeline earns its keep. The three sample pages get bundled into a PDF, rasterized back into 300-dpi PNGs via PyMuPDF, and fed into infer_multi() as a sequence rather than processed one at a time. That function widens the repetition window to 1024 to keep decoding stable across pages, and it lets the model carry context forward so cross-page references, like a table continuing onto the next sheet, stay coherent instead of getting treated as isolated images.
What comes out the other end is a set of text, Markdown, MMD and JSON files sitting in output directories, previewed directly in the script. The tutorial closes with a cheat sheet: Gundam for dense or small text, Base for clean printed pages, infer_multi with a 1024 image size for anything spanning multiple pages, and always keep that 32768 context window with repetition controls intact for long documents.
My take — AI-written commentary, not fact-checked reporting
I like that this treats OCR as one continuous reasoning task instead of a bolted-together pipeline of specialist models, because that's the direction most document AI needs to go. What genuinely impresses me is putting a usable, well-documented workflow like this in a Colab notebook rather than behind an API paywall — that's the kind of open tooling that actually moves the field forward, and it's a pattern I wish more labs outside China followed instead of hoarding inference recipes as competitive advantage.
Read more about this at: MarkTechPost
Related stories
Developing an End-to-End Document Intelligence Pipeline with docTR for OCR, Layout Analysis, KIE, Benchmarking, and Searchable PDFs
MarkTechPost · 1 month ago ·
39
Building an End-to-End Document Intelligence Pipeline with deepDoctection
MarkTechPost · 3 weeks ago ·
46
Building a Multimodal RAG Pipeline with NVIDIA NeMo Retriever, Hosted NIMs, LanceDB, Reranking, and Grounded Generation
MarkTechPost · 1 month ago ·
41