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.
Measured result: on the first 100 test pages, the merged model obtained 13.78% character error rate, 36.34% word error rate, and 99% valid JSON. It performed worse overall than the unmerged adapter on those same pages. These are 100-page results, not full-test scores or evidence of merge equivalence.
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.
Evaluation: the same 100 test pages
Evaluation used the first 100 records of the prepared test manifest in file
order: 37 Chagatai and 63 Persian pages. The adapter baseline was rescored
from its existing predictions on exactly those IDs. The merged model generated
new predictions using the same settings: enable_thinking=False,
do_sample=False, 6,144 new tokens, and a 4,194,304-pixel image budget.
| Model | CER, whitespace collapsed | CER, line breaks retained | WER | Valid JSON | Language Macro-F1 |
|---|---|---|---|---|---|
| Base + checkpoint-856 adapter | 11.99% | 12.29% | 34.72% | 100% | 100% |
| Merged BF16, this model | 13.78% | 14.07% | 36.34% | 99% | 99.60% |
| Merged model subset | Pages | CER, whitespace collapsed | WER |
|---|---|---|---|
| Chagatai | 37 | 12.62% | 42.50% |
| Persian | 63 | 14.27% | 34.15% |
The merged model increased overall character error by 1.80 percentage points and word error by 1.62 percentage points. It produced one invalid JSON response and two repetition flags; the adapter baseline had no invalid JSON and one repetition flag. The invalid merged response was a repetitive, unfinished JSON output on a Persian Masnavi page. The cause of the generation difference has not been established.
Metrics use the project's text normalization. CER_ws collapses whitespace;
CER_strict retains line breaks after normalization. Overall CER and WER divide
summed edit counts by summed reference lengths. Invalid JSON is scored as an
empty transcription. The language-balanced selection score is 0.135219:
0.50 ร CER_ws_chg + 0.50 ร CER_ws_fa + 0.20 ร (1 โ MacroF1_lang)
See merged aggregate metrics and the same-page adapter baseline. Their original local run paths remain in the metadata. These scores are not the full 328-page adapter test results documented in the source repository.
Limitations
- The merged model has been evaluated on 100 test pages, not the full 328-page test set. It can misread text, repeat passages, and emit incomplete JSON.
- 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