sinhal commited on
Commit
c816cce
·
verified ·
1 Parent(s): 92bae78

Create readme.md

Browse files
Files changed (1) hide show
  1. readme.md +198 -0
readme.md ADDED
@@ -0,0 +1,198 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Hindi (Devanagari) Text Rendering — Pilot Dataset
2
+
3
+ Synthetic image/text pairs for training a diffusion model to render **Hindi text
4
+ in Devanagari script**. 4,000 samples at 512x512, with typographically correct
5
+ shaping, exact ground-truth transcriptions, and per-sample glyph masks.
6
+
7
+ Built as a feasibility pilot for a Stable Diffusion 1.5 LoRA. Sized to answer one
8
+ question cheaply — *can the model learn Devanagari glyph shapes at all?* — rather
9
+ than to train a production model.
10
+
11
+ ---
12
+
13
+ ## Why this exists
14
+
15
+ Most text-rendering datasets are Latin-only, and most Devanagari datasets are
16
+ built for **recognition** (OCR), not **generation**. Those are not
17
+ interchangeable: recognition sets are deliberately adversarial — blurred,
18
+ occluded, low-resolution — and a generative model trained on them learns to
19
+ produce blurry, occluded text.
20
+
21
+ This dataset is the opposite: clean, sharp, and constrained so that every sample
22
+ is something a generator should aim to reproduce.
23
+
24
+ ## What makes Devanagari hard
25
+
26
+ - **Shirorekha** — a continuous horizontal bar joins letters across a word.
27
+ Models trained on Latin produce broken or wavy bars.
28
+ - **Conjuncts** — क् + ष → क्ष. Hundreds of ligatures whose shapes are not
29
+ compositional from their parts.
30
+ - **Reordering** — the matra ि is written *before* the consonant it follows
31
+ logically.
32
+ - **Three vertical zones** — matras sit above and below the base line, so glyph
33
+ extent is far taller than Latin.
34
+ - **Fine diacritics** — nukta ़, anusvara ं, chandrabindu ँ are 2–8 pixel
35
+ features that vanish under aggressive downsampling.
36
+
37
+ ## Contents
38
+
39
+ ```
40
+ data/pilot/
41
+ images/ 4,000 x 512x512 JPEG (quality 95)
42
+ masks/ 4,000 x 512x512 PNG, 8-bit glyph coverage masks
43
+ metadata.jsonl one record per sample
44
+ train_words.txt 72 words used in the images
45
+ holdout_words.txt 20 words deliberately NOT rendered
46
+ fonts/ 22 OFL Devanagari fonts
47
+ corpus/ larger word lists (see Provenance)
48
+ src/ the generator, so results are reproducible
49
+ ```
50
+
51
+ ### `metadata.jsonl` schema
52
+
53
+ | field | type | meaning |
54
+ |---|---|---|
55
+ | `file` | str | path relative to `data/pilot/` |
56
+ | `text` | str | the Hindi string rendered — exact ground truth |
57
+ | `caption` | str | training caption (varied template) |
58
+ | `tokens` | int | CLIP token count of the caption, template included |
59
+ | `font` | str | filename in `fonts/` |
60
+ | `em` | int | font em size in pixels |
61
+ | `x`, `y` | int | top-left of the text box |
62
+ | `w`, `h` | int | text box size in pixels |
63
+ | `glyphs` | int | shaped glyph count (≠ character count, due to ligatures) |
64
+
65
+ ```json
66
+ {"file": "images/000000.jpg", "text": "रुकें",
67
+ "caption": "Hindi text \"रुकें\" on a board, flat design", "tokens": 18,
68
+ "font": "Khand-Regular.ttf", "em": 40, "x": 150, "y": 405,
69
+ "w": 62, "h": 48, "glyphs": 3}
70
+ ```
71
+
72
+ ## Statistics
73
+
74
+ | | |
75
+ |---|---|
76
+ | samples | 4,000 |
77
+ | resolution | 512 x 512 |
78
+ | unique words | 72 train (+20 held out, never rendered) |
79
+ | fonts | 22, evenly sampled (156–211 samples each) |
80
+ | font em size | 32–120 px, mean 75.5 |
81
+ | text box | 44–454 px wide, 30–161 px tall |
82
+ | caption tokens | 11–29 of CLIP's 77 |
83
+ | glyphs per sample | 2–8 |
84
+
85
+ Word vocabulary spans four groups: simple no-conjunct words, real signage
86
+ vocabulary, conjunct-bearing words (क्ष ज्ञ त्र श्र द्व ह्म …), and diacritic
87
+ stress cases (nukta, anusvara, chandrabindu, visarga).
88
+
89
+ ## How it was generated
90
+
91
+ 1. **Shaping** — text is shaped with **HarfBuzz** (`uharfbuzz`) and rasterised
92
+ per-glyph with **FreeType** (`freetype-py`).
93
+
94
+ > This matters more than it sounds. Pillow's published wheels ship **without
95
+ > Raqm**, so `ImageDraw.text()` renders Devanagari *unshaped*: conjuncts break
96
+ > into separate letters and pre-base ि lands on the wrong side of its
97
+ > consonant. The output looks plausible to a non-reader while being wrong.
98
+ > Any dataset built that way teaches a model incorrect letterforms.
99
+
100
+ Verified: क्ष / त्र / ज्ञ each collapse 3 codepoints → 1 glyph; ि reorders
101
+ ahead of its consonant; स्त्री → 2 glyphs.
102
+
103
+ 2. **Composition** — flat, gradient, or lightly textured backgrounds; randomised
104
+ font, size, position and colour, with foreground/background luminance
105
+ contrast **enforced** (≥ 0.35), not sampled and hoped for.
106
+
107
+ 3. **Captions** — 10 templates × 12 surface nouns, with the quoted Hindi string
108
+ as the single invariant anchor. The phrase "Hindi text" is dropped in ~20% of
109
+ samples so a model does not become dependent on a trigger phrase.
110
+
111
+ ## The 32px rule
112
+
113
+ **Every sample renders text at font em size ≥ 32px, asserted at generation
114
+ time.** This is not a stylistic choice. Stable Diffusion 1.5's 4-channel VAE
115
+ downsamples 8×, and measured round-trips show Devanagari diacritics are
116
+ destroyed below ~24px em and clean at 32px:
117
+
118
+ | font em size | VAE reconstruction |
119
+ |---|---|
120
+ | 12–20 px | destroyed — nuktas gone, conjuncts illegible |
121
+ | 24 px | marginal — nukta merges into the stroke |
122
+ | **32 px** | **clean — minimum safe size** |
123
+ | 48–64 px | near-perfect |
124
+
125
+ Note this is **em size**, not ink-box height: measured ink/em ratio varies
126
+ 0.67–1.08 depending on which matras a word carries, so ink height is
127
+ content-dependent and unsuitable as a threshold.
128
+
129
+ Consequence: this dataset covers **headline- and signage-sized text**, roughly
130
+ 1–4 words. It is not suitable for training small or body-sized text rendering on
131
+ a 4-channel VAE at 512px — that is a reconstruction limit no training run can
132
+ overcome.
133
+
134
+ ## Intended use
135
+
136
+ - Training / fine-tuning diffusion models (LoRA or full) for Devanagari text
137
+ - Evaluating text-rendering quality, with exact transcriptions as ground truth
138
+ - Glyph-conditioned approaches (ControlNet, GlyphControl, AnyText) — masks are
139
+ included for this
140
+ - The 20 held-out words test generalisation rather than memorisation
141
+
142
+ **Not suitable for:** OCR / scene-text recognition training (these are clean
143
+ synthetic renders, not photographs), or small-text rendering (see above).
144
+
145
+ ## Limitations
146
+
147
+ - **Synthetic only.** No photographic backgrounds, perspective, occlusion or
148
+ real-world lighting. A model trained solely on this will render clean text but
149
+ may not composite convincingly into photographs.
150
+ - **Small vocabulary.** 72 words is a pilot scale, chosen to make the
151
+ feasibility question cheap to answer. It is far too small to teach the script
152
+ broadly.
153
+ - **Conjunct coverage is partial.** श्च has zero coverage in the rendered
154
+ samples; a larger stratified corpus is included separately.
155
+ - **One script, one language.** Devanagari as used for Hindi. Marathi and Nepali
156
+ share the script with minor differences and are not specifically covered.
157
+
158
+ ## Provenance and licensing
159
+
160
+ Three components with different origins — worth separating:
161
+
162
+ 1. **Images and masks** — generated by the included code from a hand-written word
163
+ list (`corpus/pilot_words.txt`) using OFL fonts. No third-party data.
164
+ Released under **CC BY 4.0**.
165
+
166
+ 2. **Fonts** (`fonts/`) — 22 families from Google Fonts, all under the **SIL Open
167
+ Font License 1.1**, which permits embedding and redistribution. Includes Noto
168
+ Sans/Serif Devanagari, Mukta, Hind, Halant, Tiro Devanagari Hindi, Baloo 2,
169
+ Kalam, Khand, Martel, Modak, Palanquin, Rozha One, Sahitya, Teko, Yatra One,
170
+ Amita, Biryani, Poppins. All audited for full Devanagari coverage and genuine
171
+ conjunct formation.
172
+
173
+ 3. **`corpus/corpus.json`** — the larger 4,569-word stratified vocabulary is
174
+ **derived from transcriptions in IIIT-IndicSTR-Word** (words only; no images
175
+ from that dataset are included or redistributed here).
176
+
177
+
178
+ If you use the corpus component, cite the source dataset:
179
+
180
+ ```bibtex
181
+ @inproceedings{mondal2024indic,
182
+ title={Indic Scene Text on the Roadside},
183
+ author={Mondal, Ajoy and Tulsyan, Krishna and Jawahar, CV},
184
+ booktitle={International Conference on Document Analysis and Recognition},
185
+ pages={263--278}, year={2024}, organization={Springer}
186
+ }
187
+ ```
188
+
189
+ ## Reproducing
190
+
191
+ ```bash
192
+ python src/diag/font_audit.py # verify fonts
193
+ python src/data/gen_pilot.py --n 4000 --masks --seed 42
194
+ python src/diag/verify_shaping.py # confirm shaping is active
195
+ ```
196
+
197
+ `PLAN.md` and `FINDINGS.md` document the full approach and every measurement
198
+ quoted above.