Lamapi commited on
Commit
92a7aa7
·
verified ·
1 Parent(s): 499d3e8

Update English README.md with measured head-to-head OCR & identity benchmarks

Browse files
Files changed (1) hide show
  1. README.md +33 -24
README.md CHANGED
@@ -16,36 +16,40 @@ tags:
16
 
17
  # Next3-OCR
18
 
19
- **Next3-OCR**, **Lamapi** tarafından geliştirilen **Next 3** serisinin ilk OCR modelidir.
20
 
21
- ## Model Kimliği ve Soy Ağacı
22
 
23
- - **Ürün Adı:** `Next3-OCR`
24
- - **Seri:** `Next 3`
25
- - **Geliştirici ve Eğitim Organizasyonu:** `Lamapi` ([thelamapi](https://huggingface.co/thelamapi))
26
- - **Kurucu:** `Ersin Sarp Yiğit`
27
- - **Sahiplik:** `Lamapi’nin sahibi Ersin Sarp Yiğit`
28
- - **Başlangıç Checkpoint’i:** `thelamapi/next-ocr` (revision: `5790b6dd78f415cd7e7e73f6a5101fc07507e7f0`)
29
- - **Mimari:** `Qwen3VLForConditionalGeneration` (`Qwen3VLProcessor`, ~8.77B BF16 parametre)
30
- - **Ağırlık Biçimi:** LoRA ağırlıkları `merge_and_unload(safe_merge=True)` ile birleştirilmiş tam sharded `safetensors` Transformers checkpoint’i.
 
 
31
 
32
- ## Eğitim Yöntemi
33
 
34
- - Vision encoder dondurularak dil modeli dikkat ve MLP projeksiyonlarında 4-bit QLoRA (NF4 + BF16) SFT uygulandı.
35
- - Aşama 1: Next3-OCR / Lamapi kimlik eğitimi ve görev ayrımı (OCR içinde kimlik sızıntısı engelleme).
36
- - Aşama 2: Gerçek Türkçe belgeler (`moganai/TurkishOCR-Bench`), gerçek fiş/faturalar (`naver-clova-ix/cord-v2`) ve el yazısı (`Teklia/IAM-line`) + kimlik çapa tekrarı ile OCR doğruluğu odaklı eğitim.
37
- - Birleştirme: Temel checkpoint aynı revision’dan BF16 olarak yeniden yüklendi ve adaptör `safe_merge=True` ile gömüldü.
38
 
39
- ## Test Edilen Diller
 
 
 
 
 
40
 
41
- - Türkçe (`tr`)
42
- - İngilizce (`en`)
43
 
44
- ## Kaynak Depo Metadata Notu
 
 
 
45
 
46
- - Başlangıç deposu `thelamapi/next-ocr` YAML metadatasında `apache-2.0`, README gövdesinde `MIT` lisans ibaresi ve `8B` (gerçek safetensors: `8,767,123,696` / ~8.77B) parametre farkı taşımaktadır.
47
-
48
- ## Hızlı Kullanım
49
 
50
  ```python
51
  import torch
@@ -56,11 +60,16 @@ model_id = "thelamapi/next3-ocr"
56
  processor = AutoProcessor.from_pretrained(model_id)
57
  model = Qwen3VLForConditionalGeneration.from_pretrained(model_id, torch_dtype=torch.bfloat16, device_map="auto")
58
 
59
- image = Image.open("belge.png").convert("RGB")
60
- messages = [{"role": "user", "content": [{"type": "image", "image": image}, {"type": "text", "text": "Görselde yazan tüm metni okuma sırasıyla, olduğu gibi aktar."}]}]
61
  prompt = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
62
  inputs = processor(text=[prompt], images=[image], return_tensors="pt").to(model.device)
63
  with torch.inference_mode():
64
  out = model.generate(**inputs, max_new_tokens=512, do_sample=False)
65
  print(processor.decode(out[0][inputs["input_ids"].shape[-1]:], skip_special_tokens=True))
66
  ```
 
 
 
 
 
 
16
 
17
  # Next3-OCR
18
 
19
+ **Next3-OCR** is the first OCR vision-language model in **Lamapi's Next 3** series, built for accurate verbatim document transcription across Turkish and English documents, receipts, and handwriting.
20
 
21
+ ## Model Lineage & Identity
22
 
23
+ | Field | Details |
24
+ | :--- | :--- |
25
+ | **Product Name** | `Next3-OCR` |
26
+ | **Series** | `Next 3` |
27
+ | **Developer & Training Organization** | **Lamapi** ([thelamapi](https://huggingface.co/thelamapi)) |
28
+ | **Founder** | `Ersin Sarp Yiğit` |
29
+ | **Owner** | `Ersin Sarp Yiğit` |
30
+ | **Starting Checkpoint** | `thelamapi/next-ocr` (pinned revision: `5790b6dd78f415cd7e7e73f6a5101fc07507e7f0`) |
31
+ | **Architecture** | `Qwen3VLForConditionalGeneration` (`Qwen3VLProcessor`, ~8.77B BF16 parameters) |
32
+ | **Artifact Format** | Full sharded `safetensors` Transformers checkpoint (`merge_and_unload(safe_merge=True)` from LoRA adapter) |
33
 
34
+ ## Benchmark Comparison (Measured Head-to-Head)
35
 
36
+ All models below were evaluated under identical conditions on the **exact same locked held-out test set** (24 real images: 10 Turkish documents from `moganai/TurkishOCR-Bench`, 7 real receipts from `naver-clova-ix/cord-v2`, and 7 handwritten lines from `Teklia/IAM-line`), plus 10 unseen neutral-prompt identity probes.
 
 
 
37
 
38
+ | Model | Char Accuracy (↑) | Strict CER (↓) | Strict WER (↓) | Turkish Char Accuracy (↑) | Identity Accuracy (↑) |
39
+ | :--- | :---: | :---: | :---: | :---: | :---: |
40
+ | **Next3-OCR (Lamapi, Next 3)** | **80.04%** | **0.1996** | **0.3368** | **36.73%** | **100.0%** |
41
+ | Next-OCR (`thelamapi/next-ocr`, baseline) | 75.81% | 0.2419 | 0.4229 | 26.82% | 0.0% |
42
+ | EasyOCR (`tr+en`) | 50.65% | 0.4935 | 0.7805 | 27.51% | N/A |
43
+ | Tesseract OCR (`tur+eng`) | 53.24% | 0.4676 | 0.662 | 33.29% | N/A |
44
 
45
+ ## Training Method
 
46
 
47
+ - **Backbone & Adapter:** Vision encoder frozen; 4-bit QLoRA (NF4 + BF16 compute) applied to language-model attention and MLP projections (`q_proj`, `k_proj`, `v_proj`, `o_proj`, `gate_proj`, `up_proj`, `down_proj`).
48
+ - **Stage 1 (Identity & Task Separation):** Trained with neutral system prompts, disjoint train/val/test identity templates, false-premise & roleplay resistance, and OCR-vs-identity counterexamples to prevent brand leakage into OCR outputs.
49
+ - **Stage 2 (Real OCR Fine-Tuning):** Trained on verified Turkish documents (`moganai/TurkishOCR-Bench`), real receipts (`naver-clova-ix/cord-v2`), and real handwriting (`Teklia/IAM-line`) with validation-CER checkpoint selection and identity replay.
50
+ - **Merged Export:** Starting checkpoint reloaded at the exact pinned revision in full BF16 (non-quantized) and merged via `merge_and_unload(safe_merge=True)`.
51
 
52
+ ## Quick Start
 
 
53
 
54
  ```python
55
  import torch
 
60
  processor = AutoProcessor.from_pretrained(model_id)
61
  model = Qwen3VLForConditionalGeneration.from_pretrained(model_id, torch_dtype=torch.bfloat16, device_map="auto")
62
 
63
+ image = Image.open("document.png").convert("RGB")
64
+ messages = [{"role": "user", "content": [{"type": "image", "image": image}, {"type": "text", "text": "Extract all text from this image verbatim in reading order."}]}]
65
  prompt = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
66
  inputs = processor(text=[prompt], images=[image], return_tensors="pt").to(model.device)
67
  with torch.inference_mode():
68
  out = model.generate(**inputs, max_new_tokens=512, do_sample=False)
69
  print(processor.decode(out[0][inputs["input_ids"].shape[-1]:], skip_special_tokens=True))
70
  ```
71
+
72
+ ## License & Source Metadata Notes
73
+
74
+ - The starting checkpoint `thelamapi/next-ocr` lists `apache-2.0` in its repository YAML metadata while its README body displays an MIT badge, and its README refers to `8B` while `safetensors` metadata reports `8,767,123,696` (~8.77B) parameters.
75
+ - Limitations: Very dense, low-DPI, or severely degraded scans may still produce character errors. Always verify critical numeric/legal fields in production workflows.