Zum Inhalt springen
ModelAufgelistetExtern
Herunterladen

Ottoman Print OCR Qwen4B

This model is a vision-language adapter for Qwen3.5-4B with LoRA (via Unsloth) for Ottoman Turkish printed texts in printed Naskh font. It mainly operates at the line level. It might still work on multi-line level.

ArtLoRABasismodellunsloth/Qwen3.5-4BVersionadapter_modelCBewertung

Modellquelle

Art
LoRA
Dateigröße
591 MB
Basismodell
unsloth/Qwen3.5-4B
Version
vadapter_model
Aktualisiert
30. Okt. 2026
Downloads
0
Quelle
Hugging Face

Quellenbeschreibung

Model Card for Ottoman_Print_OCR_QWEN4B

This model is a vision-language adapter for Qwen3.5-4B with LoRA (via Unsloth) for Ottoman Turkish printed texts in printed Naskh font. It mainly operates at the line level. It might still work on multi-line level.

The output is not modern Turkish transliteration but the original Perso-Arabic script. In this way, researchers can analyze the ortographic patterns in Ottoman Turkish directly, such as how the question suffix, +mI, was written etc. Since there are different ways to transliterate a text (e.g., IJMES Transliteration and Modern Turkish alphabet) this approach preserves the information on the text as its original form and lets other researchers to build their of transliteration tools by using the output of this OCR model.

The model processes the data with 96% character-level accuracy and 80% word-level accuracy. With further normalization, these values go to 98% character-level and 88% word-level.

You can find an example on how this model can be used here Through this link, you can find Eşar-ı Ziya as processed for OCR. You can search for a word or phrase. Such an interface can be expandable to other works with this model as well.

Data

The training data consists of 48,306 words in 5,375 lines across nine printed Ottoman Turkish works (Eşar-ı Ziya to represent poetry, New Testament (vol 2, 1857 edition) for religious/narrative works, Medhal-i Fıkh for Islamic law language, Muahedat Mecmuası for diplomatic language), Solakzade Tarihi and Muhtasar Tarih-i Umumi for history domain, Mir'at-ı Alem for the language in magazines, Kozmoğrafya, yahut, İlm-i ahval-i sema for science/astrology domain, and Mecmua-i Fünûn-i Askeriyye for military domain).

The OCR training data was manually prepared by the author.

Since the training data does not cover all genres, it might not be comprehensively effective in all Ottoman Turkish documents.

The distribution of data per work can be seen below.

Source NameLinesWords
Medhal-i Fıkh5444749
New Testament142015672
Eşar-ı Ziya11917162
Muahedat Mecmuası4704744
Mir'at-ı Alem5004006
Solakzade Tarihi3003680
Mecmua-i Fünûn-i Askeriyye3002792
Muhtasar Tarih-i Umumi5004271
Kozmoğrafya, yahut, İlm-i ahval-i sema1501230
TOTAL537548306

Training Hyperparameters

The following hyperparameters were used during training:

HyperparameterValue
Learning Rate2e-05
Train Batch Size (per device)4
Gradient Accumulation Steps4
Optimizer8-bit AdamW (adamw_8bit)
LR Scheduler TypeCosine (cosine)
Warmup Ratio0.1
Weight Decay0.05
Number of Epochs3
Max Sequence Length256
LoRA R64
LoRA Alpha64
Seed3407

Training Results

The training process was stopped at 550 steps, achieving the following best evaluation metric:

  • Best Validation Loss: 0.139433

Evaluation Results

The model was evaluated on a test set of 658 lines.

MetricBaselineNormalized (Ye + Kef)
CER (Character Error Rate)4.12%2.37%
WER (Word Error Rate)19.9%12.13%
  • Mean Line CER: 3.03%
  • Median Line CER: 1.69%
  • Perfect Matches: 350 out of 807 lines (CER = 0)

Normalization Process

To achieve the best results, the following character normalization is recommended for the output:

  • \u064a and \u0649 $\rightarrow$ \u06cc (Persian/Arabic Ye)
  • \u0643 $\rightarrow$ \u06a9 (Kef/Keheh)
  • Removal of ZWNJ (\u200c) and ZWJ (\u200d)

The first two processes do not make any significant change on how the data looks like. The last one is optional. It is basically the invisible character to write a letter in the word-ending word in the middle of a word (like داىٔره‌ده). The model is supposed to put this character in its output.

How to Use

This model requires the unsloth library and torch.

from unsloth import FastVisionModel
import torch
from PIL import Image

# 1. Load Model & Tokenizer
model, tokenizer = FastVisionModel.from_pretrained(
    "enesyila/Ottoman-Print-OCR-Qwen4B",
    load_in_4bit=True,
)
FastVisionModel.for_inference(model)
tokenizer.padding_side = "left"

