Data preparation
We received approximately 4,000 scanned forms from the client and employed a mix of strategies to train the models. Using the open-source tool Label Studio, we manually annotated layouts and transcribed handwritten fields. To overcome data scarcity and improve robustness, we generated synthetic datasets that combined various background noises with handwritten digits. Additionally, an automated pipeline was implemented to standardize the input images, ensuring consistent training conditions.
We curated specific datasets tailored to different tasks. For layout recognition, we utilized nearly 100 forms for training and over 1,000 for validation. The handwritten insurance numbers dataset consisted of approximately 700 training samples and a similar number for validation, while the handwritten IBAN dataset included over 100 samples for both training and validation. To supplement these real-world examples, we generated over 10,000 synthetic examples for both insurance numbers and IBANs.
Data preparation was performed on dida's self-hosted infrastructure using a server dedicated to the data pipeline and Label Studio.
AI model development
We utilized a two-stage approach using pre-trained open-source models as a foundation. For the Layout Model, we employed the RT-DETR (Real-Time Detection Transformer), to locate specific fields on the page. For the OCR Model, we used Microsoft's TrOCR (Transformer-based Optical Character Recognition), to read the text within the located fields.
Both models were fine-tuned on the specific domain data of the client forms. We utilized MLflow to track metrics during training runs and DVC (Data Version Control) to manage dataset versions. Additionally, hyperparameter tuning was performed to carefully balance accuracy with the inference speed constraints.
Training was conducted on high-performance, self-hosted hardware to ensure data never left dida's secure environment.
Operations
The final deliverable is a Docker container running on the client's infrastructure with a REST API interface. The hardware is optimized for CPU-only inference, meaning no GPUs are required in production. To achieve a processing time of approximately 2 seconds per page (with 2 fields), the service scales effectively with 8 CPU cores. Furthermore, the container is stateless and requires no external internet connection, ensuring strict data privacy.
Results and metrics
Layout recognition
The model demonstrated a high ability to correctly find the fields on the page (Intersection over Union > 80%), achieving a Precision > 97% and a Recall of > 98%.
Handwriting recognition
For OCR, the system returns 4 candidates. Since insurance numbers and IBANs have checksums, the system can automatically validate which candidate is correct. We achieved a > 97% accuracy for insurance numbers and a slightly worse result for IBANs, noting that IBANs are significantly longer and harder to write within the box constraints.
End-to-end evaluation
In a real-world test of around 100 forms, > 90% were processed completely correctly, while in the majority of the error cases, the handwriting recognition was correct, but the user had entered invalid data (e.g., wrong format), requiring manual review. Only 1% in this test suffered from an OCR error due to poor scan quality.
Assets
The client received full documentation and source code for the REST API, data processing, and training. We also delivered Docker images for the service, the trained model weights, and the evaluation datasets.