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.
Metadata
Release files for sae-arabic 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sae_arabic-0.1.0.tar.gz | 18.4 kB | Without provenance | Details for sae_arabic-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sae_arabic-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for sae_arabic-0.1.0-py3-none-any.whl |
Total release size: 33.3 kB
Release files / sae_arabic-0.1.0.tar.gz
| Download URL | sae_arabic-0.1.0.tar.gz |
|---|---|
| Size | 18.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b6110e33f2ef292f647612079eb4c65c720199825d2135130ed2e04751a0e6df
|
|
BLAKE2b-256 checksum How to use checksums |
78f82788f58a0283ff59cc7a2e332f6d5437fa3b40540ed3c4e9c34548c356eb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / sae_arabic-0.1.0-py3-none-any.whl
| Download URL | sae_arabic-0.1.0-py3-none-any.whl |
|---|---|
| Size | 14.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
60d238ef818e5f4244490fa7d7ef821bb4673b870da825c753e1e7fc4084fce6
|
|
BLAKE2b-256 checksum How to use checksums |
0037da006464fa32e730fed8d676bfae46b498a7c25ecb6855a624f90f396bdf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Security for sae-arabic 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.