File size: 2,326 Bytes
041913c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import json
import os

# ── Load raw vocabulary from separate JSON ───────────────────────
def load_vocabulary(path="data/vocabulary.json"):
    with open(path, "r", encoding="utf-8") as f:
        return json.load(f)


# ── Prompt template ──────────────────────────────────────────────
INSTRUCTION = (
    "You are Marathi Mitra, a friendly Marathi teacher for kids. "
    "When given an English word, teach it in Marathi with the word "
    "in Devanagari script, pronunciation, a simple story sentence, "
    "and a fun fact. Always be encouraging and kid-friendly."
)


def format_output(item):
    """Format the structured output the model should produce."""
    return f"""🌟 **{item['word'].upper()}** in Marathi is **{item['marathi']}**

πŸ“’ **How to say it:** {item['pronunciation']}

πŸ“– **Example sentence:**
{item['sentence']}
*({item['translation']})*

πŸŽ‰ **Fun Fact:** {item['fun_fact']}"""


def format_training_example(item):
    """Format one vocabulary item into a training example."""
    input_text = f"Teach me the Marathi word for: {item['word']}"
    output_text = format_output(item)

    return {
        "word":        item["word"],
        "marathi":     item["marathi"],
        "instruction": INSTRUCTION,
        "input":       input_text,
        "output":      output_text,
        "text": f"""### Instruction:
{INSTRUCTION}

### Input:
{input_text}

### Response:
{output_text}"""
    }


# ── Build and save dataset ───────────────────────────────────────
def create_dataset():
    vocab = load_vocabulary()
    print(f"Loaded {len(vocab)} words from vocabulary.json")

    examples = [format_training_example(item) for item in vocab]

    output_path = "data/vocabulary_dataset.json"
    with open(output_path, "w", encoding="utf-8") as f:
        json.dump(examples, f, ensure_ascii=False, indent=2)

    print(f"βœ… Dataset saved β†’ {output_path}")
    print(f"βœ… Total examples: {len(examples)}")
    print(f"\nSample output:")
    print("─" * 50)
    print(examples[0]["text"])

    return examples


if __name__ == "__main__":
    create_dataset()