Brahmi: Efficient Devanagari Token Injection for Multilingual LLMs (Technical Breakdown)

#1
by GautamKishore - opened
Eulogik org

Brahmi: Efficient Devanagari Token Injection for Multilingual LLMs

Abstract & Problem Overview

Multilingual transformer models built on English-heavy training corpora penalize Indian languages with a severe "Token Tax". Standard Byte-Pair Encoding (BPE) tokenizers (such as Qwen2.5's 151.9k vocabulary) split common Devanagari words into 3 to 4 fragmented byte tokens.

For example, the simple Hindi sentence:

"ज़रूरी बात है क्या करते हो"

  • Base Qwen2.5 Tokenizer: Burns 26 tokens 🔴
  • Bharat-Tiny-LLM v2 (Brahmi Tokenizer): Requires only 11 tokens 🟢 (58% Token Savings)

This token bloat inflates memory bandwidth requirements, slows down generation throughput, and forces early context window exhaustion.


Technical Innovation: Brahmi Token Injection

Instead of retraining a 1.5B model from scratch, we developed Brahmi Token Injection — a surgical two-stage vocabulary expansion and embedding alignment technique:

  1. Vocabulary Expansion: Identified top 300 recurring Devanagari subwords from a 50GB Hindi corpus and injected them into the tokenizer dictionary (expanding vocabulary from 151,936 to 152,236 tokens).
  2. Stage 1 (Embedding Alignment): Initialized new embedding matrix rows. Froze the transformer decoder backbone and trained strictly the 300 new token embeddings to align their representations with existing semantic space.
  3. Stage 2 (LoRA Fine-Tuning): Attached rank-16 PEFT LoRA adapters ($lpha=32$) across attention projection matrices (q_proj, k_proj, v_proj, o_proj) for downstream instruction tuning.

Empirical Benchmarks & Quantitative Results

Metric Base Qwen2.5-1.5B Bharat-Tiny-LLM v2 Technical Advantage
Tokens for 1,000 Hindi Chars ~950 tokens ~630 tokens 33.8% Token Reduction
Hindi Inference Speed 50 tok/s 68 tok/s +36% Faster Throughput
Validation Loss (Hindi Corpus) 2.776 1.837 52.5% Loss Reduction (Perplexity: 16.1 → 6.3)
Model Size (Q4 Affine) 880 MB 880 MB Runs in <3.8 GB RAM (Apple Silicon / PyTorch)

Code Quickstart

from transformers import AutoModelForCausalLM, AutoTokenizer
import torch

model_name = "eulogik/Bharat-Tiny-LLM-v2"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16, device_map="auto")

prompt = "भारत की सांस्कृतिक विविधता के बारे में बताइए:"
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens=150, temperature=0.7)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))

Open Weights & Apache 2.0 License. Built by Eulogik (@GautamKishore ).

Sign up or log in to comment