Hayai is a lightweight (~150M parameter) vision-to-text OCR model designed for fast, crop-level transcription across Japanese, Chinese, Korean, and English.
By pairing Google’s SigLIP2 NaFlex vision encoder with a 12-layer custom causal transformer decoder, Hayai reads dense, stylized, horizontal, and vertical text directly from images in a single forward pass without requiring a separate text detection stage (e.g., DBNet/YOLO). (Doesn't work for full pages though. Only crops)
What's New in v2.1 (Joint Multimodal + Linguistic Pretraining)
In prior versions, compact OCR models struggled with visually ambiguous CJK radicals and homoglyphs (e.g., confusing 銀 vs. 高 or 校 vs. 枚) because a pure image-trained decoder lacked statistical language priors.
Hayai v2.1 introduces Joint Multi-Task Training:
Zero-Overhead Language Prior Injection: Co-trained directly on streaming Wikipedia (JA, ZH, KO, EN) and Aozora Bunko corpora. Text-only passes enter the decoder directly with 1D RoPE (bypassing the vision backbone), teaching the decoder deep contextual CJK transition probabilities.
Radical & Counter Disambiguation: Eliminates homograph and counter errors on complex layouts.
Flawless Multi-Script Support: Significantly boosted English accuracy while maintaining high precision on vertical Japanese, Korean Hangul, and Chinese Hanzi.
Positional Embeddings: Dynamic 2D Multimodal Rotary Position Embeddings (2D mRoPE) over visual tokens; 1D RoPE over text tokens.
Attention Masking: Block-causal attention (bidirectional among visual patch tokens, causal across output text tokens).
Usage
python
1import torch
2from PIL import Image
3from transformers import AutoModel, AutoProcessor, PreTrainedTokenizerFast
45# Load Model, Processor & Tokenizer6MODEL_ID ="JustANormalTinkerer/hayai-ocr-v2"7model = AutoModel.from_pretrained(MODEL_ID, trust_remote_code=True).cuda().eval()8tokenizer = PreTrainedTokenizerFast.from_pretrained(MODEL_ID)9processor = AutoProcessor.from_pretrained("google/siglip2-base-patch16-naflex")1011# Load and Preprocess Image12image = Image.open("example.png").convert("RGB")13# Use max_num_patches=256 for standard lines; 384 or 512 for dense/complex panels14inputs = processor(images=[image], max_num_patches=256, return_tensors="pt").to("cuda")1516with torch.no_grad():17 texts = model.generate(18 pixel_values=inputs["pixel_values"],19 pixel_attention_mask=inputs["pixel_attention_mask"],20 spatial_shapes=inputs["spatial_shapes"],21 tokenizer=tokenizer,22 max_new_tokens=128,23 repetition_penalty=1.0,# Keep at 1.0 (disabled) for OCR accuracy24)2526print(texts[0])
Note:trust_remote_code=True is required because the model utilizes custom block-causal attention and 2D mRoPE definitions (configuration_hayai.py, modeling_hayai.py).
Also the previous version of the model card recommended setting num_beams to 4, ignore that. Greedy search will give the best results for Japanese, HOWEVER, tweak it as needed.
There also exists this python library that is recommended for python apps: hayai-ocr
*Throughput gain in v2.1 is due to optimized decoding batching.
Hayai OCR matches or outperforms 0.9B parameter models while delivering 10× higher throughput and operating within a ~300MB VRAM footprint in FP16.
Training Methodology
Training was conducted in two coordinated phases (for v2.1, for v2 refer to the older model card) using Kaggle 2× NVIDIA T4 GPUs.
1. Multi-Task Joint Base Training (~19,000 Steps)
OCR Stream:JustANormalTinkerer/hayai-dataset-merged (~1M images) streamed and sharded across GPUs.
Linguistic Prior Stream: Interleaved token-packed streams from Japanese, Chinese, Korean, and English Wikipedia alongside the Aozora Bunko clean literature dataset.
Loss Objective:
L_total = L_ocr + 0.30 * L_text
2. Optimization
Optimizer:Muon for decoder 2D weight matrices (orthogonalized momentum updates); AdamW for 1D vectors, embeddings, norms, and the SigLIP2 vision encoder.
Learning Rates: Base LR 8e-5 (Muon / Decoder AdamW) and 1e-5 (Vision AdamW), decayed via cosine schedule with a 5% linear warmup.
Augmentation: Random affine transforms, perspective shifts, subtle rotation (±6°), color jitter, blur, and sharpness adjustment.
Precision: Mixed Precision (FP16) with dynamic gradient scaling.
Text Normalization
For consistent Character Error Rate (CER) reproduction and downstream evaluation, text should be normalized as follows:
python
1import re
2import unicodedata
34defnormalize_text(text:str)->str:5ifnot text:6return""7 text = unicodedata.normalize("NFKC",str(text))8 text = re.sub(r'[\r\n\t]+',' ', text)9# Remove space only between CJK characters10 cjk_char =r'[\u4e00-\u9fff\u3040-\u30ff\u3400-\u4dbf\uac00-\ud7af]'11 text = re.sub(f'({cjk_char})\\s+({cjk_char})',r'\1\2', text)12return re.sub(r'\s+',' ', text).strip()
Best Practices & Limitations
Repetition Penalty: Keep repetition_penalty = 1.0. Penalties > 1.0 force the model to avoid valid repeated characters (e.g., 2校 ... 1校 or 学校).
Citations
# current Manga109
@inproceedings{baek2026mangav26,
title = {{Manga109-v2026: Revisiting Manga109 Annotations for Modern Manga Understanding}},
author = {Baek, Jeonghun and Miyai, Atsuyuki and Onohara, Shota and Ikuta, Hikaru and Aizawa, Kiyoharu},
booktitle = {Culture × AI Workshop at ICML 2026},
year = {2026},
}
# introducing Manga109 annotations
@article{multimedia_aizawa_2020,
author={Kiyoharu Aizawa and Azuma Fujimoto and Atsushi Otsubo and Toru Ogawa and Yusuke Matsui and Koki Tsubota and Hikaru Ikuta},
title={Building a Manga Dataset ``Manga109'' with Annotations for Multimedia Applications},
journal={IEEE MultiMedia},
volume={27},
number={2},
pages={8--18},
doi={10.1109/mmul.2020.2987895},
year={2020}
}
# introducing Manga109 image collection
@article{mtap_matsui_2017,
author={Yusuke Matsui and Kota Ito and Yuji Aramaki and Azuma Fujimoto and Toru Ogawa and Toshihiko Yamasaki and Kiyoharu Aizawa},
title={Sketch-based Manga Retrieval using Manga109 Dataset},
journal={Multimedia Tools and Applications},
volume={76},
number={20},
pages={21811--21838},
doi={10.1007/s11042-016-4020-z},
year={2017}
}
@inproceedings{baek2022COO,
title={COO: Comic Onomatopoeia Dataset for Recognizing Arbitrary or Truncated Texts},
author={Baek, Jeonghun and Matsui, Yusuke and Aizawa, Kiyoharu},
booktitle={Proceedings of the European Conference on Computer Vision (ECCV)},
year={2022}
}