SETUP

Read Any PDF Without Losing the Thread

Most OCR tools split documents into pages and lose context in the middle. This MIT-licensed model from Baidu reads the entire document at once with a 32,768-token context window, keeps tables intact, runs on your own machine, and costs nothing.

Most OCR tools chop documents into pages and lose context somewhere in the middle. This free, locally-running model reads the entire document in one forward pass, keeps tables intact, and processes a 40-page contract in minutes. Your files never leave your machine.


Here is how most document processing stacks fail.

You have a 40-page contract. You run it through an OCR tool. The tool splits it into pages, processes each one in isolation, and returns the text. By page 15, the tool has no memory of the table on page 3. By page 30, cross-references point to sections that exist in the original but got separated in the output. The resulting text is technically correct, page by page. Structurally, it is a mess.

This matters when you are trying to extract structured data, build a search layer over legal documents, or run an AI agent over a financial report. The pre-processing step becomes its own engineering problem.

Baidu (China's equivalent of Google) released a model called Unlimited OCR in June 2026 under an MIT license. It reads the whole document in one pass rather than splitting into pages. Its context window holds 32,768 tokens, which covers most business documents in full. Tables stay where they are. Reading order is preserved across columns and pages. And since it runs entirely on your own machine, your files do not touch any cloud service.

It has 27,800+ GitHub stars since launch.


What Makes This Different from Standard OCR

Standard OCR tools process one page at a time. There is a reason for this: most OCR models were built for page-level text recognition, not document-level comprehension. The tradeoff is that document-level structure, cross-page tables, multi-section clauses, and formulas that span pages gets lost.

Unlimited OCR is a different kind of model. It was built specifically for long-horizon document parsing. "One-shot" in its design means the model sees the full document during a single inference run. The 32K context window is not a parameter you configure; it is the model's working memory during processing.

For a business owner, the practical difference is:

Standard OCRUnlimited OCR
Page-by-page processingWhole document in one pass
Tables often break at page boundariesTables intact across pages
Cross-references may be disconnectedReading order preserved
Typically cloud-hostedRuns locally on your machine
License variesMIT, free for commercial use

The use cases where this matters most: contracts with cross-references, financial reports with multi-page tables, technical specifications, research papers, and any document where the structure across pages carries meaning.


What You Need

If you plan to deploy this at scale rather than use it locally, skip to the vLLM option below.


Setup: 3 Ways to Install

If You're Running It Locally on a Single Machine

Install the Python dependencies:

Copy this.

pip install torch torchvision transformers Pillow einops pymupdf

Load the model in your script:

Copy this.

from transformers import AutoModel, AutoTokenizer
import torch

model = AutoModel.from_pretrained(
    'baidu/Unlimited-OCR',
    trust_remote_code=True,
    use_safetensors=True,
    torch_dtype=torch.bfloat16
)
tokenizer = AutoTokenizer.from_pretrained(
    'baidu/Unlimited-OCR',
    trust_remote_code=True
)

Process a PDF:

Copy this.

# Pass the file path to the model
result = model.process_pdf('/path/to/your/document.pdf')
print(result)

Done. The model returns plain text with the document's structure preserved.

If You're Deploying This in a Container or API Environment

Pull the vLLM Docker image:

Copy this.

docker pull vllm/vllm-openai:unlimited-ocr

This gives you an OpenAI-compatible API endpoint. Drop it behind your existing document processing pipeline and call it the same way you would any other inference endpoint.

For CUDA 12.9 / Hopper GPUs:

Copy this.

docker pull vllm/vllm-openai:unlimited-ocr-cu129

If You're Running Batch Processing at Scale

SGLang supports parallel PDF processing with a --concurrency flag:

Copy this.

uv venv --python 3.12
source .venv/bin/activate
uv pip install pymupdf
python -m sglang.launch_server \
    --model baidu/Unlimited-OCR \
    --context-length 32768 \
    --host 0.0.0.0 --port 10000

Then run batch inference with --concurrency 8 for eight files in parallel.


Where This Fits in Your Document Workflow

Contracts and legal documents. Drop in a vendor agreement, an NDA, or a client contract. The model returns the full text with clause numbering and cross-references in place. From there, run your AI agent over the extracted text to answer specific questions ("What is the termination notice period?" or "Where does the liability cap apply?").

Financial reports. Scanned annual reports, P&L statements, and balance sheets often have tables that span multiple pages or use multi-column layouts. Standard OCR returns a table that is half on one page and half on the next. This model returns the full table.

RAG pipelines. If you are building a document search tool or a retrieval-augmented generation system, the pre-processing step (chunking PDFs, handling tables, managing page boundaries) is usually the messiest part. Replacing that with Unlimited OCR removes the need for custom chunking logic.

Multilingual business documents. The model handles non-Latin scripts, which matters if you are processing supplier contracts in Chinese or Japanese, or financial documents in Arabic.


What the Literal Correction Looks Like

If the model returns text with garbled table data, add this to your processing script:

Copy this.

result = model.process_pdf('/path/to/document.pdf', remove_det=True)

The remove_det() flag strips detection markers that can interfere with table output in some document layouts. If your output looks correct but a table is still wrong, this is the first thing to try.

If the output is still wrong after that, the document likely has an unusual multi-column layout that was not in the model's training data. That is a known limitation, not a bug. Process that section with a standard OCR tool as a fallback.


Honest: What This Does Not Do

You need a GPU. The model does not run quickly on CPU. If your machine does not have a CUDA-capable GPU with at least 8GB VRAM, either use the vLLM Docker container on a cloud GPU instance or rent GPU time from RunPod or Modal at a few cents per hour. This is not optional. CPU inference will work but will take minutes per page rather than seconds per document.

Setup takes time. The model download alone is several gigabytes. Plan 30 to 60 minutes for the initial install, not five minutes.

It is not a cloud service. There is no API you can call without infrastructure. You run the model yourself. For one-off documents, that is overhead. For ongoing volume (more than a few PDFs per week), it pays for itself quickly compared to cloud OCR pricing.

Output is plain text, not a re-rendered PDF. The model returns structured text. It does not reproduce the original visual layout. If you need a pixel-accurate copy of the original document, this is not the right tool.

Very complex layouts may still break. Unusual multi-column layouts with footnotes, sidebars, and nested tables in the same section are difficult for any single-pass model. The model handles standard business documents well. Documents that required a layout designer to build may need post-processing.


What to Do This Week

Pick one document type you process regularly. A contract you review for clients, a supplier invoice format, a financial report you reference monthly. Run it through Unlimited OCR and compare the output to what your current stack produces.

You do not need to commit to replacing your existing process. Run one document, check the output quality, and decide from there.

The GitHub repository with full setup instructions is below.

Come install these with me.
The community is free.

Operations Heroes is the free community where I install these systems live every Thursday, on real businesses. Three quick questions to join, and I call every new member.

Join the free community →
Take this with you Open the repo → Download as PDF ↓

Prefer to browse with company? The free community has the full skill library.

I write one system like this per week. Get the next one by email:

Free. Unsubscribe anytime with one click.