Fast, accurate OCR with correctness assessment.
docs: spell out batched Jev scoring and threshold checks
LuMingcongdca8813ea06a
diff --git a/README.md b/README.mdindex a2fb6b1..c5263e3 100644--- a/README.md+++ b/README.md@@ -120,6 +120,8 @@ Accuracy at different review-free rates across three document types.<p align="center"><a href="./assets/minicpm-ocr/review-free-en.png"><img src="./assets/minicpm-ocr/review-free-en.png" alt="Accuracy versus review-free rate for legal documents, financial receipts, and complex documents." width="100%"></a></p>+Set the threshold only after checking it on a small batch from the real application.+### Decision ExamplesJev scores for text, formula, and table recognition.diff --git a/README_zh.md b/README_zh.mdindex 78bae99..5b4e4bf 100644--- a/README_zh.md+++ b/README_zh.md@@ -118,6 +118,8 @@<p align="center"><a href="./assets/minicpm-ocr/review-free-zh.png"><img src="./assets/minicpm-ocr/review-free-zh.png" alt="法律文书、财务票据和复杂文档在不同免检比例下的准确率。" width="100%"></a></p>+具体阈值的设定建议先在真实场景下进行小批量的验证再确定。+### 判别示例文本、公式和表格识别结果的 Jev 评分。diff --git a/docs/minicpm_ocr_jev_api_en.md b/docs/minicpm_ocr_jev_api_en.mdindex 7a10a24..5baa0ff 100644--- a/docs/minicpm_ocr_jev_api_en.md+++ b/docs/minicpm_ocr_jev_api_en.md@@ -93,7 +93,60 @@ The scoring settings belong in the top-level `minicpm_ocr_jev` object, not insid| `formula` | Formula LaTeX. Escape backslashes in JSON, for example `"$$\\frac{1}{2}$$"` || `table` | An HTML table. Convert OTSL or Markdown tables to HTML first |-`category` must match the real type of the region. A mismatch raises no error, but the score is off. When using `items`, set the image, text, and category on each item, and also place those same original images and candidate texts in `messages`.+`category` must match the real type of the region. A mismatch raises no error, but the score is off.++### Scoring One Candidate for Each of Several Regions++`mode` stays `score`. Put each region in `items`, and place the original images and candidate texts in `messages` in the same order. The pairing is defined by `items`. Encode `text_image_base64` and `formula_image_base64` the same way as `image_base64` above. The response has the same shape as a single-candidate score, and `results[i]` matches `items[i]`.++```python+response = client.chat.completions.create(+ model=os.environ["JEV_MODEL"],+ messages=[+ {+ "role": "user",+ "content": [+ {+ "type": "image_url",+ "image_url": {"url": f"data:image/png;base64,{text_image_base64}"},+ },+ {"type": "text", "text": "正文识别结果"},+ {+ "type": "image_url",+ "image_url": {"url": f"data:image/png;base64,{formula_image_base64}"},+ },+ {"type": "text", "text": "$$\\frac{1}{2}$$"},+ ],+ }+ ],+ extra_body={+ "minicpm_ocr_jev": {+ "mode": "score",+ "threshold": 0.5,+ "items": [+ {+ "case_id": "block-001",+ "image": f"data:image/png;base64,{text_image_base64}",+ "ocr_text": "正文识别结果",+ "category": "text",+ },+ {+ "case_id": "block-002",+ "image": f"data:image/png;base64,{formula_image_base64}",+ "ocr_text": "$$\\frac{1}{2}$$",+ "category": "formula",+ },+ ],+ },+ },+ stream=False,+)+result = json.loads(response.choices[0].message.content)+for item in result["results"]:+ if item["verdict"] != "scored":+ raise RuntimeError(f"{item['case_id']}: {item['verdict']}: {item.get('detail', '')}")+ print(item["case_id"], item["prob_yes"])+```### Selecting among Candidates for One Regiondiff --git a/docs/minicpm_ocr_jev_api_zh.md b/docs/minicpm_ocr_jev_api_zh.mdindex ea0af43..e42b28a 100644--- a/docs/minicpm_ocr_jev_api_zh.md+++ b/docs/minicpm_ocr_jev_api_zh.md@@ -93,7 +93,60 @@ print(item["prob_yes"])| `formula` | 公式 LaTeX。JSON 字符串中的反斜杠需要转义,例如 `"$$\\frac{1}{2}$$"` || `table` | HTML 表格。OTSL 或 Markdown 表格需先转成 HTML |-`category` 必须与块的真实类型一致,填错不会报错,但分数会偏。使用 `items` 时,在每个 item 里分别填写图片、文本和类别,并在 `messages` 中放上同样的原图和待评分文本。+`category` 必须与块的真实类型一致,填错不会报错,但分数会偏。++### 多块单候选评分++`mode` 仍为 `score`。每个块放进 `items`,并在 `messages` 里按同样顺序放上原图和候选文本;每条的对应关系以 `items` 为准。`text_image_base64` 和 `formula_image_base64` 的编码方式与上面的 `image_base64` 相同。返回结构与单候选评分相同,`results[i]` 对应 `items[i]`。++```python+response = client.chat.completions.create(+ model=os.environ["JEV_MODEL"],+ messages=[+ {+ "role": "user",+ "content": [+ {+ "type": "image_url",+ "image_url": {"url": f"data:image/png;base64,{text_image_base64}"},+ },+ {"type": "text", "text": "正文识别结果"},+ {+ "type": "image_url",+ "image_url": {"url": f"data:image/png;base64,{formula_image_base64}"},+ },+ {"type": "text", "text": "$$\\frac{1}{2}$$"},+ ],+ }+ ],+ extra_body={+ "minicpm_ocr_jev": {+ "mode": "score",+ "threshold": 0.5,+ "items": [+ {+ "case_id": "block-001",+ "image": f"data:image/png;base64,{text_image_base64}",+ "ocr_text": "正文识别结果",+ "category": "text",+ },+ {+ "case_id": "block-002",+ "image": f"data:image/png;base64,{formula_image_base64}",+ "ocr_text": "$$\\frac{1}{2}$$",+ "category": "formula",+ },+ ],+ },+ },+ stream=False,+)+result = json.loads(response.choices[0].message.content)+for item in result["results"]:+ if item["verdict"] != "scored":+ raise RuntimeError(f"{item['case_id']}: {item['verdict']}: {item.get('detail', '')}")+ print(item["case_id"], item["prob_yes"])+```### 单块多候选选优diff --git a/sdk/README.pypi.md b/sdk/README.pypi.mdindex 748136c..6b22d54 100644--- a/sdk/README.pypi.md+++ b/sdk/README.pypi.md@@ -117,6 +117,8 @@ Accuracy at different review-free rates across three document types.<p align="center"><a href="https://raw.githubusercontent.com/OpenBMB/MiniCPM-OCR/main/assets/minicpm-ocr/review-free-en.png"><img src="https://raw.githubusercontent.com/OpenBMB/MiniCPM-OCR/main/assets/minicpm-ocr/review-free-en.png" alt="Accuracy versus review-free rate for legal documents, financial receipts, and complex documents." width="100%"></a></p>+Set the threshold only after checking it on a small batch from the real application.+### Decision ExamplesJev scores for text, formula, and table recognition.