CoolFace
Apppublic

snygginghani/ammani-dialect-detector

sourceHugging Faceupdated 4mo agoView on Hugging Face
0likes
App README

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

bash
pip install -r requirements.txt

No API key needed — the model downloads automatically from Hugging Face on first run (~500 MB).

Step 1 – Embed & calibrate

bash
python embed_and_train.py

This will:

  1. 1.Load cleanedDataset.csv (Ammani sentences)
  2. 2.Normalise Arabic text (remove diacritics + tatweel; the transformer handles morphology)
  3. 3.Embed all sentences with GATE-AraBert-v1 (768 dims, batched, local GPU/CPU)
  4. 4.Cache embeddings to cache/ so re-runs are instant
  5. 5.Calibrate a cosine-similarity threshold on the held-out validation split
  6. 6.Save model artefacts to models/ and evaluation plots to static/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

bash
python app.py

Open http://localhost:5000 in your browser.

How it works

StageDetail
EmbeddingGATE-AraBert-v1 (768 dims, Arabic-specific, dialect-aware)
SimilarityMean cosine similarity of top-10 nearest training vectors
Threshold5th percentile of within-corpus validation scores
ConfidenceNormalised score mapped to 0–100 %

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