HindiText-Pilot / src /data /captions.py
sinhal's picture
Add pilot dataset: 4,000 shaped Devanagari samples + masks, fonts, generator (part 14)
24e04bb verified
Raw History Blame Contribute Delete
1.55 kB
"""Caption templates.
A single fixed template would teach the LoRA to render text only inside that
one sentence, and would fight other checkpoints' prompting styles -- which
directly undermines the plug-and-play goal. So: the scene wording varies, and
the quoted Hindi string is the one invariant anchor.
"""
from __future__ import annotations
import random
# Templates that name the language explicitly.
NAMED = [
'a sign with the Hindi text "{t}"',
'a photo of a sign reading "{t}" in Hindi',
'Hindi text "{t}" on a {surface}',
'a {surface} with Hindi writing "{t}"',
'Devanagari text "{t}" on a {surface}',
'"{t}" written in Hindi on a {surface}',
]
# Templates that do NOT name the language. ~20% of samples use these so the
# model does not come to depend on the trigger phrase.
UNNAMED = [
'a {surface} with the text "{t}"',
'a sign that reads "{t}"',
'"{t}" printed on a {surface}',
'text "{t}" on a {surface}',
]
SURFACES = [
"sign", "signboard", "poster", "banner", "shop sign", "plaque",
"billboard", "notice board", "label", "book cover", "wall", "board",
]
STYLES = [
"", "", "", "", # most samples get no style suffix
", photograph", ", high resolution", ", sharp focus",
", clean design", ", studio lighting", ", flat design",
]
def make_caption(text: str, rng: random.Random) -> str:
named = rng.random() > 0.20
tpl = rng.choice(NAMED if named else UNNAMED)
cap = tpl.format(t=text, surface=rng.choice(SURFACES))
return cap + rng.choice(STYLES)