HindiText-Pilot / README.md
sinhal's picture
Add pilot dataset: 4,000 shaped Devanagari samples + masks, fonts, generator (part 14)
24e04bb verified
|
Raw History Blame Contribute Delete
7.93 kB
---
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}
}
```