A from-scratch implementation of a Mamba State Space Model (SSM) trained to speak Algerian Darija the colloquial Arabic dialect of Algeria, written in both Arabic script and Franco-Arab (Latin + numbers). Built with pure PyTorch. No Transformers. No attention. Just selective state spaces.
# Tiny Mamba for Algerian Darija π©πΏ
A from-scratch implementation of a **Mamba State Space Model (SSM)** trained to speak **Algerian Darija** β the colloquial Arabic dialect of Algeria, written in both Arabic script and Franco-Arab (Latin + numbers).
Built with pure PyTorch. No Transformers. No attention. Just selective state spaces.
> **"ΨͺΨΉΨ¬Ψ¨ΩΩ ΩΨ°ΩΩ Ψ§ΩΩΩΨ·Ψ© ΩΩ ΩΩΨͺ Ω Ψ§ΩΩ
Ψ±ΩΩΨ§Ω . Ω Ψ§ΩΩΩ ΨΊΩΨ± ΩΨΉΨ·ΩΩ Ψ§ΩΨ΅ΨΨ© Ψ¨Ψ§ΩΨͺΩΩΩΩ"**
---
## π Features
- **Pure PyTorch Mamba** β no `mamba-ssm` CUDA kernels required
- **Custom BPE Tokenizer** trained on real Algerian social media text
- **Mixed-script support** β handles Arabic script (`Ψ΄ΨΨ§Ω`) and Franco-Arab (`3andek`)
- **RTX 3060 Ti optimized** β trains on 8GB VRAM
- **Repetition penalty + top-k sampling** for clean generation
- **Resume training** from checkpoints automatically
---
## π Project Structure
.
βββ darija_preprocessed.txt # Cleaned training corpus (not in repo, too big)
βββ darija_tokenizer/ # Trained BPE tokenizer
β βββ tokenizer.json
β βββ vocab.txt
β βββ special_tokens.txt
βββ checkpoints/ # Saved model checkpoints (not in repo, too big)
β βββ final_model.pt
βββ darja_processing.py # Step 1: Clean raw text
βββ train_tokenizer.py # Step 2: Train BPE tokenizer
βββ mamba_darija.py # Step 3: Train Mamba model (pure PyTorch)
βββ infernce.py # Step 4: Generate text
βββ requirements.txt
βββ README.md
---
## π οΈ Installation
```bash
git clone
github.com
cd tiny-mamba-darija
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
## π Dataset
Uses the Algerian-Darija dataset by Ayoub Kirouane.
23 MB of raw Algerian social media text
Preprocessed to remove HTML, emojis, URLs, mentions, and duplicate characters
ποΈ# Training from Scratch
Step 1: Download & Preprocess
python darja_processing.py
Downloads from HuggingFace and cleans the text.
Output: darija_preprocess β¦