Instructions to use Saidakmal/GLM-OCR-uz with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Saidakmal/GLM-OCR-uz with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="Saidakmal/GLM-OCR-uz") 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 AutoTokenizer, AutoModelForMultimodalLM tokenizer = AutoTokenizer.from_pretrained("Saidakmal/GLM-OCR-uz") model = AutoModelForMultimodalLM.from_pretrained("Saidakmal/GLM-OCR-uz", 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 = tokenizer.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(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Saidakmal/GLM-OCR-uz with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Saidakmal/GLM-OCR-uz" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Saidakmal/GLM-OCR-uz", "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/Saidakmal/GLM-OCR-uz
- SGLang
How to use Saidakmal/GLM-OCR-uz 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 "Saidakmal/GLM-OCR-uz" \ --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": "Saidakmal/GLM-OCR-uz", "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 "Saidakmal/GLM-OCR-uz" \ --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": "Saidakmal/GLM-OCR-uz", "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 Saidakmal/GLM-OCR-uz with Docker Model Runner:
docker model run hf.co/Saidakmal/GLM-OCR-uz
GLM-OCR-uz
GLM-OCR (0.9B) fine-tuned for printed Uzbek book pages: Uzbek Cyrillic, Uzbek Latin and Russian.
It reads the text exactly as printed, including old typefaces that leave out the diacritics in Ñž Ò› Ò“ Ò³. It does not "modernise" the spelling.
Accuracy
The test set has 41 pages from 29 books that were not used in training: 18 Uzbek Cyrillic, 15 Uzbek Latin and 8 Russian. Pages are scanned at about 150 dpi.
The reference text was proofread by hand, starting from Gemini's output.
Text is normalised before scoring:
- markdown removed;
- hyphenated line breaks joined;
- apostrophes and dashes unified.
| WER ↓ | all | Uzbek Cyrillic | Uzbek Latin | Russian | size |
|---|---|---|---|---|---|
GLM-OCR-uz (this model) + postfix.py |
4.5% | 5.7% | 1.4% | 7.4% | 0.9B |
| uzocr-8b | 3.9% | 5.1% | 1.8% | 4.8% | 8B |
| Gemini (API) | 2.2%* | 3.5%* | 1.5%* | 0.3%* | — |
* The reference was drafted from Gemini's text, so Gemini's numbers may be slightly optimistic.
Uzbek Latin is better than both uzocr-8b and Gemini. Uzbek Cyrillic is close to uzocr-8b at about 1/9 of its size. Russian is weaker; it is not the target language.
Speed
Both models ran on the same 41 pages on one RTX 5090 with vLLM 0.28.
- This model: bf16, pages upscaled to a 1600 px long side.
- uzocr-8b: FP8, pages upscaled to a 2000 px long side (its best setting).
| GLM-OCR-uz | uzocr-8b | speed-up | |
|---|---|---|---|
| latency, 1 page at a time | 1.5 s/page | 6.6 s/page | 4.4× |
| throughput, 16 parallel requests | 3.3 pages/s (≈11,800 pages/hour) | 0.68 pages/s | 4.8× |
| output tokens/s (16 parallel) | ~3,000 | ~600 | |
| model weights in VRAM | ~2.2 GB (bf16) | ~9 GB (FP8) |
With plain transformers (bf16, batch 1, no vLLM), it averages 5.0 s/page, uses 2.5 GB peak VRAM, and generates about 180 tokens/s.
Usage
Upscale small scans so the long side is about 1600 px. This matters a lot: on a hard test set, WER dropped from 17% to 8% with upscaling.
import torch
from PIL import Image
from transformers import AutoProcessor, GlmOcrForConditionalGeneration
from postfix import fix_mixed # optional: maps stray Latin homoglyphs inside Cyrillic words
M = "Saidakmal/GLM-OCR-uz"
proc = AutoProcessor.from_pretrained(M)
model = GlmOcrForConditionalGeneration.from_pretrained(M, dtype=torch.bfloat16, device_map="cuda").eval()
im = Image.open("page.jpg").convert("RGB")
s = 1600 / max(im.size)
im = im.resize((int(im.width * s), int(im.height * s)), Image.BICUBIC)
msgs = [{"role": "user", "content": [{"type": "image"}, {"type": "text", "text": "Text Recognition:"}]}]
prompt = proc.apply_chat_template(msgs, tokenize=False, add_generation_prompt=True)
x = proc(text=[prompt], images=[im], return_tensors="pt").to("cuda")
x.pop("token_type_ids", None)
out = model.generate(**x, max_new_tokens=3000, do_sample=False, repetition_penalty=1.05)
text = proc.decode(out[0][x["input_ids"].shape[1]:], skip_special_tokens=True).replace("<think></think>", "").strip()
print(fix_mixed(text))
vLLM:
vllm serve Saidakmal/GLM-OCR-uz --max-model-len 8192 --limit-mm-per-prompt '{"image":1}'
# chat/completions: image + "Text Recognition:", temperature 0, repetition_penalty 1.05
Training
The model is a full fine-tune of zai-org/GLM-OCR, trained in three rounds with 8-bit AdamW, batch 1 and gradient accumulation 8.
Real pages (about 26.6K) are scans of Uzbek and Russian books. They are labelled as follows:
- Uzbek Cyrillic: a word-level majority vote of three OCR systems (Gemini, uzocr-8b and an earlier version of this model). Its WER against the hand-checked reference is about 1.7%. 143 pages, where the systems disagreed, were checked by hand.
- Uzbek Latin and Russian: Gemini.
Pages in other Turkic Cyrillic orthographies are filtered out: Tajik, Karakalpak and others.
Synthetic pages: about 70K pages of rendered Uzbek and Russian text. They use many fonts, layouts and degradations, with exact labels.
Image size: pages are trained at a 1600 px long side, randomly scaled by 0.85–1.0.
Limitations
- The model is trained for printed text. Handwriting, tables and complex layouts are not specifically trained.
- Russian is noticeably weaker than Uzbek.
- The model sometimes misreads individual letters on very poor scans. That is where the larger uzocr-8b is still ahead.
- Downloads last month
- -
Model tree for Saidakmal/GLM-OCR-uz
Base model
zai-org/GLM-OCR