๐ Nanonets-OCR-s GGUF Models
Nanonets-OCR-s GGUF models are advanced image - to - markdown OCR models, which can transform documents into structured markdown. They are equipped with intelligent content recognition and semantic tagging, making them highly suitable for downstream processing by Large Language Models (LLMs).
๐ Quick Start
Using transformers
from PIL import Image
from transformers import AutoTokenizer, AutoProcessor, AutoModelForImageTextToText
model_path = "nanonets/Nanonets-OCR-s"
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-OCR-s
- Predict with the model
from openai import OpenAI
import base64
client = OpenAI(api_key="123", base_url="http://localhost:8000/v1")
model = "nanonets/Nanonets-OCR-s"
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 docext
pip install docext
python -m docext.app.app --model_name hosted_vllm/nanonets/Nanonets-OCR-s
Checkout GitHub for more details.
โจ Features
Nanonets-OCR-s by Nanonets is a powerful, state - of - the - art image - to - markdown OCR model. It has the following features:
- LaTeX Equation Recognition: Automatically converts mathematical equations and formulas into properly formatted LaTeX syntax, distinguishing between inline (
$...$
) and display ($$...$$
) equations.
- Intelligent Image Description: Describes images within documents using structured
<img>
tags, suitable for LLM processing. It can describe various image types, including logos, charts, graphs, etc., detailing their content, style, and context.
- Signature Detection & Isolation: Identifies and isolates signatures from other text, outputting them within a
<signature>
tag, which 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.
๐ Documentation
Model Generation Details
This model was generated using llama.cpp at commit bf9087f5
.
Quantization Beyond the IMatrix
The author has been experimenting with a new quantization approach that selectively elevates the precision of key layers beyond what the default IMatrix configuration provides. Standard IMatrix quantization underperforms at lower bit depths, especially with Mixture of Experts (MoE) models. To address this, the --tensor - type
option in llama.cpp
is used to manually "bump" important layers to higher precision. You can see the implementation here:
๐ [Layer bumping with llama.cpp](https://github.com/Mungert69/GGUFModelBuilder/blob/main/model - converter/tensor_list_builder.py)
While this does increase model file size, it significantly improves precision for a given quantization level.
Choosing the Right GGUF Model Format
Click here to get info on choosing the right GGUF model format.
Testing the AI - Powered Quantum Network Monitor Assistant
If you find these models useful, you can help test the AI - Powered Quantum Network Monitor Assistant with quantum - ready security checks:
๐ Quantum Network Monitor
The full Open Source Code for the Quantum Network Monitor Service is available at the author's github repos (repos with NetworkMonitor in the name): Source Code Quantum Network Monitor. You can also find the code used 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's being tested
The author is 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 unfortunately 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 latest 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
The author funds the servers used to create these model files, runs the Quantum Network Monitor service, and pays for inference from Novita and OpenAI out of their 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 the author a coffee โ. Your support helps cover service costs and allows the author to raise token limits for everyone.
The author is also open to job opportunities or sponsorship.
๐ BibTex
@misc{Nanonets-OCR-S,
title={Nanonets-OCR-S: A model for transforming documents into structured markdown with intelligent content recognition and semantic tagging},
author={Souvik Mandal and Ashish Talewar and Paras Ahuja and Prathamesh Juvatkar},
year={2025},
}
๐ Information Table
Property |
Details |
Model Type |
Nanonets-OCR-s GGUF Models |
Base Model |
Qwen/Qwen2.5-VL-3B-Instruct |
Pipeline Tag |
image-text-to-text |
Tags |
OCR, pdf2markdown |
Library Name |
transformers |