Ramayana Series ┬╖ Indic LLMs from scratch

Ramayana LLM

рд╣рд┐рдиреНрджреА рдореЗрдВ рд╕реЛрдЪрдиреЗ рдФрд░ рдЬрд╡рд╛рдм рджреЗрдиреЗ рд╡рд╛рд▓реЗ рдЫреЛрдЯреЗ рднрд╛рд╖рд╛ рдореЙрдбрд▓

Three Hindi language models trained from random initialisation, without any pretrained weights, on a single 6 GB laptop GPU: Jatayu (11M), Hanuman (42M base) and Angad (42M, instruction-tuned to answer questions). The tokenizer, data pipeline, pretraining and fine-tuning were all built from scratch.

3models released
42.1Mparameters (largest)
56M + 37kpretraining tokens + Q&A pairs
6 GBRTX 3060 laptop GPU
The family

One epic, many models

Each model is named after a figure from the Ramayana whose role matches what the model does.

live
рдЬрдЯрд╛рдпреБ

Jatayu

11M ┬╖ Hindi

A small bird who took on a much bigger enemy. Our first test run: grammatical Hindi, made-up facts.

live
рд╣рдиреБрдорд╛рди

Hanuman

42M ┬╖ Hindi

Master of speech. Fluent, grammatical Hindi in an encyclopaedic style.

live
рдЕрдВрдЧрдж

Angad

42M ┬╖ Hindi chat

Rama's envoy. Hanuman instruction-tuned on 37k Hindi Q&A pairs, so it answers instead of just continuing.

planned
рдЬрд╛рдореНрдмрд╡рд╛рди

Jambavan

~110M ┬╖ Hindi

The wise elder. Larger model, trained on 1тАУ2B tokens of the Sangraha corpus.

planned
рд╕реЗрддреБ

Setu

multilingual

The bridge to Lanka. One model across Hindi, Marathi, Bengali, Tamil and more.

Why "Hanuman"

A name earned through grammar

When Hanuman first meets Rama in the Kishkindha Kanda, Rama tells Lakshmana that this messenger must have mastered grammar, because he spoke at length without a single mistake. Getting grammar right is the first thing a language model learns, and it is what this model does best.

рдиреВрдирдВ рд╡реНрдпрд╛рдХрд░рдгрдВ рдХреГрддреНрд╕реНрдирдордиреЗрди рдмрд╣реБрдзрд╛ рд╢реНрд░реБрддрдореНред
рдмрд╣реБ рд╡реНрдпрд╛рд╣рд░рддрд╛рдиреЗрди рди рдХрд┐рдЮреНрдЪрд┐рджрдкрд╢рдмреНрджрд┐рддрдореНрее Valmiki Ramayana, Kishkindha Kanda 3.29: "Surely he has studied the whole of grammar many times; though he spoke much, not one word was wrong."
Real outputs

What Hanuman writes

Unedited samples (temperature 0.8, top-p 0.95). Bold is the prompt and the rest is the model. The grammar is correct; facts are sometimes invented.

