snygginghani/ammani-dialect-detector
Ammani Dialect Confidence Scorer
Given any Arabic sentence, returns a 0–100 % confidence score of how closely it matches the Ammani dialect training corpus, plus a sentiment prediction (positive / neutral / negative).
Embeddings use [GATE-AraBert-v1](https://huggingface.co/Omartificial-Intelligence-Space/GATE-AraBert-v1) — an Arabic-specific, dialect-aware embedding model that outperforms OpenAI embeddings by 20–25 % on Arabic semantic-similarity benchmarks. It runs locally (no API key, no rate limits, free).
Setup
pip install -r requirements.txtNo API key needed — the model downloads automatically from Hugging Face on first run (~500 MB).
Step 1 – Embed & calibrate
python embed_and_train.pyThis will:
- Load
cleanedDataset.csv(Ammani sentences) - Normalise Arabic text (remove diacritics + tatweel; the transformer handles morphology)
- Embed all sentences with
GATE-AraBert-v1(768 dims, batched, local GPU/CPU) - Cache embeddings to
cache/so re-runs are instant - Calibrate a cosine-similarity threshold on the held-out validation split
- Save model artefacts to
models/and evaluation plots tostatic/plots/
First run downloads the model (~500 MB) then embeds locally in ~1–2 min on CPU. Subsequent runs skip embedding entirely (cache hit).
Step 2 – Run the web app
python app.pyOpen http://localhost:5000 in your browser.
How it works
Output files
cache/
embeddings_<hash>.npy ← all sentence embeddings (cached)
train_embeddings.npy ← training split only (for nearest-neighbour)
train_texts.json ← matching text strings
models/
threshold.json ← calibrated threshold + distribution stats
static/plots/
score_distribution.png
score_cdf.png
score_percentiles.png