πŸ“‹ Model Description


language:
  • en
base_model:
  • nanonets/Nanonets-OCR-s
pipeline_tag: image-text-to-text tags:
  • OCR
  • unsloth
  • pdf2markdown
library_name: transformers

Unsloth Dynamic 2.0 achieves superior accuracy & outperforms other leading quants.

Nanonets-OCR-s is a powerful, state-of-the-art image-to-markdown OCR model that goes 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-OCR-s 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 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 tag. This is crucial for processing legal and business documents.
  • Watermark Extraction: Detects and extracts watermark text from documents, placing it within a 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.

πŸ“’ Read the full announcement | πŸ€— Hugging Face Space Demo

Usage

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",
attnimplementation="flashattention_2"
)
model.eval()

tokenizer = AutoTokenizer.frompretrained(modelpath)
processor = AutoProcessor.frompretrained(modelpath)

def ocrpagewithnanonetss(imagepath, model, processor, maxnew_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: <pagenumber>14</pagenumber> or <pagenumber>9/22</pagenumber>. 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.applychattemplate(messages, tokenize=False, addgenerationprompt=True)
inputs = processor(text=[text], images=[image], padding=True, return_tensors="pt")
inputs = inputs.to(model.device)

outputids = model.generate(inputs, maxnewtokens=maxnewtokens, dosample=False)
generatedids = [outputids[len(inputids):] for inputids, outputids in zip(inputs.inputids, output_ids)]

outputtext = processor.batchdecode(generatedids, skipspecialtokens=True, cleanuptokenizationspaces=True)
return output_text[0]

image_path = "/path/to/your/document.jpg"
result = ocrpagewithnanonetss(imagepath, model, processor, maxnew_tokens=15000)
print(result)

Using vLLM

  1. Start the vLLM server.
vllm serve nanonets/Nanonets-OCR-s
  1. Predict with the model
from openai import OpenAI
import base64

client = OpenAI(apikey="123", baseurl="http://localhost:8000/v1")

model = "nanonets/Nanonets-OCR-s"

def encodeimage(imagepath):
with open(imagepath, "rb") as imagefile:
return base64.b64encode(image_file.read()).decode("utf-8")

def ocrpagewithnanonetss(img_base64):
response = client.chat.completions.create(
model=model,
messages=[
{
"role": "user",
"content": [
{
"type": "image_url",
"imageurl": {"url": f"data:image/png;base64,{imgbase64}"},
},
{
"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: <pagenumber>14</pagenumber> or <pagenumber>9/22</pagenumber>. Prefer using ☐ and β˜‘ for check boxes.",
},
],
}
],
temperature=0.0,
max_tokens=15000
)
return response.choices[0].message.content

testimgpath = "/path/to/your/document.jpg"
imgbase64 = encodeimage(testimgpath)
print(ocrpagewithnanonetss(img_base64))

Using docext

pip install docext
python -m docext.app.app --modelname hostedvllm/nanonets/Nanonets-OCR-s
Checkout GitHub for more details.

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},
}

πŸ“‚ GGUF File List

πŸ“ Filename πŸ“¦ Size ⚑ Download
Nanonets-OCR-s-BF16.gguf
LFS FP16
5.75 GB Download
Nanonets-OCR-s-IQ4_NL.gguf
LFS Q4
1.7 GB Download
Nanonets-OCR-s-IQ4_XS.gguf
LFS Q4
1.62 GB Download
Nanonets-OCR-s-Q2_K.gguf
LFS Q2
1.19 GB Download
Nanonets-OCR-s-Q2_K_L.gguf
LFS Q2
1.19 GB Download
Nanonets-OCR-s-Q3_K_M.gguf
LFS Q3
1.48 GB Download
Nanonets-OCR-s-Q3_K_S.gguf
LFS Q3
1.35 GB Download
Nanonets-OCR-s-Q4_0.gguf
Recommended LFS Q4
1.7 GB Download
Nanonets-OCR-s-Q4_1.gguf
LFS Q4
1.86 GB Download
Nanonets-OCR-s-Q4_K_M.gguf
LFS Q4
1.8 GB Download
Nanonets-OCR-s-Q4_K_S.gguf
LFS Q4
1.71 GB Download
Nanonets-OCR-s-Q5_K_M.gguf
LFS Q5
2.07 GB Download
Nanonets-OCR-s-Q5_K_S.gguf
LFS Q5
2.02 GB Download
Nanonets-OCR-s-Q6_K.gguf
LFS Q6
2.36 GB Download
Nanonets-OCR-s-Q8_0.gguf
LFS Q8
3.06 GB Download
Nanonets-OCR-s-UD-IQ1_M.gguf
LFS
840.8 MB Download
Nanonets-OCR-s-UD-IQ1_S.gguf
LFS
788.06 MB Download
Nanonets-OCR-s-UD-IQ2_M.gguf
LFS Q2
1.09 GB Download
Nanonets-OCR-s-UD-IQ2_XXS.gguf
LFS Q2
925.72 MB Download
Nanonets-OCR-s-UD-IQ3_XXS.gguf
LFS Q3
1.21 GB Download
Nanonets-OCR-s-UD-Q2_K_XL.gguf
LFS Q2
1.22 GB Download
Nanonets-OCR-s-UD-Q3_K_XL.gguf
LFS Q3
1.52 GB Download
Nanonets-OCR-s-UD-Q4_K_XL.gguf
LFS Q4
1.82 GB Download
Nanonets-OCR-s-UD-Q5_K_XL.gguf
LFS Q5
2.08 GB Download
Nanonets-OCR-s-UD-Q6_K_XL.gguf
LFS Q6
2.58 GB Download
Nanonets-OCR-s-UD-Q8_K_XL.gguf
LFS Q8
3.66 GB Download
mmproj-BF16.gguf
LFS FP16
1.25 GB Download
mmproj-F16.gguf
LFS FP16
1.25 GB Download
mmproj-F32.gguf
LFS
2.49 GB Download