News Froggy
newsfroggy
HomeTechReviewProgrammingGamesHow ToAboutContacts
newsfroggy

Your daily source for the latest technology news, startup insights, and innovation trends.

More

  • About Us
  • Contact
  • Privacy Policy
  • Terms of Service

Categories

  • Tech
  • Review
  • Programming
  • Games
  • How To

© 2026 News Froggy. All rights reserved.

TwitterFacebook
Programming

Unlimited OCR: One-Shot Long-Horizon Parsing for Modern Docs — Key

The world of Optical Character Recognition (OCR) has seen significant advancements, but challenges persist when dealing with complex, multi-page, or lengthy documents. Traditional OCR often struggles with maintaining

PublishedJune 23, 2026
Reading Time9 min
Unlimited OCR: One-Shot Long-Horizon Parsing for Modern Docs — Key

The world of Optical Character Recognition (OCR) has seen significant advancements, but challenges persist when dealing with complex, multi-page, or lengthy documents. Traditional OCR often struggles with maintaining contextual coherence across pages or handling extremely long text outputs without fragmentation.

Welcome to the era of Unlimited OCR, a powerful evolution building upon the Deepseek-OCR foundation. This new system introduces a groundbreaking approach: One-shot Long-horizon Parsing. In essence, it aims to process entire documents, potentially spanning many pages and thousands of words, in a single, coherent operation. This 'one-shot' capability promises to unlock richer contextual understanding and more consistent extraction of information, sidestepping the limitations of page-by-page processing.

Released recently (as of June 2026), Unlimited OCR is making waves in the research community, with its paper available on arXiv and a ready-to-use model integrated into ModelScope. For developers, it offers two primary avenues for integration: the familiar Hugging Face Transformers library for direct application and SGLang for high-throughput, scalable inference serving.

Getting Started with Hugging Face Transformers

For developers looking to quickly integrate Unlimited OCR into their Python applications, the Hugging Face Transformers library provides a straightforward interface. You'll need a Python 3.12.3 environment with CUDA 12.9 and the specified dependencies to ensure compatibility.

python import os import torch from transformers import AutoModel, AutoTokenizer

Required dependencies:

torch==2.10.0

torchvision==0.25.0

transformers==4.57.1

Pillow==12.1.1

matplotlib==3.10.8

einops==0.8.2

addict==2.4.0

easydict==1.13

pymupdf==1.27.2.2

psutil==7.2.2

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

The model supports two main inference functions: infer for single images and infer_multi for multi-page documents or PDFs.

Single Image Parsing:

For individual images, you can choose between two configurations: gundam or base. The gundam mode, typically used with crop_mode=True and a smaller image_size (e.g., 640), is optimized for specific image crops, potentially for higher detail on focused regions. The base mode uses a larger image_size (e.g., 1024) and crop_mode=False, suitable for full-page processing.

