DeepSeek OCR Online: Introduction and Usage Guide
DeepSeek OCR represents a significant leap forward in Optical Character Recognition (OCR) and document understanding. Developed as a cutting-edge, open vision-language model, it is specifically optimized to work in conjunction with Large Language Models (LLMs). Its core innovation lies in “optical context compression,” a powerful technique that efficiently converts extensive 2D visual contexts (like entire document pages) into compressed vision tokens, enabling LLMs to process and comprehend vast amounts of visual information with unprecedented efficiency.
Key Features and Capabilities
DeepSeek OCR stands out with a robust set of features designed to tackle a wide range of document processing challenges:
- Efficient Document Processing: It excels at reading and processing large scanned documents, such as receipts, invoices, research papers, and books. By compressing visual information, it dramatically reduces the token count (achieving up to a 10x compression ratio with 97% accuracy), making the processing of extensive documents far more efficient for LLMs.
- Structured Data Extraction: Beyond simple text extraction, DeepSeek OCR can accurately parse and understand structured elements within documents. This includes tables, charts, and geometric figures, which it can convert into structured formats like HTML tables or Markdown, facilitating easier data analysis and integration.
- Multilingual and Handwritten Text Support: The model is not limited to printed English text; it supports the extraction of text from diverse multilingual documents and even handwritten notes, broadening its applicability across various global contexts.
- Complex Content Understanding: DeepSeek OCR demonstrates impressive capabilities in understanding complex content, including chemistry formulas, mathematical equations, and even the nuances of visual memes, showcasing its advanced multimodal comprehension.
- Flexible Output: Users can choose to receive extracted content in either plain text or a structured Markdown format, providing versatility for different downstream applications.
How DeepSeek OCR Works (High-Level Overview)
DeepSeek OCR operates as a sophisticated two-stage system:
- DeepEncoder: This visual encoder is responsible for processing the input image, such as a scanned document page. It transforms the image into a compact sequence of “vision tokens.” This stage leverages components like SAM-base for local perception and CLIP-large for a broader global understanding of the image content.
- DeepSeek-3B-MoE Decoder: Following the encoding stage, a specialized language model decoder takes these compressed vision tokens. It then reconstructs the text and structural information, effectively performing OCR tasks and allowing the system to answer complex questions about the document’s content.
Usage Guide: Accessing DeepSeek OCR Online
DeepSeek OCR can be deployed for various use cases, from offline batch processing to real-time online serving. Here are common methods for accessing and utilizing its capabilities:
1. Online Serving with vLLM
For deploying DeepSeek OCR as an online service with an OpenAI-compatible API, vLLM is a recommended choice.
- Installation:
bash
uv venv
source .venv/bin/activate
uv pip install -U vllm --torch-backend auto - Running the Server: Start the
vLLMserver, ensuring to use the custom logits processor and disabling prefix caching for optimal OCR performance.
bash
vllm serve deepseek-ai/DeepSeek-OCR --logits_processors vllm.model_executor.models.deepseek_ocr:NGramPerReqLogitsProcessor --no-enable-prefix-caching --mm-processor-cache-gb 0 - API Interaction: Once the server is live, you can interact with it using any OpenAI-compatible client library.
python
from openai import OpenAI
client = OpenAI(api_key="EMPTY", base_url="http://localhost:8000/v1", timeout=3600)
messages = [{"role": "user", "content": "<image>\nFree OCR."}]
# ... (code to send image and receive response)
2. Local Usage with Ollama
For local execution and experimentation, DeepSeek OCR is supported by Ollama (ensure you have version v0.13.0 or later).
- Example Commands:
bash
ollama run deepseek-ocr "/path/to/image\nFree OCR."
ollama run deepseek-ocr "/path/to/image\n<|grounding|>Convert the document to markdown."
ollama run deepseek-ocr "/path/to/image\nParse the figure."
Note that the model can be sensitive to prompting; specific prompt formats are often recommended for achieving the best results.
3. API Access via Third-Party Platforms
Several platforms, such as Clarifai, offer OpenAI-compatible endpoints to access DeepSeek OCR. This allows developers to integrate DeepSeek OCR into their applications using standard client libraries, sending images from local files (often base64 encoded) or directly via image URLs.
4. Gradio Web Application
A Gradio-based web application provides a user-friendly graphical interface for DeepSeek OCR. This allows users to upload images directly through a browser or within environments like Google Colab and receive structured output without needing to write code.
Configuration Tips for Optimal Performance
To maximize the accuracy and efficiency of DeepSeek OCR, consider the following configuration guidelines:
- Custom Logits Processor: Always utilize the custom logits processor with the model, especially when generating Markdown output, as it significantly enhances OCR quality.
- Disable Caching: For typical OCR tasks, disable prefix caching and image reuse. These features are generally not beneficial for OCR and can introduce unnecessary overhead.
- Plain Prompts: DeepSeek OCR often performs better with plain, direct prompts rather than overly complex or highly structured instruction formats.
- Adjust
max_num_batched_tokens: Depending on your hardware resources, adjusting themax_num_batched_tokensparameter can help optimize throughput.
Conclusion
DeepSeek OCR Online represents a powerful and versatile solution for advanced OCR and document understanding. Its innovative approach to optical context compression, coupled with its comprehensive feature set, makes it an invaluable tool for efficiently extracting and comprehending information from diverse visual documents, paving the way for more intelligent and automated document processing workflows.