Image-Text-to-Text
Transformers
Safetensors
Turkish
English
qwen3_vl
ocr
multimodal
lamapi
next3
conversational
Instructions to use thelamapi/next3-ocr with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use thelamapi/next3-ocr with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="thelamapi/next3-ocr") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("thelamapi/next3-ocr") model = AutoModelForMultimodalLM.from_pretrained("thelamapi/next3-ocr", device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use thelamapi/next3-ocr with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "thelamapi/next3-ocr" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "thelamapi/next3-ocr", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/thelamapi/next3-ocr
- SGLang
How to use thelamapi/next3-ocr with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "thelamapi/next3-ocr" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "thelamapi/next3-ocr", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "thelamapi/next3-ocr" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "thelamapi/next3-ocr", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use thelamapi/next3-ocr with Docker Model Runner:
docker model run hf.co/thelamapi/next3-ocr
Update English README.md with measured head-to-head OCR & identity benchmarks
Browse files
README.md
CHANGED
|
@@ -16,36 +16,40 @@ tags:
|
|
| 16 |
|
| 17 |
# Next3-OCR
|
| 18 |
|
| 19 |
-
**Next3-OCR**
|
| 20 |
|
| 21 |
-
## Model
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
##
|
| 33 |
|
| 34 |
-
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
-
|
| 42 |
-
- İngilizce (`en`)
|
| 43 |
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
-
|
| 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("
|
| 60 |
-
messages = [{"role": "user", "content": [{"type": "image", "image": image}, {"type": "text", "text": "
|
| 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.
|