# 2. Load Image
image_path = "path_to_your_line_image.png"  # You should put the path of your image here.
image = Image.open(image_path).convert("RGB")

# 3. Prepare Prompt
instruction = "Transcribe the Ottoman Turkish printed text in this image."  # Please do not change this instruction. The model was trained with this instruction so it should work the best with this.
messages = [
    {"role": "user", "content": [
        {"type": "image"},
        {"type": "text", "text": instruction},
    ]}
]
prompt = tokenizer.apply_chat_template(messages, add_generation_prompt=True, enable_thinking=False) # disabling thinking ensures that the model will only give the OCR output and not its reasoning.

# 4. Tokenize & Generate
inputs = tokenizer(
    images=[image],
    text=[prompt],
    add_special_tokens=False,
    return_tensors="pt",
).to("cuda")

if "pixel_values" in inputs:
    inputs["pixel_values"] = inputs["pixel_values"].to(torch.bfloat16)

with torch.inference_mode():
    output_ids = model.generate(
        **inputs,
        max_new_tokens=128,  # This value is enough for just one line. If you want to process larger pieces of text, you can increase this value but I can't guarantee that the model will work on multi-line level.
        use_cache=True,
        do_sample=False,
        temperature=0.0,
        repetition_penalty=1.1,
    )

# 5. Decode Result
input_len = inputs.input_ids.shape[1]
result = tokenizer.decode(output_ids[0][input_len:], skip_special_tokens=True).strip()

print("Transcription:", result)

Copyright

This model is licensed under Creative Commons Attribution Non Commercial 4.0. Therefore, the commercial use is strictly forbidden. However, you can use this model for your research freely.

Contact

[email protected]

Quellen

1 Quelle
Hugging FacePrimärVersion 9642684e8aeeef3e35f0f73b576f43def0f6f255
huggingface.co/enesyila/Ottoman-Print-OCR-Qwen4B/tree/9642684e8aeeef3e35f0f73b576f43def0f6f255

Verifiziert 30. Okt.

Download files

Modellartefakte

1 Artefakt

adapter_model.safetensors

safetensors · 591 MB · SHA-256 1a9638b25b5d…22ef · Hugging Face

Download file

Quellenauszüge

2 Auszüge

--- license: cc-by-nc-4.0 language: - ota metrics: - cer - wer base_model: - unsloth/Qwen3.5-4B pipeline_tag: image-to-text tags: - OCR - Printed - Ottoman-Turkish --- # Model Card for Ottoman_Print_OCR_QWEN4B This model is a vision-language adapter for **Qwen3.5-4B** with LoRA (via Unsloth) for **Ottoman Turkish printed texts** in printed Naskh font. It mainly operates at the **line level**. It might still work on multi-line level. The output is not modern Turkish transliteration but the original Perso-Arabic script. In this way, researchers can analyze the ortographic patterns in Ottoman Turkish directly, such as how the question suffix, +mI, was written etc. Since there are different ways to transliterate a text (e.g., IJMES Transliteration and Modern Turkish alphabet) this approach preserves the information on the text as its original form and lets other researchers to build their of transliteration tools by using the output of this OCR model. The model processes the data with 96% character-level accuracy and 80% word-level accuracy. With further normalization, these values go to 98% character-level and 88% word-level. You can find an example on how this model can be used [here](https://koras0ff.github.io/Esar-i-Ziya-Pasa-OCRd/) Through this link, you can find _Eşar-ı Ziya_ as processed for OCR. You can search for a word or phrase. Such an interface can be expandable to other works with this model as well. ## Data The training data consists of 48,306 words in 5,375 lines across nine printed Ottoman Turkish works ([**_Eşar-ı Ziya_**](https://www.loc.gov/resource/amedhamid2.437039537) to represent poetry, [**_New Testament_**](https://scripture.dbs.org/pdfs/Turkish-1857-New-Testament-Turque-Nouveau-New-Testament-Incil-injil-Kitabi-Mukaddes-2-Vol.pdf) (vol 2, 1857 edition) for religious/narrative works, [**_Medhal-i Fıkh_**](www.loc.gov/resource/amedhamid2.437039501/) for Islamic law language, [**_Muahedat Mecmuası_**](https://www.loc.gov/resource/amedhamid2.437039707/) for diplomatic language), [**_Solakzade Tarihi_**](https://www.loc.gov/item/85146759/) and [**_Muhtasar Tarih-i Umumi_**](https://www.loc.gov/item/2016397763/) for history domain, [**_Mir'at-ı Alem_**](https://www.loc.gov/item/sn91038213/) for the language in magazines, [**_Kozmoğrafya, yahut, İlm-i ahval-i sema_**](https://www.loc.gov/item/2016397760/) for science/astrology domai...

Source context: 0 downloads · 0 likes · Pipeline image-to-text · Repo enesyila/Ottoman-Print-OCR-Qwen4B