рдорд╣рд╛рддреНрдорд╛ рдЧрд╛рдВрдзреА рдиреЗ рдЗрд╕ рдкреНрд░рд╕реНрддрд╛рд╡ рдХреЛ рдЕрд╕реНрд╡реАрдХрд╛рд░ рдХрд░ рджрд┐рдпрд╛ред рдЧрд╛рдВрдзреА рдХреЗ рдЗрд╕ рднрд╛рд╖рдг рдореЗрдВ рдЙрдиреНрд╣реЛрдВрдиреЗ рдХрд╣рд╛ рдХрд┐ рдЧрд╛рдБрдзреАрдЬреА рдЕрдкрдиреЗ рдЖрдкрдХреЛ рджреЗрд╢ рдХреА рднрд╛рд╖рд╛ рд╕рдордЭреЗрдВ рдФрд░ рдЕрдкрдиреЗ рдЬреАрд╡рди-рдпрд╛рдкрди рдХреЛ рд╣реА рд╣рд┐рдиреНрджреА рдорд╛рдзреНрдпрдо рдмрдирд╛ рд╕рдХрддреЗ рд╣реИрдВтАж
Narrative style; keeps the subject consistent.
рд╣рд┐рдорд╛рд▓рдп рдкрд░реНрд╡рдд, рдЙрддреНрддрд░рд╛рдЦрдВрдб рдХрд╛ рдПрдХ рднреВ-рднрд╛рдЧ рд╣реИред рд╣рд┐рдорд╛рд▓рдп рдХреА рджрдХреНрд╖рд┐рдгреА рд╕реАрдорд╛ рджрдХреНрд╖рд┐рдг рдореЗрдВ рдиреЗрдкрд╛рд▓ рдХреЗ рд╣рд┐рдорд╛рд▓ рдкреНрд░рджреЗрд╢ рд╕реЗ рд▓рдЧрддреА рд╣реБрдИ рднрд╛рд░рдд рддрдХ рдлреИрд▓реА рд╣реБрдИ рд╣реИред
Geography roughly right: Uttarakhand, Nepal, India.
рднрд╛рд░рдд рдХреА рд░рд╛рдЬрдзрд╛рдиреА рдирдИ рджрд┐рд▓реНрд▓реА рдХрд╛ рдПрдХ рдХреНрд╖реЗрддреНрд░ рд╣реИред рдпрд╣ рд╢рд╣рд░ рджрд┐рд▓реНрд▓реА рдирдЧрд░ рдирд┐рдЧрдо рдХреЗ рд╕реНрд╡рд╛рдорд┐рддреНрд╡ рдореЗрдВ рд╣реИрдВтАж
Links Delhi to its municipal corporation.
рдХреНрд░рд┐рдХреЗрдЯ () рдПрдХ рдЦреЗрд▓ рд╣реИ рдЬреЛ рдореБрдЦреНрдп рд░реВрдк рд╕реЗ рдХреНрд░рд┐рдХреЗрдЯ рдореЗрдВ рдЦреЗрд▓реА рдЬрд╛рддреА рд╣реИред тАжрдЗрдпрд╛рди рдкреЛрдВрдЯрд┐рдВрдЧтАж
A typical small-model failure: right sentence shape, circular content, a made-up name.
Angad ┬╖ instruction-tuned

Ask it a question

Angad is Hanuman fine-tuned for about an hour on 37k Hindi questionтАУanswer pairs. Answer perplexity fell from 58.4 тЖТ 16.9, and it now ends every answer cleanly. It has learned how to answer, but not yet what is true.

рдкреНрд░рд╢реНрди: рд╕реНрд╡рд╕реНрде рд░рд╣рдиреЗ рдХреЗ рддреАрди рдЙрдкрд╛рдп рдмрддрд╛рдЗрдПред
1. рдмреЗрд╣рддрд░ рднреЛрдЬрди рдХрд░реЗрдВ тАж рдПрдХ рд╕реНрд╡рд╕реНрде рдЖрд╣рд╛рд░ рдмрдирд╛рдП рд░рдЦреЗрдВред 3. рдирд┐рдпрдорд┐рдд рд░реВрдк рд╕реЗ рд╡реНрдпрд╛рдпрд╛рдо рдХрд░реЗрдВ: рддрдирд╛рд╡ рдХрдо рдХрд░рдиреЗ рдФрд░ рд▓рдЧрд╛рддрд╛рд░ рд╡реНрдпрд╛рдпрд╛рдо рдХрд░рдиреЗ рдкрд░ рдзреНрдпрд╛рди рдХреЗрдВрджреНрд░рд┐рдд рдХрд░реЗрдВтАж
Follows the "three tips" instruction with a numbered list (and skips number 2).
рдкреНрд░рд╢реНрди: рд╣реЛрд▓реА рдХрд╛ рддреНрдпреЛрд╣рд╛рд░ рдХреНрдпреЛрдВ рдордирд╛рдпрд╛ рдЬрд╛рддрд╛ рд╣реИ?
рд╣реЛрд▓реА рдПрдХ рд▓реЛрдХрдкреНрд░рд┐рдп рддреНрдпреЛрд╣рд╛рд░ рд╣реИред рдпрд╣ рдПрдХ рдмрд╣реБрдд рд╣реА рдкреНрд░рд╛рдЪреАрди рддреНрдпреЛрд╣рд╛рд░ рд╣реИ, рдЬреЛ рд╣рд░ рд╕рд╛рд▓ рдЕрдХреНрдЯреВрдмрд░ рдХреЗ рдкрд╣рд▓реЗ рдФрд░ рдЕрдВрддрд┐рдо рджрд┐рдиреЛрдВ рдореЗрдВ рдордирд╛рдпрд╛ рдЬрд╛рддрд╛ рд╣реИред
Right tone, wrong month: Holi falls in Phalgun (March).
рдкреНрд░рд╢реНрди: рднрд╛рд░рдд рдХреА рд░рд╛рдЬрдзрд╛рдиреА рдХреНрдпрд╛ рд╣реИ?
рдЪреЗрдиреНрдирдИ
Answers briefly in the right format, but the fact is wrong. Small models need more parameters to store facts.
prompt = "<hi>рдкреНрд░рд╢реНрди: рд╣реЛрд▓реА рдХрд╛ рддреНрдпреЛрд╣рд╛рд░ рдХреНрдпреЛрдВ рдордирд╛рдпрд╛ рдЬрд╛рддрд╛ рд╣реИ?\nрдЙрддреНрддрд░: "
# model: ashishpatel26/angad-hi-42m  ┬╖  generate until </s>
Results

