Instructions to use shbaydadaev/ocr-chg-fa-bf16 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use shbaydadaev/ocr-chg-fa-bf16 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="shbaydadaev/ocr-chg-fa-bf16") 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("shbaydadaev/ocr-chg-fa-bf16") model = AutoModelForMultimodalLM.from_pretrained("shbaydadaev/ocr-chg-fa-bf16", 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 shbaydadaev/ocr-chg-fa-bf16 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "shbaydadaev/ocr-chg-fa-bf16" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "shbaydadaev/ocr-chg-fa-bf16", "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/shbaydadaev/ocr-chg-fa-bf16
- SGLang
How to use shbaydadaev/ocr-chg-fa-bf16 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 "shbaydadaev/ocr-chg-fa-bf16" \ --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": "shbaydadaev/ocr-chg-fa-bf16", "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 "shbaydadaev/ocr-chg-fa-bf16" \ --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": "shbaydadaev/ocr-chg-fa-bf16", "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 shbaydadaev/ocr-chg-fa-bf16 with Docker Model Runner:
docker model run hf.co/shbaydadaev/ocr-chg-fa-bf16
OCR ChagataiโPersian, merged BF16
Whole-page OCR for historical Chagatai and Persian documents in Arabic script.
This is a standalone BF16 export of LoRA checkpoint-856, fine-tuned from
LlamaIndex OCRia-1. It returns one JSON
object with text, language, and script. No separate adapter is needed.
- Architecture:
Qwen3_5ForConditionalGeneration. - Stored tensor elements: 5,174,964,736, approximately 5.175 billion; BF16 weights in three safetensors shards.
- Source and CLI: shbaydadaev/OCR-chg-fa.
- Dataset: shbaydadaev/ocr-chg-fa-dataset.
- Recognition prompt: t2_recognition_system.txt.
Latest full-test result (2026-11-30): on all 328 test pages, this merged model obtained 14.74% character error rate (whitespace collapsed), 36.62% word error rate, and 98.78% valid JSON. All 328 predictions were verified against the test manifest, and rescoring the saved predictions reproduced the metrics exactly. Full metrics and prediction artifacts. The earlier 100-page adapter/merged comparison is retained below.
License and attribution
This model is governed by the upstream OCRia-1 Model and Code License, including its use-based restrictions and derivative-distribution requirements. It is not licensed under the separate Apache-2.0 license used for the project's original source code. Read the complete model license, including Attachment A, before use or redistribution.
The base model was developed by LlamaIndex, Inc. and is itself derived from
Qwen3.5-4B by the Qwen team, Alibaba Cloud.
This repository uses the OCRia-1 snapshot
489f5fa8f63858545368b9aff44256bbea6e46bc. It is an independently fine-tuned
derivative and does not imply endorsement by LlamaIndex or the Qwen team.
Modification notice: shbaydadaev fine-tuned the base with rank-32 LoRA for Chagatai/Persian JSON transcription, then merged checkpoint-856 into the base and exported BF16 weights. Model configuration, tokenizer, and processor assets were re-saved by the export tool. The original license and attribution notices are retained; see NOTICE.
Run OCR
Use the project CLI to apply the same prompt, image preparation, and decoding settings used for the recorded evaluation. Create an environment, install CUDA-compatible PyTorch and torchvision inside it, and install the project:
git clone https://github.com/shbaydadaev/OCR-chg-fa.git
cd OCR-chg-fa
python3.12 -m venv .ocria_ocr
source .ocria_ocr/bin/activate
# Install PyTorch and torchvision inside this environment before continuing.
python -m pip install -e ".[train]"
ocria-ocr-sft infer \
--model shbaydadaev/ocr-chg-fa-bf16 \
--image /path/to/page.jpg \
--system-prompt-file prompts/t2_recognition_system.txt \
--max-new-tokens 6144 \
--image-max-pixels 4194304 \
--pretty
Replace /path/to/page.jpg with your image. Do not pass --adapter when
loading this model. The CLI loads BF16 weights with device_map="auto", disables
thinking, uses greedy decoding, and prints the transcription with parse
diagnostics. Remove --pretty to print the raw generated response.
The intended output is:
{"text":"โฆ", "language":"chg", "script":"Arab"}
The model was trained on chg and fa targets. The prompt also allows ar,
mixed, and und; those labels are not supported by a separate evaluation here.
Check the returned JSON validity and transcription before downstream use.
Training and export
The recorded prepared dataset contains 3,423 training pages, 583 validation pages, and 328 test pages, with approximately 40% Chagatai and 60% Persian in each split. Preparation restores manuscript line breaks where available and applies the project's diplomatic Unicode normalization.
The run used four epochs, learning rate 3e-5, effective batch size 16 on one
GPU, LoRA rank 32, alpha 64, dropout 0.05, and a 10,240-token cutoff. LoRA covered
linear projections in the vision tower, visual merger, and both hybrid decoder
layer types. Base weights remained frozen during fine-tuning. Training used an
NVIDIA RTX PRO 6000 with 96 GB VRAM.
Checkpoint-856 had the lowest recorded validation loss, 0.537773, slightly below
step 800. Other checkpoints do not have the same completed generated validation
evaluation, so that loss comparison does not establish the best checkpoint by
OCR accuracy. Export used LLaMA-Factory with infer_dtype: bfloat16.
Latest evaluation: full 328-page test
This run evaluated every record in data/prepared/test_eval.jsonl: 131 Chagatai
and 197 Persian pages. It used the standalone merged BF16 weights, without a
separate adapter, and generated all predictions afresh. The checksums of all ten
evaluated model assets match the files in this Hugging Face model repository.
| Group | Pages | CER, whitespace collapsed | CER, line breaks retained | WER | Valid JSON |
|---|---|---|---|---|---|
| Overall | 328 | 14.74% | 15.23% | 36.62% | 98.78% |
| Chagatai | 131 | 19.16% | 19.36% | 48.78% | 100.00% |
| Persian | 197 | 12.54% | 13.18% | 31.34% | 97.97% |
Overall CER and WER divide summed edit counts by summed reference lengths; they are not equal-language averages. Equal-language mean CER (whitespace collapsed) is 15.85% and WER is 40.06%. Language Macro-F1 is 99.49%.
There were zero inference exceptions, four invalid JSON outputs (all Persian), and nine heuristic repetition flags. Invalid JSON is scored as an empty transcription and remains included in these scores. A repetition flag is not necessarily a failed response. All 328 prediction IDs are unique and exactly match the test manifest. The first 100 predictions match the earlier merged-model run exactly; the full-test scores use a larger evaluation population.
Generation used enable_thinking=False, do_sample=False, max_new_tokens=6144,
and image_max_pixels=4194304. The recorded environment was Python 3.12.13,
PyTorch 2.11.0+cu128, Transformers 5.17.0, and Accelerate 1.11.0 on an NVIDIA RTX
PRO 6000 Blackwell Max-Q Workstation Edition. The provenance files contain the
full command, runtime versions, source commit, input fingerprints, and evaluated
model-file checksums.
Artifacts:
- Full aggregate and per-language metrics
- All 328 predictions
- Metrics recomputed from saved predictions
- Evaluation settings and provenance
- Evaluated model-file manifest
- Completion verification
- Evaluation log
- Artifact SHA-256 checksums
To evaluate the full prepared test split with the project CLI:
ocria-ocr-sft evaluate \
--model shbaydadaev/ocr-chg-fa-bf16 \
--eval-jsonl data/prepared/test_eval.jsonl \
--images-root data/prepared \
--system-prompt-file prompts/t2_recognition_system.txt \
--max-new-tokens 6144 \
--image-max-pixels 4194304 \
--output-dir runs/test_merged_856_full
Use a fresh output directory for a fresh generation run. The CLI resumes saved
predictions by ID if the directory already contains predictions. Omitting
--limit evaluates all 328 records. The data-overlap and dataset-provenance
limitations below still apply to this full-test result.
Limitations
- The full 328-page test recorded four invalid JSON outputs and nine repetition flags. The model can misread text, repeat passages, and emit incomplete JSON; these results are specific to the prepared test split and recorded settings.
- A local data audit found a train/validation near-duplicate:
mix_data:page_0235.json:T2in training andmix_data:page_0233.json:T2in validation depict the same printed page and have identical references. The reported data and scores retain this pair. - Several named books/source groups occur in training, validation, and test. These are not exclusively unseen-book evaluations. Generic document IDs in mixed collections are not reliable book identifiers, and the audit is not an exhaustive guarantee against additional overlap.
- The original source dataset revision was not recorded; preparation resolved
its
mainbranch and could reuse local caches. The published dataset records the prepared files used by this project. - No performance or compatibility claim is made here for other OCR tasks, languages, quantized variants, vLLM, GGUF, or other serving runtimes.
The project repository includes preparation, scoring, and training code plus aggregate result provenance. Model weights and data retain their respective upstream terms.
- Downloads last month
- 8