ocr-gemma-3-4b-it

This model is a fine-tuned version of google/gemma-3-4b-it on the ocr_finetune_train dataset. It achieves the following results on the evaluation set:

  • Loss: 0.0547

Arabic Legal Documents OCR (Gemma-3-4B-IT)

Fine-tuned Gemma-3-4B-IT model for OCR and structured information extraction from Arabic legal document images.

Model Details

  • Base model: google/gemma-3-4b-it
  • Fine-tuning method: LoRA SFT using LLaMA-Factory
  • Task: OCR + structured JSON extraction
  • Language: Arabic
  • Domain: legal / official documents

Repository Structure

  • arabic-documents-ocr-v1/: merged inference ready model
  • checkpoints/: intermediate LoRA checkpoints
  • data/: training datasets and OCR images
  • training/: LLaMA-Factory training configs
  • notebooks/: evaluation notebook
  • adapter_config.json: LoRA adapter configuration

Intended uses & limitations

  • The model may hallucinate fields if the document is unclear.
  • OCR quality depends on scan resolution and image preprocessing.
  • Outputs should be validated before use in legal or production workflows.
  • Not suitable as a source of legal advice.

This model is intended for:

  • Arabic OCR extraction
  • legal document parsing
  • structured JSON generation from scanned pages
  • research and experimentation

Training and evaluation data

The model was trained on Arabic legal document page images paired with JSON outputs containing:

  • markdown-style page content
  • structural elements
  • headers / footers
  • lists and tables
  • legal articles
  • document metadata

Training hyperparameters

The following hyperparameters were used during training:

  • learning_rate: 0.0001
  • train_batch_size: 1
  • eval_batch_size: 1
  • seed: 42
  • gradient_accumulation_steps: 8
  • total_train_batch_size: 8
  • optimizer: Use OptimizerNames.ADAMW_TORCH_FUSED with betas=(0.9,0.999) and epsilon=1e-08 and optimizer_args=No additional optimizer arguments
  • lr_scheduler_type: cosine
  • lr_scheduler_warmup_steps: 0.1
  • num_epochs: 3.0

Training results

Training Loss Epoch Step Validation Loss
0.1468 1.0101 500 0.1214
0.0806 2.0202 1000 0.0706
0.0643 3.0 1485 0.0547

Framework versions

  • PEFT 0.18.1
  • Transformers 5.6.0
  • Pytorch 2.8.0+cu128
  • Datasets 4.0.0
  • Tokenizers 0.22.2

Dataset: https://laws.moj.gov.sa/ar/legislations-regulations?pageNumber=1&pageSize=9&sortingBy=7

Downloads last month
9
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for realml/ocr-gemma-3-4b-it

Adapter
(382)
this model