You need to agree to share your Hugging Face information to access this model

This repository is publicly accessible, but you have to accept the conditions to access its files and content.

Log in or Sign Up to review the conditions and access this model content.

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.

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:

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:T2 in training and mix_data:page_0233.json:T2 in 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 main branch 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
Safetensors
Model size
5B params
Tensor type
BF16
ยท
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Model tree for shbaydadaev/ocr-chg-fa-bf16

Finetuned
Qwen/Qwen3.5-4B
Finetuned
(2)
this model