marathi-mitra / data /create_dataset.py
ninadp's picture
πŸ“š Add vocabulary dataset β€” 30 Marathi words
041913c
Raw
History Blame Contribute Delete
2.33 kB
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()