HindiText-Pilot / readme.md
sinhal's picture
Update readme.md
dc8fae5 verified
|
Raw History Blame Contribute Delete
8.09 kB

Hindi (Devanagari) Text Rendering — Pilot Dataset

Synthetic image/text pairs for training a diffusion model to render Hindi text in Devanagari script. 4,000 samples at 512x512, with typographically correct shaping, exact ground-truth transcriptions, and per-sample glyph masks.

Built as a feasibility pilot for a Stable Diffusion 1.5 LoRA. Sized to answer one question cheaply — can the model learn Devanagari glyph shapes at all? — rather than to train a production model.


Why this exists

Most text-rendering datasets are Latin-only, and most Devanagari datasets are built for recognition (OCR), not generation. Those are not interchangeable: recognition sets are deliberately adversarial — blurred, occluded, low-resolution — and a generative model trained on them learns to produce blurry, occluded text.

This dataset is the opposite: clean, sharp, and constrained so that every sample is something a generator should aim to reproduce.

What makes Devanagari hard

  • Shirorekha — a continuous horizontal bar joins letters across a word. Models trained on Latin produce broken or wavy bars.
  • Conjuncts — क् + ष → क्ष. Hundreds of ligatures whose shapes are not compositional from their parts.
  • Reordering — the matra ि is written before the consonant it follows logically.
  • Three vertical zones — matras sit above and below the base line, so glyph extent is far taller than Latin.
  • Fine diacritics — nukta ़, anusvara ं, chandrabindu ँ are 2–8 pixel features that vanish under aggressive downsampling.

Contents

data/pilot/
  images/          4,000 x 512x512 JPEG (quality 95)
  masks/           4,000 x 512x512 PNG, 8-bit glyph coverage masks
  metadata.jsonl   one record per sample
  train_words.txt  72 words used in the images
  holdout_words.txt 20 words deliberately NOT rendered
fonts/             22 OFL Devanagari fonts
corpus/            larger word lists (see Provenance)
src/               the generator, so results are reproducible

metadata.jsonl schema

field type meaning
file str path relative to data/pilot/
text str the Hindi string rendered — exact ground truth
caption str training caption (varied template)
tokens int CLIP token count of the caption, template included
font str filename in fonts/
em int font em size in pixels
x, y int top-left of the text box
w, h int text box size in pixels
glyphs int shaped glyph count (≠ character count, due to ligatures)
{"file": "images/000000.jpg", "text": "रुकें",
 "caption": "Hindi text \"रुकें\" on a board, flat design", "tokens": 18,
 "font": "Khand-Regular.ttf", "em": 40, "x": 150, "y": 405,
 "w": 62, "h": 48, "glyphs": 3}

Statistics

samples 4,000
resolution 512 x 512
unique words 72 train (+20 held out, never rendered)
fonts 22, evenly sampled (156–211 samples each)
font em size 32–120 px, mean 75.5
text box 44–454 px wide, 30–161 px tall
caption tokens 11–29 of CLIP's 77
glyphs per sample 2–8

Word vocabulary spans four groups: simple no-conjunct words, real signage vocabulary, conjunct-bearing words (क्ष ज्ञ त्र श्र द्व ह्म …), and diacritic stress cases (nukta, anusvara, chandrabindu, visarga).

How it was generated

  1. Shaping — text is shaped with HarfBuzz (uharfbuzz) and rasterised per-glyph with FreeType (freetype-py).

    This matters more than it sounds. Pillow's published wheels ship without Raqm, so ImageDraw.text() renders Devanagari unshaped: conjuncts break into separate letters and pre-base ि lands on the wrong side of its consonant. The output looks plausible to a non-reader while being wrong. Any dataset built that way teaches a model incorrect letterforms.

    Verified: क्ष / त्र / ज्ञ each collapse 3 codepoints → 1 glyph; ि reorders ahead of its consonant; स्त्री → 2 glyphs.

  2. Composition — flat, gradient, or lightly textured backgrounds; randomised font, size, position and colour, with foreground/background luminance contrast enforced (≥ 0.35), not sampled and hoped for.

  3. Captions — 10 templates × 12 surface nouns, with the quoted Hindi string as the single invariant anchor. The phrase "Hindi text" is dropped in ~20% of samples so a model does not become dependent on a trigger phrase.

The 32px rule

Every sample renders text at font em size ≥ 32px, asserted at generation time. This is not a stylistic choice. Stable Diffusion 1.5's 4-channel VAE downsamples 8×, and measured round-trips show Devanagari diacritics are destroyed below ~24px em and clean at 32px:

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

Note this is em size, not ink-box height: measured ink/em ratio varies 0.67–1.08 depending on which matras a word carries, so ink height is content-dependent and unsuitable as a threshold.

Consequence: this dataset covers headline- and signage-sized text, roughly 1–4 words. It is not suitable for training small or body-sized text rendering on a 4-channel VAE at 512px — that is a reconstruction limit no training run can overcome.

Intended use

  • Training / fine-tuning diffusion models (LoRA or full) for Devanagari text
  • Evaluating text-rendering quality, with exact transcriptions as ground truth
  • Glyph-conditioned approaches (ControlNet, GlyphControl, AnyText) — masks are included for this
  • The 20 held-out words test generalisation rather than memorisation

Not suitable for: OCR / scene-text recognition training (these are clean synthetic renders, not photographs), or small-text rendering (see above).

Limitations

  • Synthetic only. No photographic backgrounds, perspective, occlusion or real-world lighting. A model trained solely on this will render clean text but may not composite convincingly into photographs.
  • Small vocabulary. 72 words is a pilot scale, chosen to make the feasibility question cheap to answer. It is far too small to teach the script broadly.
  • Conjunct coverage is partial. श्च has zero coverage in the rendered samples; a larger stratified corpus is included separately.
  • One script, one language. Devanagari as used for Hindi. Marathi and Nepali share the script with minor differences and are not specifically covered.

Provenance and licensing

Three components with different origins — worth separating:

  1. Images and masks — generated by the included code from a hand-written word list (corpus/pilot_words.txt) using OFL fonts. No third-party data. Released under CC BY 4.0.

  2. Fonts (fonts/) — 22 families from Google Fonts, all under the SIL Open Font License 1.1, which permits embedding and redistribution. Includes Noto Sans/Serif Devanagari, Mukta, Hind, Halant, Tiro Devanagari Hindi, Baloo 2, Kalam, Khand, Martel, Modak, Palanquin, Rozha One, Sahitya, Teko, Yatra One, Amita, Biryani, Poppins. All audited for full Devanagari coverage and genuine conjunct formation.

  3. corpus/corpus.json — the larger 4,569-word stratified vocabulary is derived from transcriptions in IIIT-IndicSTR-Word (words only; no images from that dataset are included or redistributed here).

If you use the corpus component, cite the source dataset:

@inproceedings{mondal2024indic,
  title={Indic Scene Text on the Roadside},
  author={Mondal, Ajoy and Tulsyan, Krishna and Jawahar, CV},
  booktitle={International Conference on Document Analysis and Recognition},
  pages={263--278}, year={2024}, organization={Springer}
}