Model details
Table | |
|---|
| Architecture | Llama-style decoder (LlamaForCausalLM): RMSNorm, SwiGLU, RoPE, grouped-query attention, tied embeddings |
| Parameters | ~337M |
| Layers / hidden / FFN | 27 / 1024 / 2816 |
| Attention | 16 heads, 4 KV heads, head dim 64 |
| Context length | 2048 tokens |
| Vocabulary | 32,000 (SentencePiece BPE trained on Hindi, byte fallback, digits split) |
| RoPE theta | 10,000 |
| Weights | float32 safetensors (~1.3 GB) |
| Language | Hindi (Devanagari). English and other languages are not supported. |
Special tokens: <unk>=0, <s>=1, </s>=2, <pad>=3. The tokenizer also defines <|im_start|> and <|im_end|>, but they were not used in training. This model uses the plain-text template below.
How to use
The model was tuned on single-turn prompts in exactly this template. Use it, or the outputs will be noticeably worse.
import torchfrom transformers import AutoModelForCausalLM, AutoTokenizer repo = "srivassid/hindi-llm-340m-instruct"tok = AutoTokenizer.from_pretrained(repo)model = AutoModelForCausalLM.from_pretrained(repo, dtype=torch.bfloat16).to("cuda").eval() PROMPT = "### निर्देश:\n{instruction}\n\n### उत्तर:\n" def ask(instruction, max_new_tokens=300): ids = tok(PROMPT.format(instruction=instruction), return_tensors="pt").to("cuda") with torch.no_grad(): out = model.generate( **ids, max_new_tokens=max_new_tokens, do_sample=False, # greedy; use do_sample=True, temperature=0.7, top_p=0.9 for variety repetition_penalty=1.1, # helps with looping lists eos_token_id=tok.eos_token_id, ) return tok.decode(out[0, ids["input_ids"].shape[1]:], skip_special_tokens=True).strip() print(ask("भारत की राजधानी क्या है?"))
Notes:
- A
repetition_penalty of about 1.1 is recommended; without it, list-style answers (recipes, steps) tend to loop.
- Keep prompts and answers short. Long outputs drift and repeat.
- There is no multi-turn memory. Each call is independent.
Training
Pretraining
- Data: the Hindi (
hin) portion of AI4Bharat Sangraha, using the verified, unverified and synthetic subsets (native Devanagari only; romanized *_Latn synthetic data was excluded). 277 parquet files (~97 GB of text). About 25B Hindi tokens were available; the run consumed 10B tokens (19,074 steps).
- Objective: next-token prediction, packed sequences of 2048 tokens, no document masking.
- Batch: 524,288 tokens per step. Optimizer: AdamW (fused), peak LR 4e-4, 1,000 warmup steps, cosine decay to 4e-5. bf16 autocast,
torch.compile.
- Hardware / time: one RTX 5090 (32 GB), ~52k tokens/s, about 55 hours of compute. The run was stopped and resumed from checkpoints several times; data order is deterministic per step, so resumes are exact.
- Final held-out loss: 2.545 nats/token on a held-out Hindi validation set (perplexity ≈ 12.7 with this tokenizer; not comparable to perplexities from other tokenizers).
Instruction tuning (SFT)
Table with columns: Source, Examples| Source | Examples |
|---|
| anudesh | 7,253 |
| dolly (translated) | 14,459 |
| wikihow | 4,949 |
| oasst1 | 3,389 |
| lm_sys | 15,000 (capped) |
| flan_v2 | 15,000 (capped) |
| Total | 60,050, split into 59,050 train / 1,000 validation |
- Setup: full fine-tuning, loss on response tokens only, 3 epochs, LR 2e-5 with 3% warmup and cosine decay, effective batch 32, bf16. About 85 minutes on the same GPU.
- Validation loss: 1.822 (epoch 1), 1.797 (epoch 2), 1.818 (epoch 3). Epoch 3 overfits very slightly; the released weights are the end of epoch 3.
Evaluation
Scored by comparing the model's log-likelihood of each answer choice (no prompting tricks), on the Hindi test sets. "Sum" means total log-probability of the choice; this is the headline number.
Table with columns: Benchmark, Chance, Pretrained base, This model (SFT)| Benchmark | Chance | Pretrained base | This model (SFT) |
|---|
| IndicCOPA (hi, 449 items) | 50% | 55.0% | 57.9% |
| Belebele (hin_Deva, 900 items) | 25% | 29.6% | 29.8% |
Full breakdown
Accuracy, in percent. "Sum" ranks answer choices by total log-probability; "norm" divides by the number of answer tokens first. Both are shown because they differ by a point or two; compare models using the same column.
Table with columns: Benchmark / slice, n, Chance, Base (sum), Base (norm), SFT (sum), SFT (norm)| Benchmark / slice | n | Chance | Base (sum) | Base (norm) | SFT (sum) | SFT (norm) |
|---|
| IndicCOPA, all | 449 | 50 | 55.0 | 53.5 | 57.9 | 54.3 |
| IndicCOPA, "cause" questions | 223 | 50 | 56.1 | 53.4 | 59.2 | 54.7 |
| IndicCOPA, "effect" questions | 226 | 50 | 54.0 | 53.5 | 56.6 | 54.0 |
| Belebele hin_Deva | 900 | 25 | 29.6 | 28.2 | 29.8 | 27.9 |
Held-out language-model loss (not a benchmark, for reference): pretraining validation loss 2.545 nats/token on Hindi text (perplexity ≈ 12.7); SFT validation loss 1.818 on 1,000 held-out instruction examples.
How to read these: the standard error is about ±2.4 points on IndicCOPA (±3.3 on the cause/effect halves) and ±1.4 on Belebele. Both models are above chance, but the differences between base and SFT are within noise. Scores at this level are typical for a model of this size; it has little commonsense or reading-comprehension ability. Only two benchmarks were run; no knowledge (MMLU-style) or maths benchmarks were attempted because a model this size is expected to score near chance.
Method and reproduction
- IndicCOPA: the prompt is
"<premise without final danda> क्योंकि" for cause questions and "... इसलिए" for effect questions, followed by each choice. The choice with the higher log-likelihood is the prediction. No SFT prompt template is used, so this measures the language model rather than instruction following.
- Belebele: the prompt is
"<passage>\nप्रश्न: <question>\nउत्तर:" followed by each of the four answers; the answer with the highest log-likelihood is the prediction.
- Single run, no sampling, so the numbers are deterministic. Evaluation code is in the project's
hindillm/eval/ (copa.py, belebele.py); datasets are the public test files from the linked repositories.
Limitations
Please read before using the model.
- Factual errors are common and confident. Example from testing: asked for the chemical formula of water, it answered that water "contains hydrogen gas". It also gave the wrong name for Gandhi's father and a muddled history for Delhi as capital.
- Arithmetic and reasoning are unreliable. "5 apples, give away 2" returned "1 apple".
- Repetition and degeneration on long outputs and list-style tasks (a tea recipe turned into a loop of repeated ingredients).
- Often unable to complete creative or translation tasks. A request for a poem returned only the opening line; an English→Hindi translation request returned a generic greeting.
- Boilerplate openings such as "नमस्ते! मुझे आपकी मदद करने में खुशी हो रही है" appear often. These come from the translated chat data.
- Translated, machine-generated training data. The instruction data is largely machine-translated from English, so phrasing can sound unnatural and carries English-language cultural assumptions.
- No safety tuning. There was no RLHF, preference tuning or red-teaming. It may produce inaccurate, biased or inappropriate text, reflecting its web-scale pretraining data and chat data.
- Hindi only, single-turn only, 2048-token context.
Do not use this model for medical, legal, financial or other high-stakes decisions. Treat it as an experiment and a base for further research or fine-tuning.
License
The model weights and code in this repository are released under the Apache License 2.0.
Please note that the training data comes from several sources with their own terms, and the instruction data collection (ai4bharat/indic-instruct-data-v0.1) does not declare a single licence:
- Pretraining: AI4Bharat Sangraha, CC-BY-4.0 (attribution required).
- Instruction tuning: translated Dolly (CC-BY-SA-3.0), OASST1 (Apache-2.0), Anudesh, Flan v2, and translated wikiHow and LMSYS-Chat conversations, which carry their own upstream terms (wikiHow and LMSYS-Chat are, to my knowledge, non-commercial).
If your use is commercial or you redistribute derivative models, review the upstream terms yourself. The model author makes no legal claim about the data's terms.
Acknowledgements and citations
- AI4Bharat Sangraha (IndicLLMSuite) for the pretraining corpus.
- AI4Bharat indic-instruct-data-v0.1 for the instruction data, which also underlies the Airavata Hindi instruction-tuned model.
- Belebele (Meta) and IndicCOPA (AI4Bharat) for evaluation.
- Training code: a custom PyTorch Llama implementation (project
HindiLLM), exported to Hugging Face format.