Egyptian ID OCR โ€” PaddleOCR-VL LoRA

An Arabic OCR adapter by Amr Osama Abdellatif that extracts six fields from the whole front of an Egyptian national ID card and returns JSON.

Task fine-tuning used synthetic cards. Real cards were used for development and evaluation. The pretrained base model is PaddlePaddle/PaddleOCR-VL.

Example extractions

Three Egyptian ID OCR examples, with extracted fields and draft references

These examples illustrate the input and output format using an earlier adapter version. The reference columns contain draft annotations. Portraits are masked in the preview.

Input and output

Input: one cropped or rectified image of the entire front of a card. The adapter performs joint extraction without a separate field detector.

JSON key Expected content
first_name Printed Arabic first name
paternal_names Printed remaining Arabic names
address Entire upper address line
governorate Entire lower address line, including locality, separators, and governorate
birthdate Date in YYYY/MM/DD format; derived from the national ID when not printed separately
national_id Fourteen ASCII digits, without spaces

The governorate key contains the full lower line, such as ู…ุฑูƒุฒ ุทู†ุทุง - ุงู„ุบุฑุจูŠุฉ.

Use the same extraction prompt used during training:

Read this Egyptian front ID card. Return only a JSON object with exactly these string keys: first_name, paternal_names, address, governorate, birthdate, national_id. Preserve Arabic text. address is the entire first address line. governorate is the entire second address line exactly as printed, including any district, center, city, separator, and governorate; do not shorten it to the governorate name. national_id must contain 14 ASCII digits without spaces. birthdate must use YYYY/MM/DD; derive it from the national ID if not printed.

Adapter details

Setting Value
Base model PaddlePaddle/PaddleOCR-VL
Recorded base revision 7fa00a8c55b735ba51ba49a9058f3f9c57a99a11
Adapter LoRA; rank 16; alpha 32; dropout 0
Trainable parameters 6,045,696; base model frozen

Synthetic-only training refers to task fine-tuning. The base model was already pretrained. Birthdate may be derived from national-ID digits when no separate date is printed.

Load the adapter

This is a PEFT adapter, not a standalone base model. Download the repository and run from its directory with PyTorch, Transformers, PEFT, Pillow, and Safetensors installed. The recorded training environment used Transformers 5.2.0 and PEFT 0.19.1.

The following CUDA example uses the recorded base revision and processor settings. Set IMAGE to a cropped front-card image.

import torch
from PIL import Image, ImageOps
from peft import PeftModel
from transformers import AutoProcessor, PaddleOCRVLForConditionalGeneration

BASE = "PaddlePaddle/PaddleOCR-VL"
REVISION = "7fa00a8c55b735ba51ba49a9058f3f9c57a99a11"
ADAPTER = "."  # Directory containing adapter_config.json and adapter weights.
IMAGE = "card.jpg"

PROMPT = (
    "Read this Egyptian front ID card. Return only a JSON object with exactly "
    "these string keys: first_name, paternal_names, address, governorate, "
    "birthdate, national_id. Preserve Arabic text. address is the entire first "
    "address line. governorate is the entire second address line exactly as "
    "printed, including any district, center, city, separator, and governorate; "
    "do not shorten it to the governorate name. national_id must contain "
    "14 ASCII digits without spaces. birthdate must use YYYY/MM/DD; derive "
    "it from the national ID if not printed."
)

processor = AutoProcessor.from_pretrained(BASE, revision=REVISION, use_fast=True)
processor.image_processor.size = {
    "shortest_edge": 256 * 28**2,
    "longest_edge": 768 * 28**2,
}
processor.tokenizer.padding_side = "left"
base = PaddleOCRVLForConditionalGeneration.from_pretrained(
    BASE,
    revision=REVISION,
    dtype=torch.bfloat16,
    attn_implementation="sdpa",
)
for key in ("bos_token_id", "eos_token_id", "pad_token_id"):
    value = getattr(processor.tokenizer, key)
    setattr(base.config, key, value)
    setattr(base.generation_config, key, value)
model = PeftModel.from_pretrained(base, ADAPTER).to("cuda").eval()

messages = [{"role": "user", "content": [
    {"type": "image"},
    {"type": "text", "text": PROMPT},
]}]
text = processor.apply_chat_template(
    messages, tokenize=False, add_generation_prompt=True
)
with Image.open(IMAGE) as source:
    image = ImageOps.exif_transpose(source).convert("RGB")
inputs = processor(text=[text], images=[image], return_tensors="pt").to("cuda")
with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16):
    output = model.generate(
        **inputs, max_new_tokens=384, do_sample=False, use_cache=True
    )
answer = processor.tokenizer.batch_decode(
    output[:, inputs["input_ids"].shape[1]:], skip_special_tokens=True
)[0]
print(answer)

The example follows the recorded inference settings. It has not been rerun as part of packaging this release.

License & Attribution

The adapter weights and original documentation in this release are licensed under the CC BY 4.0 License. See LICENSE for the full terms.

In plain English: you may use, share, adapt, and further fine-tune this adapter for academic or commercial purposes. Give credit to Amr Osama Abdellatif, link to the license, and state whether you made changes. When sharing, retain the supplied attribution and notices.

The PaddleOCR-VL base model is separately released under Apache 2.0. Its license and attribution requirements continue to apply. Third-party content reproduced in the example screenshots retains its existing rights; the adapter license does not relicense those source images. See NOTICE for upstream attribution.

Citation

If you use this adapter in your work or research, please cite:

@misc{abdellatif_egyptian_id_ocr_2026,
  author       = {Amr Osama Abdellatif},
  title        = {Egyptian ID OCR: PaddleOCR-VL LoRA},
  year         = {2026},
  publisher    = {Hugging Face},
  howpublished = {Hugging Face model repository},
  url          = {https://huggingface.co/amrosama/egyptian-id-ocr},
  note         = {Synthetic-only task fine-tuning for six-field Egyptian ID extraction}
}
Downloads last month
12
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Model tree for amrosama/egyptian-id-ocr

Adapter
(8)
this model