Bangla GPT-2 (small), trained from scratch
A 23M-parameter GPT-2 language model trained from scratch on Bangla text, with a Bangla byte-level BPE tokenizer (32k vocabulary).
⚠️ A small research model. It writes fluent-looking Bangla but often makes up facts. It is not instruction-tuned and does not follow commands. Don't use its output as information.
Try it in your browser: irfanhossainsust/bangla-nlp-dashboard (runs locally with
transformers.js; the onnx/ folder holds fp32 and int8-quantized ONNX exports).
Usage
from transformers import AutoTokenizer, GPT2LMHeadModel
tok = AutoTokenizer.from_pretrained("irfanhossainsust/bangla-gpt2-small")
model = GPT2LMHeadModel.from_pretrained("irfanhossainsust/bangla-gpt2-small")
ids = tok("বাংলাদেশের রাজধানী", return_tensors="pt").input_ids
out = model.generate(ids, max_new_tokens=60, do_sample=True, temperature=0.8, top_p=0.95,
repetition_penalty=1.2, pad_token_id=tok.eos_token_id)
print(tok.decode(out[0], skip_special_tokens=True))
Training data
irfanhossainsust/bangla-nlp-corpus
v0.2.0, corpus config: Bangla Wikipedia, Wikisource (proofread pages only), Wikibooks, Wikiquote
and Wikivoyage, deduplicated and quality-filtered (CC BY-SA 4.0).
Training: 136,241,994 tokens (230,678 documents).
Validation: 7,553,621 tokens. The validation split shares no documents,
duplicate clusters or Wikisource books with train.
Tokenizer
Byte-level BPE, 32,000 tokens, trained on the corpus. Unlike GPT-2's English pre-tokenizer, it keeps Bangla vowel signs and the hasanta (Unicode marks) attached to their letters, so words aren't cut apart. On held-out text it averages 4.6 characters per token, vs 0.5 for the original GPT-2 tokenizer (9.3× shorter sequences).
Architecture and training
| Architecture | GPT-2: 6 layers, 6 heads, 384 hidden, context 512 |
| Parameters | 23,132,160 |
| Tokens per step | 32,768 |
| Steps | 4,157 (1.0 epoch) |
| Optimizer | AdamW (β=0.9/0.95, wd 0.1), peak LR 0.001, warmup 300, cosine to 10% |
| Hardware | Apple M4 (MPS), fp32, 2h41m |
Evaluation
Best validation loss 6.1692, so perplexity 477.8 (per BPE token; not comparable with models that use other tokenizers).
| Step | Val loss | Perplexity |
|---|---|---|
| 500 | 7.1687 | 1,298.2 |
| 1,000 | 6.7578 | 860.7 |
| 1,500 | 6.5713 | 714.3 |
| 2,000 | 6.4754 | 649.0 |
| 2,500 | 6.3317 | 562.1 |
| 3,000 | 6.2676 | 527.2 |
| 3,500 | 6.1849 | 485.4 |
| 4,000 | 6.1916 | 488.6 |
| 4,157 | 6.1692 | 477.8 |
Sample generations (temperature 0.8, top-p 0.95, seed 42+i)
- বাংলাদেশের রাজধানী একটি। জেলার থেকে কিলোমিটার অবস্থিত শহরটি ও অবস্থান শহর ভারতের সালের অনুযায়ীনগর জনসংখ্যা,�৯। মধ্যে,, এর পুরুষ% নারী নারী নারীদের এই বেশি। সাক্ষরতার ৮০ হল বছর তার কম। এখানে হার%। মধ্যে হার% নারীদের এই ৭৮ এবং মধ্যে
- রবীন্দ্রনাথ ঠাকুর ছিলেন আলশ চৌধুরী-ী চট্টোপাধ্যায়১৩২৪ (.) একজন বাঙালি, সমালোচক সাহিত্যিক কথাসাহিত্যিক ঔপন্যাসিক প্রাবন্ধিক গবেষক ইতিহাসবিদ সাহিত্যিক তিনি। রিতা () প্রথম বাংলা বাংলাদেশের যুদ্ধের বীর।: ()ুল রায়জন্মজন্ম ব্রিটিশ স্বাধীনতা এবং স্বাধীনতা অন্যতম ব্যক্তিত্ব
- সুন্দরবন অা -,-- সু -িনী শদী (ঃ), ন, প্র - হিনী ন খিয়া ধিলা র িরি প থ ব চ
Limitations and bias
- Trained only on encyclopedic and literary text (no news, conversation or social media), so the style is formal.
- Wikipedia over-represents geography, biographies and Bangladesh/India-centric topics.
- Small model: it can't reliably recall facts and will produce confident falsehoods.
- Not safety-tuned. It may reproduce biases in the source text.
License and attribution
Weights are released under CC BY-SA 4.0, following the share-alike license of the training text (© Wikipedia and Wikimedia contributors).