File size: 7,933 Bytes
92bae78
24e04bb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92bae78
24e04bb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
---
license: cc-by-4.0
language:
- hi
tags:
- devanagari
- hindi
- text-rendering
- synthetic
- diffusion
- stable-diffusion
task_categories:
- text-to-image
size_categories:
- 1K<n<10K
pretty_name: HindiText Pilot
---

# HindiText-Pilot

4,000 synthetic 512×512 image/text pairs for training diffusion models to render
**Hindi text in Devanagari script**. Correct HarfBuzz shaping, exact ground-truth
transcriptions, per-sample glyph masks.

Built as a feasibility pilot for a Stable Diffusion 1.5 LoRA, and released
because the hard parts — correct shaping and the VAE size floor — are reusable
regardless of what you train.

> **Note on scale.** This is a *pilot*: 72 distinct words. It exists to answer
> "can a model learn Devanagari glyph shapes at all", not to teach the script
> broadly. See [Limitations](#limitations) before using it as a training set.

## Why this exists

Most Devanagari datasets target **recognition** (OCR) and are deliberately
adversarial — blur, occlusion, low resolution. A *generator* trained on those
learns to produce blurry text. This is the opposite: clean, sharp, and
size-constrained so every sample is something a generator should aim to match.

## What makes Devanagari hard

- **Shirorekha** — a continuous horizontal bar joins letters across a word.
  Latin-trained models 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.
- **Fine diacritics** — nukta ़, anusvara ं, chandrabindu ँ are 2–8 pixel
  features that vanish under aggressive downsampling.

## Contents

```
data/images/           4,000 × 512×512 JPEG (quality 95)
data/masks/            4,000 × 512×512 PNG, 8-bit glyph coverage masks
data/metadata.jsonl    one record per sample
data/train_words.txt   72 words used in the images
data/holdout_words.txt 20 words deliberately NOT rendered
fonts/                 22 OFL Devanagari fonts + fonts/licenses/
corpus/pilot_words.txt the source word list
src/                   the generator — this dataset is reproducible
FINDINGS.md            the measurements behind the design
```

### `metadata.jsonl`

| field | meaning |
|---|---|
| `file` | path relative to `data/` |
| `text` | the Hindi string rendered — exact ground truth |
| `caption` | training caption (varied template) |
| `tokens` | CLIP token count of the caption, template included |
| `font` | filename in `fonts/` |
| `em` | font em size in pixels |
| `x`, `y`, `w`, `h` | text bounding box |
| `glyphs` | shaped glyph count — differs from character count due to ligatures |

```json
{"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 × 512 |
| 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 |

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

## How it was generated

Text is shaped with **HarfBuzz** (`uharfbuzz`) and rasterised per-glyph with
**FreeType** (`freetype-py`).

> ### ⚠️ If you extend this, do not use Pillow for the text
>
> 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, and silently corrupts the dataset.
>
> Check with `PIL.features.check('raqm')`. If it returns `False`, use
> `src/render/shaper.py` here instead.

Verified by `src/diag/verify_shaping.py`, which passes on all 22 fonts: क्ष / त्र /
ज्ञ each collapse 3 codepoints → 1 glyph, and the base consonant lands *second*
in कि, proving the matra reordered ahead of it.

Backgrounds are flat, gradient or lightly textured, with foreground/background
luminance contrast **enforced** (≥ 0.35) rather than sampled and hoped for.
Captions use 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.** SD1.5's 4-channel VAE downsamples 8×; measured encode→decode 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: the 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 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

- 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.

## Limitations

- **Synthetic only.** No photographic backgrounds, perspective, occlusion or
  real-world lighting. A model trained solely on this renders clean text but may
  not composite convincingly into photographs.
- **72 words is pilot scale** — far too small to teach the script broadly.
- **Partial conjunct coverage.** श्च has zero coverage in the rendered samples.
- **One script, one language.** Devanagari as used for Hindi. Marathi and Nepali
  share the script with minor differences and are not specifically covered.

## Licensing

- **Images, masks, metadata, generator code** — generated from the hand-written
  word list in `corpus/pilot_words.txt` using OFL fonts. No third-party data.
  **CC BY 4.0.**
- **`fonts/`** — 22 families from Google Fonts under the **SIL Open Font License
  1.1**, which permits redistribution. Full licence texts are included in
  `fonts/licenses/`. The OFL applies to those files, not CC BY.

Nothing in this repository is derived from any dataset whose terms prohibit
redistribution.

## Reproducing

```bash
pip install uharfbuzz freetype-py pillow numpy transformers
python src/diag/get_fonts.py          # fetch the 22 OFL fonts
python src/diag/font_audit.py         # coverage + conjunct-formation check
python src/diag/verify_shaping.py     # prove HarfBuzz shaping is active
python src/data/gen_pilot.py --n 4000 --out data/pilot --masks --seed 42
```

## Citation

```bibtex
@misc{hinditext_pilot_2026,
  title  = {HindiText-Pilot: synthetic Devanagari text-rendering pairs},
  author = {Sinhal},
  year   = {2026},
  url    = {https://huggingface.co/datasets/sinhal/HindiText-Pilot}
}
```