A 30M parameter GPT language model trained from scratch on Kiswahili text using JAX and Flax NNX. Multi-day resumable training on Google Colab's free T4 GPU.
# Swahili GPT (MiniGPT-JAX) π°πͺπ€
A ~30 million parameter language model trained entirely from scratch on a pure Kiswahili dataset. Built using JAX and Flax (NNX API), this project demonstrates an end-to-end pipeline for training a compute-optimal Small Language Model (SLM) on Google Colab's free T4 GPUs.
## π Training Loss Curve
> Loss dropped from **9.56 β ~3.8** in the first 5,000 steps, confirming the model is learning Kiswahili structure. Full training runs to 200,000 steps.
## π Project Overview
This model is designed to be a highly efficient, lightweight Kiswahili text generation engine. By restricting the vocabulary to 10,000 tokens, the BPE tokenizer is forced to learn the agglutinative grammatical structure of Kiswahili (prefixes, infixes, roots) rather than memorizing massive words.
### Model Architecture
| Hyperparameter | Value |
|---|---|
| Parameters | ~30 Million |
| Framework | JAX / Flax (NNX API) / Optax |
| Context Window | 1024 tokens (~750 Swahili words) |
| Vocabulary Size | 10,000 tokens (Custom BPE) |
| Embedding Dim | 512 |
| Attention Heads | 8 |
| Transformer Blocks | 6 |
| Training Target | 200,000 steps (Chinchilla-optimal) |
## π Repository Structure
```
swahili-gpt/
βββ MiniGPT_Kiswahili_Resumable_Final.ipynb # Training notebook
βββ inference_demo.ipynb # Interactive inference on Colab
βββ inference.py # CLI inference script (local)
βββ requirements.txt # Python dependencies
βββ kenya_tokenizer.json # Custom 10k BPE tokenizer
βββ assets/
β βββ loss_curve.png # Training loss chart
βββ LICENSE
```
## π Getting Started
### Option A β Run inference on Colab (no setup)
Click the **Inference Demo** badge above. Mount your Drive and run all cells.
### Option B β Train the model yourself
1. Click the **Open in Colab** badge above.
2. Go to **Runtime β Change runtime type β T4 GPU β Save**.
3. Upload `kenya β¦