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.

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: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
(3)
this model