Perplexity on held-out Hindi

Measured on Wikipedia text the models never saw during training (lower is better). Making the model 4├Ч larger cut perplexity by more than half.

Jatayu ┬╖ 11M
107.5
Hanuman ┬╖ 42M
46.4

Instruction tuning: answer perplexity

Measured on 380 held-out Hindi questionтАУanswer pairs, scoring the answer tokens only. Fine-tuning made answers 3.5├Ч more predictable.

Hanuman ┬╖ base
58.4
Angad ┬╖ SFT
16.9
How it was built

From raw Wikipedia to a chat model

DownloadHindi Wikipedia (Nov 2023), 163k articles, 608 MB
CleanNFC normalisation, тЙе80% Devanagari, exact dedup тЖТ 948k lines
TokenizeSentencePiece Unigram, 32k vocab, ~1.1 tokens per Hindi word
Packuint16 memmap, no padding тЖТ 55.7M train tokens
PretrainHanuman: 3,500 steps ├Ч 65k tokens, bf16, cosine LR
Fine-tuneAngad: 37k Hindi Q&A, loss on answers only, 2 epochs, ~1 hour

Architecture

TypeLlama-style decoder (RMSNorm, SwiGLU, RoPE)
Hidden / FFN512 / 1408
Layers / heads8 / 8
Context512 tokens
EmbeddingsTied input/output
Vocabulary32,000 (byte fallback)

Training

GPURTX 3060 Laptop, 6 GB
Precisionbf16 autocast, SDPA attention
OptimiserAdamW (0.9, 0.95), wd 0.1, clip 1.0
LR schedule6e-4 тЖТ 6e-5 cosine, warmup
Tokens seen~229M (~4 epochs)
Val loss3.84
Try it

Run it in a few lines

Hanuman and Jatayu are base models: they continue the text you give them, so start the prompt with <hi>. Angad answers questions; use the template shown below.

# pip install torch transformers sentencepiece huggingface_hub

import torch, sentencepiece as spm
from huggingface_hub import hf_hub_download
from transformers import LlamaForCausalLM

repo = "ashishpatel26/hanuman-hi-42m"
model = LlamaForCausalLM.from_pretrained(repo)
sp = spm.SentencePieceProcessor(model_file=hf_hub_download(repo, "spm.model"))

x = torch.tensor([sp.encode("<hi>рд╣рд┐рдорд╛рд▓рдп рдкрд░реНрд╡рдд")])
y = model.generate(x, max_new_tokens=100, do_sample=True,
                   top_p=0.95, temperature=0.8, repetition_penalty=1.15)
print(sp.decode(y[0].tolist()))
# Angad: ask a question
repo = "ashishpatel26/angad-hi-42m"
model = LlamaForCausalLM.from_pretrained(repo)
sp = spm.SentencePieceProcessor(model_file=hf_hub_download(repo, "spm.model"))

x = torch.tensor([sp.encode("<hi>рдкреНрд░рд╢реНрди: рд╕реНрд╡рд╕реНрде рд░рд╣рдиреЗ рдХреЗ рддреАрди рдЙрдкрд╛рдп рдмрддрд╛рдЗрдПред\nрдЙрддреНрддрд░: ")])
y = model.generate(x, max_new_tokens=150, do_sample=True, top_p=0.9, temperature=0.7,
                   repetition_penalty=1.15, eos_token_id=sp.eos_id(), pad_token_id=sp.pad_id())
print(sp.decode(y[0, x.shape[1]:].tolist()))
What's next

Roadmap

Be honest

Limitations