HindiText-Pilot / FINDINGS.md
sinhal's picture
Add pilot dataset: 4,000 shaped Devanagari samples + masks, fonts, generator (part 14)
24e04bb verified
|
Raw History Blame Contribute Delete
2.82 kB

Feasibility findings — Hindi text LoRA on SD1.5

Measured 2026-09-28, CPU-only, on this machine. Scripts in src/diag/.

1. Shaping (verify_shaping.py) — SOLVED

Pillow's wheel ships without Raqm/HarfBuzz, so ImageDraw.text() renders Devanagari unshaped (broken conjuncts, ि on the wrong side). Silent corruption: it looks plausible unless you check.

Fix: src/render/shaper.py = uharfbuzz (shaping) + freetype-py (raster). Verified: क्ष/त्र/ज्ञ collapse 3 cp -> 1 glyph; ि reorders before its consonant; स्त्री -> 2 glyphs. Continuous shirorekha confirmed visually.

2. VAE capacity (vae_size_sweep.py, vae_visual.py) — HARD FLOOR AT ~32px EM

SD1.5's 4-ch VAE round-trip, measured inside the ink box:

font em size result
12-20px destroyed; nuktas gone, conjuncts illegible
24px marginal; nukta merges into stroke
32px clean — minimum safe size
48-64px near-perfect

=> Every training sample must render text at font em size >= 32px (FreeType set_pixel_sizes). NOT ink-box height: the measured ink/em ratio varies 0.67 (bhaarat, no tall matras) to 1.08 (hindii) depending on which matras a word carries, so ink height is content-dependent and a bad assert target. Em size controls stroke width and is what the sweep actually varied. => At 512 canvas this caps usable text at roughly 2-4 words. => SD1.5 can do headline/signage text. It cannot do small body text. Ever.

3. Text conditioning (tokenizer_test.py) — THE REAL BOTTLENECK

CLIP ViT-L/14 tokenizer vs Devanagari:

  • 0 of 49,408 vocab entries contain any Devanagari codepoint.
  • Falls back to raw UTF-8 byte BPE: ~1-2 tokens per character.
  • Character identity IS preserved (decode round-trips), so the signal is not information-theoretically lost — but CLIP never trained on these tokens, so the embeddings are meaningless.
  • 77-token cap: MEASURED ~1.1 tokens/char even for conjunct-heavy strings (kshatriya 8ch->9tok; pradhanmantri karyalaya 21ch->23tok). BPE merges the 3-byte UTF-8 sequences efficiently -- there is no conjunct blowup. With a 12-token caption template that leaves ~65 tokens = ~55-60 chars.

=> Must train the text encoder alongside the UNet. A UNet-only LoRA cannot work: the conditioning vectors it would read are noise. => The token cap is NOT the binding constraint. At em 32px (~17.6px/char advance) only ~27 chars fit across a 512px line, so PIXELS bind first. Enforce length in tokens anyway (exact, template included), but scope is set by the VAE floor.

Verdict

Viable, scope bounded by the VAE floor: short, large Devanagari text (1-4 words, <=27 chars per 512px line). Not viable: small or dense text.