matenia03[at]gmail[dot]com
. For questions related to the architecture, contact: y.siglidis[at]gmail[dot]com
This page provides a comprehensive guide for using the Learnable Handwriter. The Learnable Handwriter is an adaptation of The Learnable Typewriter: A Generative Approach to Text Analysis for palaeographical morphological analysis.The tutorial covers preparing data, training and fine-tuning models, as well as best practices.
Your dataset must follow a specific structure for the system to work correctly. You will need to create a datasets/name-of-your-dataset
directory containing extracted images of text lines as well as their annotations in an annotation.json
, as illustrated in the image below.
datasets/<DATASET-NAME>/
βββ annotation.json
βββ images/
βββ <image_id>.png
βββ ...
The annotation.json
file must contain entries in this exact format:
{
"<image_id>": {
"split": "train", # {"train" or "val" if you don't want to train on these data but want to finetune on them}
"label": "your transcription text", # The ground truth text
"script": "Script_Type_Name", # Script category (hand or script type)
"page": "manuscript_page.jpg" # (optional) Source page reference, or other metadata
},
...
}
π You can download and follow the instructions in this notebook to automatically create a Learnable Handwriter-compatible dataset.
No GPU? You can still train models using our Google Colab notebook.
Or perform inference on pre-trained and fine-tuned models:
After cloning the repository and entering the base folder:
conda create --name lhr python=3.10
conda activate lhr
Follow the official PyTorch installation guide for your system. Ensure CUDA compatibility if using GPU.
python -m pip install -r requirements.txt
To get started quickly with our reference dataset from the paper βAn Interpretable Deep Learning Approach for Morphological Script Type Analysis (IWCP 2024)β :
datasets.zip
python scripts/train.py iwcp_south_north.yaml
python scripts/finetune_scripts.py -i runs/iwcp_south_north/train/ \
-o runs/iwcp_south_north/finetune/ \
--mode g_theta --max_steps 2500 --invert_sprites \
--script Northern_Textualis Southern_Textualis \
-a datasets/iwcp_south_north/annotation.json \
-d datasets/iwcp_south_north/ --split train
python scripts/finetune_docs.py -i runs/iwcp_south_north/train/ \
-o runs/iwcp_south_north/finetune/ \
--mode g_theta --max_steps 2500 --invert_sprites \
-a datasets/iwcp_south_north/annotation.json \
-d datasets/iwcp_south_north/ --split all
The configuration system uses YAML files to define hyperparameters, dataset paths, and training settings. Each experiment requires both a dataset configuration and a main configuration file.
configs/dataset/<DATASET_ID>.yaml
DATASET-TAG:
path: <DATASET-NAME>/
sep: '' # Character separator in annotation
space: ' ' # Space representation in annotation
configs/<DATASET_ID>.yaml
python scripts/train.py <CONFIG_NAME>.yaml
python scripts/finetune_scripts.py -i runs/<MODEL_PATH>/ \
-o <OUTPUT_PATH>/ --mode g_theta --max_steps <int> \
--invert_sprites --script '<SCRIPT_NAME>' \
-a <DATASET_PATH>/annotation.json \
-d <DATASET_PATH>/ --split <train or all>
python scripts/finetune_docs.py -i runs/<MODEL_PATH>/ \
-o <OUTPUT_PATH>/ --mode g_theta --max_steps <int> \
--invert_sprites -a <DATASET_PATH>/annotation.json \
-d <DATASET_PATH>/ --split <train or all>