CoolFace
Modelpublic

Benjamin-png/swahili-gpt-71m-instruct

sourceHugging Facecc-by-nc-4.0updated 3mo agoView on Hugging Face
2likes15downloads
Model Card

<p align="center"> <img src="https://huggingface.co/Benjamin-png/swahili-gpt-71m-instruct/resolve/main/swahili_banner.png" alt="swahili-gpt-71m-instruct" width="820"> </p>

swahili-gpt-71m-instruct

An instruction-tuned Swahili model — `Benjamin-png/swahili-gpt-71m` (71M, trained from scratch) fine-tuned (SFT) to follow instructions and answer questions in Kiswahili, instead of just completing text.

![Open In Colab](https://colab.research.google.com/drive/1R00lE1vjbiHRXdqZqUeyKGAo8E6KZcjY?usp=sharing) — chat with it in your browser, no setup.

✅ Final checkpoint — SFT complete (3 epochs, 7,989 steps). It follows the instruction format and answers in Swahili, but as a 71M model it has limited knowledge and can be repetitive or wrong. Treat it as a proof-of-concept, not a finished assistant.

Prompt format

The model was fine-tuned on this exact template — use it for best results:

### Maagizo:
{your instruction or question}
### Jibu:

(Optionally add ### Ingizo:\n{context}\n between them when you have extra context.) The model generates the answer after ### Jibu: and stops at </s>.

Usage

bash
pip install torch sentencepiece huggingface_hub
python
from huggingface_hub import hf_hub_download
import sentencepiece as spm

REPO = "Benjamin-png/swahili-gpt-71m-instruct"
hf_hub_download(REPO, "modeling_kiswahili.py", local_dir=".")
from modeling_kiswahili import load_model, generate

weights = hf_hub_download(REPO, "pytorch_model.pt")
hf_hub_download(REPO, "model_config.json")
tok = hf_hub_download(REPO, "swahili_tokenizer.model")

model, cfg = load_model(weights, device="cpu")     # or "cuda"
sp = spm.SentencePieceProcessor(); sp.load(tok)

def ask(q):
    prompt = f"### Maagizo:\n{q}\n### Jibu:\n"
    out = generate(model, sp, prompt, device="cpu", max_new_tokens=120)
    return out.split("### Jibu:")[-1].split("### Maagizo:")[0].strip()

print(ask("Eleza umuhimu wa elimu kwa jamii."))

Or run the included inference.py.

Training

  • —Base: Benjamin-png/swahili-gpt-71m (decoder-only Transformer, 12 layers, 8 heads, hidden 512, 32k SentencePiece vocab).
  • —Method: supervised fine-tuning (SFT) with loss masked to the response (the prompt is context only), gradient checkpointing, cosine LR (peak 2e-5).
  • —Data: `Benjamin-png/swahili-instruction-mix` — ~85k examples.

Loss trajectory

SFT loss (computed on response tokens only) over fine-tuning steps:

<p align="center"> <img src="https://huggingface.co/Benjamin-png/swahili-gpt-71m-instruct/resolve/main/loss_curve.png" alt="SFT loss trajectory" width="760"> </p>

StepVal lossPerplexity
5004.05~57
10003.79~44
20003.57~36
30003.47~32
40003.41~30
50003.37~29
60003.34~28
70003.33~28
75003.33~28

Val loss fell steadily across the full 3-epoch run (~85k examples/epoch) and flattened to 3.33 at this 71M model's capacity. This is the final checkpoint; training is complete.

Data sources & attribution

The instruction data is a blend of open Swahili datasets — full credit to:

License

CC BY-NC-4.0 (non-commercial) — inherited from Bactrian-X in the training mix. Please keep attribution and respect the non-commercial terms.

Limitations

71M parameters: little world knowledge, no reliable facts or reasoning, may repeat or hallucinate. Early SFT checkpoint. Not for production or any high-stakes use. Built as an open, from-scratch step toward Swahili-first AI.