Nanonets OCR2 八大核心能力,重新定義OCR技術(shù)
Nanonets-OCR2以Qwen2.5-VL-3B型號(hào)作為視覺語言模型 (VLM) 的基礎(chǔ)模型,為了訓(xùn)練新的視覺語言模型 (VLM) 以進(jìn)行高精度光學(xué)字符識(shí)別 (OCR),匯集了超過 300 萬頁的數(shù)據(jù)集。
該數(shù)據(jù)集包含廣泛的文檔類型, 包括研究論文、財(cái)務(wù)報(bào)告、法律合同、醫(yī)療記錄、稅表、收據(jù)和 發(fā)票。它還包括包含嵌入圖像、繪圖、方程式、簽名、水印、 復(fù)選框和復(fù)雜表。
此外,還納入了流程圖、組織結(jié)構(gòu)圖、手寫 材料和多語言文檔,以確保全面覆蓋現(xiàn)實(shí)世界的文檔變體。
橫向?qū)Ρ?/h2>- 與dots.ocr對(duì)比:在復(fù)選框檢測(cè)、流程圖提取、圖像描述、簽名識(shí)別、表格提取、水印處理六大維度,Nanonets OCR 2表現(xiàn)更精準(zhǔn),尤其在復(fù)雜結(jié)構(gòu)識(shí)別上優(yōu)勢(shì)顯著;
- 與主流模型對(duì)決:以Gemini-2.5-Pro為評(píng)測(cè)基準(zhǔn),Nanonets OCR 2+(高階版本)在“圖像轉(zhuǎn)Markdown”任務(wù)中,對(duì)陣Gemini 2.5 Flash、GPT-5、Nanonets-OCR-s等模型,勝率最高達(dá)57.6%,碾壓低階版本Nanonets-OCR2 1.5B(對(duì)方勝率僅13%);
- VQA能力評(píng)測(cè):在IDP Leaderboard數(shù)據(jù)集測(cè)試中,Nanonets OCR 2+在Chart QA任務(wù)得79.20分,DocVQA任務(wù)得85.15分,3B版本DocVQA得分更高達(dá)89.43分,接近甚至超越Qwen 2.5-VL-72B Instruct等主流大模型。
主要能力
- LaTeX 方程識(shí)別 自動(dòng)將數(shù)學(xué)方程式和公式轉(zhuǎn)換為格式正確的 LaTeX 語法。 內(nèi)聯(lián)數(shù)學(xué)表達(dá)式轉(zhuǎn)換為 LaTeX 內(nèi)聯(lián)方程,而顯示的方程是 轉(zhuǎn)換為 LaTeX 顯示方程。頁碼在<page_number>標(biāo)簽中預(yù)測(cè)。

- 智能圖像描述 使用結(jié)構(gòu)化標(biāo)記描述文檔中的圖像,使其易于 LLM 處理。如果 圖標(biāo)題存在,然后將其用作描述,否則模型將生成 描述。該模型可以描述單個(gè)或多個(gè)圖像(徽標(biāo)、圖表、圖形、二維碼等) 就其內(nèi)容、風(fēng)格和上下文而言。模型預(yù)測(cè)圖像描述 標(biāo)簽。
- 簽名檢測(cè)和隔離 識(shí)別簽名并將其與文檔中的其他文本隔離開來,這對(duì)法律和業(yè)務(wù)至關(guān)重要 文檔處理。該模型預(yù)測(cè)標(biāo)記中的簽名文本。如果 signature 不可讀,則模型會(huì)將signature返回給 標(biāo)記為已簽名。
- 水印提取 與簽名檢測(cè)類似,該模型可以檢測(cè)和提取文檔中的水印文本。模型預(yù)測(cè)標(biāo)簽內(nèi)的水印文本。該模型在低電平下表現(xiàn)良好 高質(zhì)量圖像,如下所示:

- 智能復(fù)選框處理 將表單復(fù)選框和單選按鈕轉(zhuǎn)換為標(biāo)準(zhǔn)化的 Unicode 符號(hào),實(shí)現(xiàn)一致性。模型預(yù)測(cè)標(biāo)記中的復(fù)選框狀態(tài)。

- 復(fù)雜表提取 從文檔中提取復(fù)雜表并將其轉(zhuǎn)換為 Markdown 和 html 表。
- 流程圖和組織結(jié)構(gòu)圖 該模型提取流程圖和組織結(jié)構(gòu)圖的美人魚代碼。
- 多語言 模型在多種語言的文檔上進(jìn)行訓(xùn)練,包括英語、中文、法語、西班牙語、 葡萄牙語、德語、意大利語、俄語、日語、韓語、阿拉伯語等等。

- 視覺問答 該模型旨在直接提供文檔中存在的答案;否則,它會(huì)回復(fù)“未提及”。

Nanonets-OCR2-3B實(shí)戰(zhàn)
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_implementatinotallow="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)本文轉(zhuǎn)載自??CourseAI??,作者:CourseAI
已于2025-10-23 11:23:10修改
贊
收藏
回復(fù)
分享
微博
QQ
微信
舉報(bào)
回復(fù)
相關(guān)推薦

