python model.infer( tokenizer, prompt='<image>document parsing.', image_file='your_image.jpg', output_path='your/output/dir', base_size=1024, image_size=640, crop_mode=True, # Example using 'gundam' config max_length=32768, # Max output length no_repeat_ngram_size=35, ngram_window=128, # Generation parameters save_results=True, )

Multi-page and PDF Parsing:

For documents with multiple pages or PDFs, infer_multi is your go-to, exclusively using the base image configuration (image_size=1024). The system includes a convenient utility, pdf_to_images, leveraging PyMuPDF to convert PDF pages into image files, which can then be fed into infer_multi.

python import tempfile, fitz # PyMuPDF

def pdf_to_images(pdf_path, dpi=300): doc = fitz.open(pdf_path) tmp_dir = tempfile.mkdtemp(prefix='pdf_ocr_') mat = fitz.Matrix(dpi / 72, dpi / 72) paths = [] for i, page in enumerate(doc): out = os.path.join(tmp_dir, f'page_{i+1:04d}.png') page.get_pixmap(matrix=mat).save(out) paths.append(out) doc.close() return paths

model.infer_multi( tokenizer, prompt='<image>Multi page parsing.', image_files=pdf_to_images('your_doc.pdf', dpi=300), output_path='your/output/dir', image_size=1024, max_length=32768, no_repeat_ngram_size=35, ngram_window=1024, save_results=True, )

Notice the max_length parameter, set to a substantial 32768. This highlights the 'long-horizon' capability, allowing the model to generate very extensive text outputs, crucial for comprehensive document parsing.

SGLang for Scalable Inference Serving

For production environments requiring high concurrency and optimized performance, Unlimited OCR integrates seamlessly with SGLang. This provides a robust server-client architecture, allowing you to deploy the model as an OpenAI-compatible API endpoint.

First, set up your SGLang environment, installing the necessary packages, including pymupdf for PDF processing:

bash uv venv --python 3.12 source .venv/bin/activate uv pip install wheel/sglang-0.0.0.dev11416+g92e8bb79e-py3-none-any.whl uv pip install kernels==0.11.7 uv pip install pymupdf==1.27.2.2

Then, launch the SGLang server. Key parameters like --attention-backend fa3, --context-length 32768, and --enable-custom-logit-processor are configured for optimal performance and long context handling:

bash python -m sglang.launch_server
--model baidu/Unlimited-OCR
--served-model-name Unlimited-OCR
--attention-backend fa3
--page-size 1
--mem-fraction-static 0.8
--context-length 32768
--enable-custom-logit-processor
--disable-overlap-schedule
--skip-server-warmup
--host 0.0.0.0
--port 10000

With the server running, you can send streaming requests via Python, utilizing helper functions to encode images and construct the API payload. The custom_logit_processor and custom_params (like ngram_size and window_size) are crucial for managing output quality and preventing repetition, especially over long parsing tasks.

python import base64 import json import os import tempfile import fitz import requests from sglang.srt.sampling.custom_logit_processor import DeepseekOCRNoRepeatNGramLogitProcessor

server_url = "http://127.0.0.1:10000" session = requests.Session() session.trust_env = False

def pdf_to_images(pdf_path, dpi=300): # ... (same as in Huggingface example) ... doc = fitz.open(pdf_path) tmp_dir = tempfile.mkdtemp(prefix="pdf_ocr_") mat = fitz.Matrix(dpi / 72, dpi / 72) image_paths = [] for i, page in enumerate(doc): image_path = os.path.join(tmp_dir, f"page_{i + 1:04d}.png") page.get_pixmap(matrix=mat).save(image_path) image_paths.append(image_path) doc.close() return image_paths

def encode_image(image_path): ext = os.path.splitext(image_path)[1].lower() mime = "image/jpeg" if ext in (".jpg", ".jpeg") else f"image/{ext.lstrip('.')}" with open(image_path, "rb") as f: data = base64.b64encode(f.read()).decode("utf-8") return {"type": "image_url", "image_url": {"url": f"data:{mime};base64,{data}"}}

def build_content(prompt, image_paths): return [{"type": "text", "text": prompt}] + [encode_image(path) for path in image_paths]

def generate(prompt, image_paths, image_mode, ngram_window): payload = { "model": "Unlimited-OCR", "messages": [{"role": "user", "content": build_content(prompt, image_paths)}], "temperature": 0, "skip_special_tokens": False, "images_config": {"image_mode": image_mode}, "custom_logit_processor": DeepseekOCRNoRepeatNGramLogitProcessor.to_str(), "custom_params": { "ngram_size": 35, "window_size": ngram_window, }, "stream": True, } response = session.post( f"{server_url}/v1/chat/completions", headers={"Content-Type": "application/json"}, data=json.dumps(payload), timeout=1200, stream=True, ) response.raise_for_status() chunks = [] for line in response.iter_lines(chunk_size=1, decode_unicode=True): if not line or not line.startswith("data: "): continue data = line[len("data: "):] if data == "[DONE]": break event = json.loads(data) delta = event["choices"][0].get("delta", {}).get("content", "") if delta: print(delta, end="", flush=True) chunks.append(delta) print() return "".join(chunks)

Example for PDF parsing using SGLang server

generate("Multi page parsing.", pdf_to_images("your_doc.pdf", dpi=300), image_mode="base", ngram_window=1024)

For batch inference, infer.py is provided as a command-line tool that can automatically manage the SGLang server and send concurrent requests, making it ideal for processing directories of images or large PDFs efficiently.

bash python infer.py
--pdf ./examples/document.pdf
--output_dir ./outputs
--concurrency 8
--image_mode gundam

Practical Takeaways for Developers

  • Choose your integration: For quick prototyping or smaller-scale tasks, the Hugging Face Transformers library offers a direct, code-centric approach. For high-performance, scalable inference serving, SGLang is the recommended path, providing an OpenAI-compatible API.
  • Handle PDFs seamlessly: Both integration methods provide utilities to convert PDFs into image sequences, abstracting away the multi-page complexity.
  • Understand image modes: Leverage gundam for focused, cropped single-image analysis where fine detail might be critical, and base for full-page or multi-page documents to ensure comprehensive coverage.
  • Long-horizon capabilities: The max_length=32768 parameter is a key enabler for the 'one-shot long-horizon parsing'. Ensure your infrastructure can support the memory and compute required for such extensive outputs, especially on GPUs.
  • Refine output quality: Parameters like no_repeat_ngram_size and ngram_window are vital for controlling the quality and preventing repetitive text in the long generated outputs. Experiment with these values to fine-tune results for your specific document types.

Unlimited OCR represents a significant step forward in document understanding, offering robust tools for handling the most demanding parsing tasks with unprecedented contextual awareness.

FAQ

Q: What does "one-shot long-horizon parsing" mean in the context of Unlimited OCR?

A: It refers to the model's ability to process entire documents, potentially spanning multiple pages and containing extensive text, in a single pass. Unlike traditional OCR that might process each page independently, Unlimited OCR aims to understand and parse the document as a whole, maintaining context and consistency across very long textual outputs. This is facilitated by its ability to handle extremely long output lengths, up to 32768 tokens.

Q: When should I use the Hugging Face Transformers approach versus SGLang for Unlimited OCR?

A: The Hugging Face Transformers approach is ideal for direct, programmatic integration within Python applications, prototyping, or scenarios with lower inference volume. It's straightforward to set up and use. SGLang, on the other hand, is designed for high-performance, scalable inference serving. If you need to handle concurrent requests, achieve higher throughput, or deploy the model as a robust, easily consumable API (e.g., in a microservices architecture), SGLang with its dedicated server is the better choice.

Q: What's the difference between the gundam and base image modes for parsing?

A: The gundam mode is typically configured with crop_mode=True and a smaller image_size (e.g., 640), suggesting it's optimized for processing specific, possibly cropped, regions of an image where fine detail is paramount. The base mode uses a larger image_size (e.g., 1024) and crop_mode=False, designed for processing full pages or entire multi-page documents where comprehensive coverage is more important than extreme localized detail. For multi-page and PDF parsing, only the base mode is supported.

#programming#Hacker News#unlimited#one-shot#long-horizon#parsingMore

Related articles

AI's Confidence vs. Formal Methods' Rigor: Design Flaws & Verification
Programming
Stack Overflow BlogOct 16

AI's Confidence vs. Formal Methods' Rigor: Design Flaws & Verification

While AI accelerates code generation, formal methods remain critical for ensuring system correctness. Languages like TLA+ and tools like Quint enable developers to model and verify system designs before coding, catching subtle flaws. Quint makes formal methods more accessible with developer-friendly syntax and executability. This approach is vital for verifying AI-generated code through trace validation and model-based testing, ensuring reliability against real-world data.

Ephemeral PR Preview Environments on GKE: A Deep Dive
Programming
freeCodeCampOct 16

Ephemeral PR Preview Environments on GKE: A Deep Dive

Every development team eventually grapples with the limitations of shared staging environments. The familiar scenario: multiple features deployed simultaneously, database migrations clashing, and the phrase "it works on

Secure Internal API Access for AI Agents with MCP
Programming
freeCodeCampOct 16

Secure Internal API Access for AI Agents with MCP

AI agents accessing internal APIs directly pose significant risks, including identity loss, unrestricted queries, and security bypasses. The Model Context Protocol (MCP) offers a solution by defining explicit tools. A secure architecture involves an MCP server wrapping the API with strict input validation, coupled with a gateway that handles authentication, rate limiting, and audit logging, ensuring safe and accountable access.

Review
Android AuthorityOct 13

Googlebook: App Strategy Falters on Android's Promise

Googlebook's app strategy prioritizes web apps over native Android apps for key services like Gmail and Docs, despite its Android-based foundation. This creates a restrictive user experience, especially on touchscreens, undermining a core selling point.

Beyond the Resume Noise: Developer Story Rethinks Tech Hiring
Programming
Stack Overflow BlogOct 12

Beyond the Resume Noise: Developer Story Rethinks Tech Hiring

Stack Overflow is addressing the growing challenges in tech hiring, exacerbated by AI's influence leading to untrustworthy and generic resumes. Their solution, the re-introduced Developer Story, offers a platform for developers to authentically showcase their work, expertise, and impact through verifiable contributions and personal projects. This aims to provide hiring teams with more objective insights and help genuine talent stand out in a crowded market.

Adding & Validating JSON-LD Structured Data in Next.js
Programming
freeCodeCampOct 11

Adding & Validating JSON-LD Structured Data in Next.js

When we build websites, we want them to be discoverable and accurately understood by search engines. This isn't just about keywords and meta descriptions anymore; it's about providing explicit, machine-readable context.

Back to Newsroom

Stay ahead of the curve

Get the latest technology insights delivered to your inbox every morning.