sae-arabic
Open-source toolkit for training and causally validating Sparse Autoencoder (SAE) features in Arabic LLMs, using dialectness (ALDi) as external ground truth.
Status
v0.1.0 — complete, tested, and released. Phases 1-3 (pipeline, SAE
training, causal validation) are implemented and verified with 29 offline
tests plus a full real-MARBERT run on Colab. ALDi scoring auto-loads the
public AMR-KELEG/Sentence-ALDi model (override with the ALDI_MODEL env var)
and optionally averages the three published seeds (--seed-average).
Final metrics — including the honest causal null result — are in RESULTS.md.
Package layout
| Module | Purpose | Phase |
|---|---|---|
sae_arabic/sae.py |
Custom linear SAE (encoder/decoder, MSE + L1), training loop, checkpoints | 2 |
sae_arabic/activations.py |
MARBERT activation extraction and disk serialization | 1 |
sae_arabic/data.py |
Arabic preprocessing, tokenization, dataset loading | 1 |
sae_arabic/analysis.py |
Top-feature extraction and context browsing | 3 |
sae_arabic/aldi.py |
ALDi scoring (Sentence-ALDi, seed-ensembled) + causal MLM-head scrub + correlation | 3 |
scripts/train_real.py |
Real-data entrypoint: dataset -> MARBERT activations -> SAE training | 1-2 |
scripts/evaluate.py |
Evaluate a checkpoint: explained variance, dead rate, feature stats | 2-3 |
scripts/layer_sweep.py |
Time-boxed layer selection ranked by explained variance | 2 |
scripts/causal_validate.py |
Causal scrub: control-relative effects + bootstrap 95% CIs | 3 |
scripts/end_to_end_dry_run.py |
Offline wiring smoke test (tiny BERT) | 1-3 |
notebooks/train_on_colab.ipynb |
Ready-to-upload Colab GPU notebook (train + evaluate + sweep + causal) | 1-3 |
Install
pip install -e ".[dev]"
Quickstart
Offline dry run (no network, tiny random BERT):
python -m scripts.end_to_end_dry_run
Real pipeline (MARBERT + dialect data, on a Colab GPU):
- Upload
notebooks/train_on_colab.ipynb(needs anHF_TOKENsecret). data.pyloads + normalizes the dataset.activations.pyextracts MARBERT layer activations and writes shards.sae.pytrains the SAE (training_config.yaml) and writes checkpoints +report.json.aldi.pyruns the causal MLM-head scrub withAMR-KELEG/Sentence-ALDi.
Locally (small run): python scripts/train_real.py --num-samples 100 --num-steps 1000
Evaluate a checkpoint: python scripts/evaluate.py --checkpoint data/real_run/checkpoints/final.pt --activations-dir data/real_run/activations
Pick the target layer: python -m scripts.layer_sweep --layers 4 6 8 --num-samples 200 --num-steps 2000 --out-dir data/sweep
Run causal validation: python -m scripts.causal_validate --checkpoint data/sweep/layer8.pt --layer 8 --num-features 5 --seed-average
Known limitations
- Sentence-ALDi calibration: scores on short/colloquial text are compressed and do not reliably order MSA < dialectal (see RESULTS.md).
- Causal scrub is null: hidden-state interventions shift ALDi uniformly (~−0.04) regardless of the feature, so feature-specific effects are not detectable; reconstruction artifacts act as a confound.
Citation
@software{sae_arabic,
title = {sae-arabic: Sparse Autoencoder toolkit for Arabic LLM interpretability},
author = {Yousef Al-Halabi},
year = {2026},
url = {https://github.com/Yousef13133/sae-arabic},
note = {DOI: 10.5281/zenodo.21848168},
}
License
MIT — see LICENSE.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sae_arabic-0.1.0.tar.gz.
File metadata
- Download URL: sae_arabic-0.1.0.tar.gz
- Upload date:
- Size: 18.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b6110e33f2ef292f647612079eb4c65c720199825d2135130ed2e04751a0e6df
|
|
| MD5 |
9483a7de0ba9f4d3bc6754cffdeac277
|
|
| BLAKE2b-256 |
78f82788f58a0283ff59cc7a2e332f6d5437fa3b40540ed3c4e9c34548c356eb
|
File details
Details for the file sae_arabic-0.1.0-py3-none-any.whl.
File metadata
- Download URL: sae_arabic-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
60d238ef818e5f4244490fa7d7ef821bb4673b870da825c753e1e7fc4084fce6
|
|
| MD5 |
3ce97d834fcd33bf196f356397c7881c
|
|
| BLAKE2b-256 |
0037da006464fa32e730fed8d676bfae46b498a7c25ecb6855a624f90f396bdf
|