Instructions to use Mungert/Nanonets-OCR2-3B-GGUF with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Mungert/Nanonets-OCR2-3B-GGUF with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="Mungert/Nanonets-OCR2-3B-GGUF") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("Mungert/Nanonets-OCR2-3B-GGUF", dtype="auto") - llama-cpp-python
How to use Mungert/Nanonets-OCR2-3B-GGUF with llama-cpp-python:
# !pip install llama-cpp-python from llama_cpp import Llama llm = Llama.from_pretrained( repo_id="Mungert/Nanonets-OCR2-3B-GGUF", filename="Nanonets-OCR2-3B-bf16.gguf", )
llm.create_chat_completion( messages = [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] ) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use Mungert/Nanonets-OCR2-3B-GGUF with llama.cpp:
Install from brew
brew install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf Mungert/Nanonets-OCR2-3B-GGUF:Q4_K_M # Run inference directly in the terminal: llama-cli -hf Mungert/Nanonets-OCR2-3B-GGUF:Q4_K_M
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf Mungert/Nanonets-OCR2-3B-GGUF:Q4_K_M # Run inference directly in the terminal: llama-cli -hf Mungert/Nanonets-OCR2-3B-GGUF:Q4_K_M
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf Mungert/Nanonets-OCR2-3B-GGUF:Q4_K_M # Run inference directly in the terminal: ./llama-cli -hf Mungert/Nanonets-OCR2-3B-GGUF:Q4_K_M
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf Mungert/Nanonets-OCR2-3B-GGUF:Q4_K_M # Run inference directly in the terminal: ./build/bin/llama-cli -hf Mungert/Nanonets-OCR2-3B-GGUF:Q4_K_M
Use Docker
docker model run hf.co/Mungert/Nanonets-OCR2-3B-GGUF:Q4_K_M
- LM Studio
- Jan
- vLLM
How to use Mungert/Nanonets-OCR2-3B-GGUF with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Mungert/Nanonets-OCR2-3B-GGUF" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Mungert/Nanonets-OCR2-3B-GGUF", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/Mungert/Nanonets-OCR2-3B-GGUF:Q4_K_M
- SGLang
How to use Mungert/Nanonets-OCR2-3B-GGUF with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "Mungert/Nanonets-OCR2-3B-GGUF" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Mungert/Nanonets-OCR2-3B-GGUF", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "Mungert/Nanonets-OCR2-3B-GGUF" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Mungert/Nanonets-OCR2-3B-GGUF", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Ollama
How to use Mungert/Nanonets-OCR2-3B-GGUF with Ollama:
ollama run hf.co/Mungert/Nanonets-OCR2-3B-GGUF:Q4_K_M
- Unsloth Studio
How to use Mungert/Nanonets-OCR2-3B-GGUF with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for Mungert/Nanonets-OCR2-3B-GGUF to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for Mungert/Nanonets-OCR2-3B-GGUF to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for Mungert/Nanonets-OCR2-3B-GGUF to start chatting
- Docker Model Runner
How to use Mungert/Nanonets-OCR2-3B-GGUF with Docker Model Runner:
docker model run hf.co/Mungert/Nanonets-OCR2-3B-GGUF:Q4_K_M
- Lemonade
How to use Mungert/Nanonets-OCR2-3B-GGUF with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull Mungert/Nanonets-OCR2-3B-GGUF:Q4_K_M
Run and chat with the model
lemonade run user.Nanonets-OCR2-3B-GGUF-Q4_K_M
List all available models
lemonade list
Nanonets-OCR2-3B GGUF Models
Model Generation Details
This model was generated using llama.cpp at commit 3cfa9c3f1.
Quantization Beyond the IMatrix
I've been experimenting with a new quantization approach that selectively elevates the precision of key layers beyond what the default IMatrix configuration provides.
In my testing, standard IMatrix quantization underperforms at lower bit depths, especially with Mixture of Experts (MoE) models. To address this, I'm using the --tensor-type option in llama.cpp to manually "bump" important layers to higher precision. You can see the implementation here:
๐ Layer bumping with llama.cpp
While this does increase model file size, it significantly improves precision for a given quantization level.
I'd love your feedbackโhave you tried this? How does it perform for you?
Click here to get info on choosing the right GGUF model format
Nanonets-OCR2: A model for transforming documents into structured markdown with intelligent content recognition and semantic tagging
Nanonets-OCR2 by Nanonets is a family of powerful, state-of-the-art image-to-markdown OCR models that go far beyond traditional text extraction. It transforms documents into structured markdown with intelligent content recognition and semantic tagging, making it ideal for downstream processing by Large Language Models (LLMs).
Nanonets-OCR2 is packed with features designed to handle complex documents with ease:
- LaTeX Equation Recognition: Automatically converts mathematical equations and formulas into properly formatted LaTeX syntax. It distinguishes between inline (
$...$) and display ($$...$$) equations. - Intelligent Image Description: Describes images within documents using structured
<img>tags, making them digestible for LLM processing. It can describe various image types, including logos, charts, graphs and so on, detailing their content, style, and context. - Signature Detection & Isolation: Identifies and isolates signatures from other text, outputting them within a
<signature>tag. This is crucial for processing legal and business documents. - Watermark Extraction: Detects and extracts watermark text from documents, placing it within a
<watermark>tag. - Smart Checkbox Handling: Converts form checkboxes and radio buttons into standardized Unicode symbols (
โ,โ,โ) for consistent and reliable processing. - Complex Table Extraction: Accurately extracts complex tables from documents and converts them into both markdown and HTML table formats.
- Flow charts & Organisational charts: Extracts flow charts and organisational as mermaid code.
- Handwritten Documents: The model is trained on handwritten documents across multiple languages.
- Multilingual: Model is trained on documents of multiple languages, including English, Chinese, French, Spanish, Portuguese, German, Italian, Russian, Japanese, Korean, Arabic, and many more.
- Visual Question Answering (VQA): The model is designed to provide the answer directly if it is present in the document; otherwise, it responds with "Not mentioned."
Nanonets-OCR2 Family
| Model | Access Link |
|---|---|
| Nanonets-OCR2-Plus | Docstrange link |
| Nanonets-OCR2-3B | ๐ค link |
| Nanonets-OCR2-1.5B-exp | ๐ค link |
Usage
Using transformers
from PIL import Image
from transformers import AutoTokenizer, AutoProcessor, AutoModelForImageTextToText
model_path = "nanonets/Nanonets-OCR2-3B"
model = AutoModelForImageTextToText.from_pretrained(
model_path,
torch_dtype="auto",
device_map="auto",
attn_implementation="flash_attention_2"
)
model.eval()
tokenizer = AutoTokenizer.from_pretrained(model_path)
processor = AutoProcessor.from_pretrained(model_path)
def ocr_page_with_nanonets_s(image_path, model, processor, max_new_tokens=4096):
prompt = """Extract the text from the above document as if you were reading it naturally. Return the tables in html format. Return the equations in LaTeX representation. If there is an image in the document and image caption is not present, add a small description of the image inside the <img></img> tag; otherwise, add the image caption inside <img></img>. Watermarks should be wrapped in brackets. Ex: <watermark>OFFICIAL COPY</watermark>. Page numbers should be wrapped in brackets. Ex: <page_number>14</page_number> or <page_number>9/22</page_number>. Prefer using โ and โ for check boxes."""
image = Image.open(image_path)
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": [
{"type": "image", "image": f"file://{image_path}"},
{"type": "text", "text": prompt},
]},
]
text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = processor(text=[text], images=[image], padding=True, return_tensors="pt")
inputs = inputs.to(model.device)
output_ids = model.generate(**inputs, max_new_tokens=max_new_tokens, do_sample=False)
generated_ids = [output_ids[len(input_ids):] for input_ids, output_ids in zip(inputs.input_ids, output_ids)]
output_text = processor.batch_decode(generated_ids, skip_special_tokens=True, clean_up_tokenization_spaces=True)
return output_text[0]
image_path = "/path/to/your/document.jpg"
result = ocr_page_with_nanonets_s(image_path, model, processor, max_new_tokens=15000)
print(result)
Using vLLM
- Start the vLLM server.
vllm serve nanonets/Nanonets-OCR2-3B
- Predict with the model
from openai import OpenAI
import base64
client = OpenAI(api_key="123", base_url="http://localhost:8000/v1")
model = "nanonets/Nanonets-OCR2-3B"
def encode_image(image_path):
with open(image_path, "rb") as image_file:
return base64.b64encode(image_file.read()).decode("utf-8")
def ocr_page_with_nanonets_s(img_base64):
response = client.chat.completions.create(
model=model,
messages=[
{
"role": "user",
"content": [
{
"type": "image_url",
"image_url": {"url": f"data:image/png;base64,{img_base64}"},
},
{
"type": "text",
"text": "Extract the text from the above document as if you were reading it naturally. Return the tables in html format. Return the equations in LaTeX representation. If there is an image in the document and image caption is not present, add a small description of the image inside the <img></img> tag; otherwise, add the image caption inside <img></img>. Watermarks should be wrapped in brackets. Ex: <watermark>OFFICIAL COPY</watermark>. Page numbers should be wrapped in brackets. Ex: <page_number>14</page_number> or <page_number>9/22</page_number>. Prefer using โ and โ for check boxes.",
},
],
}
],
temperature=0.0,
max_tokens=15000
)
return response.choices[0].message.content
test_img_path = "/path/to/your/document.jpg"
img_base64 = encode_image(test_img_path)
print(ocr_page_with_nanonets_s(img_base64))
Using Docstrange
import requests
url = "https://extraction-api.nanonets.com/extract"
headers = {"Authorization": <API KEY>}
files = {"file": open("/path/to/your/file", "rb")}
data = {"output_type": "markdown"}
data["model"] = "nanonets"
response = requests.post(url, headers=headers, files=files, data=data)
print(response.json())
Check out Docstrange for more details.
Evaluation
Markdown Evaluations
Nanonets OCR2 Plus
| Model | Win Rate vs Nanonets OCR2 Plus (%) | Lose Rate vs Nanonets OCR2 Plus (%) | Both Correct (%) |
|---|---|---|---|
| Gemini 2.5 flash (No Thinking) | 34.35 | 57.60 | 8.06 |
| Nanonets OCR2 3B | 29.37 | 54.58 | 16.04 |
| Nanonets-OCR-s | 24.86 | 66.12 | 9.02 |
| Nanonets OCR2 1.5B exp | 13.00 | 81.20 | 5.79 |
| GPT-5 (Thinking: low) | 23.53 | 74.86 | 1.60 |
Nanonets OCR2 3B
| Model | Win Rate vs Nanonets OCR2 3B (%) | Lose Rate vs Nanonets OCR2 3B (%) | Both Correct (%) |
|---|---|---|---|
| Gemini 2.5 flash (No Thinking) | 39.98 | 52.43 | 7.58 |
| Nanonets-OCR-s | 30.61 | 58.28 | 11.12 |
| Nanonets OCR2 1.5B exp | 14.78 | 79.18 | 6.04 |
| GPT-5 | 25.00 | 72.87 | 2.13 |
Visual Question Answering (VQA) Evaluations
| Dataset | Nanonets OCR2 Plus | Nanonets OCR2 3B | Qwen2.5-VL-72B-Instruct | Gemini 2.5 Flash |
|---|---|---|---|---|
| ChartQA (IDP-Leaderboard) | 79.20 | 78.56 | 76.20 | 84.82 |
| DocVQA (IDP-Leaderboard) | 85.15 | 89.43 | 84.00 | 85.51 |
Tips to improve accuracy
- Increasing the image resolution will improve model's performance.
- For complex tables (eg. Financial documents) using
repetition_penalty=1gives better results. You can try this prompt also, which generally works better for finantial documents.
user_prompt = """Extract the text from the above document as if you were reading it naturally. Return the tables in HTML format. Return the equations in LaTeX representation. If there is an image in the document and image caption is not present, add a small description of the image inside the <img></img> tag; otherwise, add the image caption inside <img></img>. Watermarks should be wrapped in brackets. Ex: <watermark>OFFICIAL COPY</watermark>. Page numbers should be wrapped in brackets. Ex: <page_number>14</page_number> or <page_number>9/22</page_number>. Prefer using โ and โ for check boxes. Only return HTML table within <table></table>."""
- This is already implemented in Docstrange, please use the
Markdown (Financial Docs)option for processing table heavy financial documents.
import requests
url = "https://extraction-api.nanonets.com/extract"
headers = {"Authorization": <API KEY>}
files = {"file": open("/path/to/your/file", "rb")}
data = {"output_type": "markdown-financial-docs"}
response = requests.post(url, headers=headers, files=files, data=data)
print(response.json())
- Model might work best on certain resolution for specific document types. Please check the cookbooks for details.
BibTex
@misc{Nanonets-OCR2,
title={Nanonets-OCR2: A model for transforming documents into structured markdown with intelligent content recognition and semantic tagging},
author={Souvik Mandal and Ashish Talewar and Siddhant Thakuria and Paras Ahuja and Prathamesh Juvatkar},
year={2025},
}
๐ If you find these models useful
Help me test my AI-Powered Quantum Network Monitor Assistant with quantum-ready security checks:
The full Open Source Code for the Quantum Network Monitor Service available at my github repos ( repos with NetworkMonitor in the name) : Source Code Quantum Network Monitor. You will also find the code I use to quantize the models if you want to do it yourself GGUFModelBuilder
๐ฌ How to test:
Choose an AI assistant type:
TurboLLM(GPT-4.1-mini)HugLLM(Hugginface Open-source models)TestLLM(Experimental CPU-only)
What Iโm Testing
Iโm pushing the limits of small open-source models for AI network monitoring, specifically:
- Function calling against live network services
- How small can a model go while still handling:
- Automated Nmap security scans
- Quantum-readiness checks
- Network Monitoring tasks
๐ก TestLLM โ Current experimental model (llama.cpp on 2 CPU threads on huggingface docker space):
- โ Zero-configuration setup
- โณ 30s load time (slow inference but no API costs) . No token limited as the cost is low.
- ๐ง Help wanted! If youโre into edge-device AI, letโs collaborate!
Other Assistants
๐ข TurboLLM โ Uses gpt-4.1-mini :
- **It performs very well but unfortunatly OpenAI charges per token. For this reason tokens usage is limited.
- Create custom cmd processors to run .net code on Quantum Network Monitor Agents
- Real-time network diagnostics and monitoring
- Security Audits
- Penetration testing (Nmap/Metasploit)
๐ต HugLLM โ Latest Open-source models:
- ๐ Runs on Hugging Face Inference API. Performs pretty well using the lastest models hosted on Novita.
๐ก Example commands you could test:
"Give me info on my websites SSL certificate""Check if my server is using quantum safe encyption for communication""Run a comprehensive security audit on my server"- '"Create a cmd processor to .. (what ever you want)" Note you need to install a Quantum Network Monitor Agent to run the .net code on. This is a very flexible and powerful feature. Use with caution!
Final Word
I fund the servers used to create these model files, run the Quantum Network Monitor service, and pay for inference from Novita and OpenAIโall out of my own pocket. All the code behind the model creation and the Quantum Network Monitor project is open source. Feel free to use whatever you find helpful.
If you appreciate the work, please consider buying me a coffee โ. Your support helps cover service costs and allows me to raise token limits for everyone.
I'm also open to job opportunities or sponsorship.
Thank you! ๐
- Downloads last month
- 237
Model tree for Mungert/Nanonets-OCR2-3B-GGUF
Base model
Qwen/Qwen2.5-VL-3B-Instruct