Add training / fine-tuning code (train_ocr.py --finetune-from + data loaders + TRAINING.md)
82eb32a verified Training / fine-tuning
Baberu OCR is a from-scratch 115M model: a frozen DINOv2 vision encoder, an MLP projector, and a custom 6-layer character-level GQA decoder. The training code is included so you can fine-tune the released checkpoint on your own bubbles, or reproduce the full recipe. All scripts are flat β run them from the repo root.
Fine-tune the released model on your own crops (Step 3)
Continues image->text training from the released weights with a fresh optimizer:
python train_ocr.py \
--crops-dir /path/to/your/crops \
--index /path/to/ocr_text_index.parquet \
--tokenizer-dir ./tokenizer \
--finetune-from . # load full weights from this repo, fresh schedule
--out-dir ./ft-out \
--epochs 1 --batch-size 96 --num-workers 8
# add --unfreeze-vision --vision-lr 1e-5 to also adapt the encoder
--finetune-from <dir>loadsconfig.json+model.safetensorsfrom<dir>(point it at this repo) and starts a fresh optimizer/schedule.--resume-from <dir>instead continues an interrupted run of this trainer (restores optimizer/scheduler/RNG fromtraining_state.pt).
Data format
--index is a parquet (built by build_ocr_index.py) pairing each crop id with
its text and language; --crops-dir holds the crop images the index refers to.
ocr_pairs.py / data_ocr.py show the exact loader β adapt them to your store.
Full recipe (from scratch)
train_text.pyβ pretrain the decoder as a character LM (FineWeb2 + text).train_text.pyagain β adapt to manga-style text (Step 2).train_ocr.py --init-decoder-from <step2>β connect vision and train on (crop, text) pairs; then re-run with--unfreeze-visionto adapt DINOv2.
See each script's module docstring for the exact flags.
Files
train_ocr.pyβ Step 3 image->text training / fine-tuning entrytrain_text.pyβ Step 1/2 character-LM pretrainingdata_ocr.py,ocr_pairs.pyβ OCR (crop, text) data loadingdata_baberu.py,data_fineweb.pyβ text data loading for the LM stagesbuild_ocr_index.pyβ build the crop->text index parquetmodeling_baberu.py,configuration_baberu.py,tokenization_baberu.pyβ the model