# zelinzhu-richard/scai-duke-2026 architecture

> Architecture diagram of the GitHub repository zelinzhu-richard/scai-duke-2026, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-02-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/zelinzhu-richard/scai-duke-2026
- Repository: https://github.com/zelinzhu-richard/scai-duke-2026

## Overview

##### What this project is (type + purpose)
This repo is an **offline, batch-style benchmarking pipeline** (not a deployed service) that measures **ASR equity** for customer-support-like calls across **accent / native vs ESL groups**. It ingests speech samples (Mozilla Common Voice or similar), requires a **manual ground-truth labeling step**, runs **Whisper transcription**, performs **intent classification (before/after normalization)**, then computes **equity metrics** (CER, disparity index) and generates **plots + a demo notebook**.

##### What the file tree says about architecture
Top-level structure strongly indicates a **script-driven pipeline**:

- `scripts/organize_mozilla_cv.py` → data ingestion / sampling / balancing into `data/audio/`, creates a ground truth template.
- `data/ground_truth.csv` (and `ground_truth_template.csv` created by scripts) → **human-labeled source of truth**.
- `scripts/run_whisper.py` → ASR batch job producing `results/transcripts.csv`.
- `scripts/classify_intent.py` → intent labeling and evaluation producing `results/intents.csv` (includes “before/after normalization” concept from README).
- `scripts/calculate_metrics.py` → computes CER + disparity + failure examples into `results/metrics.json`.
- `demo/demo_notebook_template.py` → presentation layer consuming outputs for interactive review.
- `scripts/_python_version_check.py` → explicit runtime constraint enforcement (Python 3.12.12).
- `requirements.txt` → core runtime deps (PyTorch, Transformers, pandas, etc.).
- `data/ground_truth.csv` in repo indicates a “checked-in example” dataset.

Architecturally: this is a **linear pipeline with checkpoints (files)**, plus **one manual intervention step** (ground truth authoring).

Goal: show what’s *outside* vs *inside* the repo.

**External entities to include**
- **Mozilla Common Voice dataset (local download)**: audio files + metadata TSV/CSV.
- **Human annotator**: creates/edits `data/ground_truth.csv`.
- **OpenAI Whisper model weights** (downloaded/cached) + **ffmpeg** (audio decoding).
- Optional: **Hugging Face models** (if zero-shot intent classification is used).

**Inside-system**
- “Benchmark Pipeline (Python scripts)” producing results + visuals.

- Common Voice → `organize_mozilla_cv.py` → `data/audio/*`
- Human annotator ↔ `data/ground_truth.csv`
- `data/audio/*` → Whisper → `results/transcripts.csv`
- transcripts + ground_truth → intent classifier → `results/intents.csv`
- intents → metrics → `results/metrics.json`
- intents/metrics → visualization → `visualizations/*.png`
- all outputs → demo notebook

##### Level 1: Container / Dataflow DAG (most important for this project)

**Recommended nodes (map 1:1 to repo)**
##### Data Ingestion & Sampling
- `scripts/organize_mozilla_cv.py`
- Inputs: `cv_dir`, metadata CSV/TSV (optional)
- Outputs:
- `data/audio/` (directory of selected wav files)
- `data/ground_truth_template.csv` (implied by README)
##### Ground Truth Authoring (Manual Step)
- Human edits `data/ground_truth.csv`
##### ASR Transcription
- `scripts/run_whisper.py`
- Dependencies: `whisper`, `torch`, `ffmpeg`
- Output: `results/transcripts.csv`
##### Intent Classification + Before/After Normalization
- `scripts/classify_intent.py`
- Inputs: `results/transcripts.csv`, `data/ground_truth.csv`
- Output: `results/intents.csv`
- Make “Before normalization” and “After normalization” explicit as two sub-steps or two labeled outputs/columns (since the README emphasizes this comparison).
##### Metrics Computation
- `scripts/calculate_metrics.py`
- Output: `results/metrics.json`
- Includes: CER by accent, disparity index vs baseline, failure examples
##### Visualization
- Output: `visualizations/*.png`
##### Demo / Reporting
- `demo/demo_notebook_template.py` consumes results/visualizations

- `data/audio/` (filesystem)
- `data/ground_truth.csv`
- `results/transcripts.csv`
- `results/intents.csv`
- `results/metrics.json`
- `visualizations/` (PNGs)

**Important flows to label**
- “Audio (wav)” vs “Metadata (accent labels, transcripts)” vs “Predictions” vs “Metrics”
- Accent grouping logic (from README: default accent tokens in `organize_mozilla_cv.py`)
- Baseline selection (`--baseline US` in metrics/visualization scripts)

This DAG is the “truth” of how the repo works.

This repo’s core value is the benchmark logic, so zoom into two internals:

##### ASR stage internals (`run_whisper.py`)
Show:
- Audio loader/decoder → ffmpeg
- Whisper inference (model selection: tiny/base) → transcript text + metadata (language, timing)
- CSV writer

##### Metrics stage internals (`calculate_metrics.py` + classifier)
Show:
- Join step: transcripts ↔ ground_truth by `filename`
- CER computation (string distance) per sample → aggregate by accent_group
- Intent accuracy computation per accent_group
- Disparity index computation relative to baseline group
- Failure example selection (top-N worst / illustrative)

##### All modules communicate via files (CSV/JSON/PNG), not in-memory APIs
- That’s the architectural style: “pipeline with persisted checkpoints”.
##### Accent grouping is determined during ingestion and/or ground-truth
- The benchmark depends on consistent `accent_group` naming between `organize_mozilla_cv.py` and `ground_truth.csv`.
##### Runtime constraints are part of architecture
- Python 3.12.12 requirement (`scripts/_python_version_check.py`) and ffmpeg dependency should appear as environment prerequisites.

- **Python 3.12.12** runtime (global)
- **PyTorch** (Whisper inference)
- **OpenAI Whisper** model (ASR node)
- **ffmpeg** (audio decoding dependency for Whisper)
- **Transformers (HF)** (if using zero-shot/BART; classifier node)
- **pandas/numpy** (data join + aggregation; metrics node)
- **matplotlib/seaborn** (visualization node)
- Input dataset: **Mozilla Common Voice** (external)

- **Rectangles (blue)**: compute steps (scripts)
- **Cloud (purple)**: external systems (Common Voice source, model hubs)

##### “As many components as possible” (but still coherent)

- Split “Intent Classification” into:
- Transcript normalization (before/after)
- Keyword classifier OR Zero-shot classifier (two subcomponents)
- Accuracy computation (overall + by accent)
- Split “Visualization” into:
- CER chart
- Intent error chart
- Disparity heatmap
- Dashboard composite

##### Slide 3: Metrics + disparity computation detail (joins, group-by, baseline)
4. **Slide 4: Extension points** (optional `prepare_data.py`, additional ASR models, new accent groups, noise simulation)

That set will be both accurate to the repo and maximally useful for future extension.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% =========================
    %% Level 0: Context (Offline)
    %% =========================
    subgraph L0["Level 0 — Context (Offline batch benchmarking; file-based checkpoints)"]
        direction TB

        CV[("Mozilla Common Voice\n(local download: audio + metadata)")]:::external
        HF[("Model hubs / downloads\n(Whisper weights; optional HF intent models)")]:::external
        FFMPEG[("ffmpeg\n(audio decode)")]:::external

        Human["Human annotator\n(manual ground-truth labeling)"]:::human

        subgraph REPO_SUB["Benchmark Pipeline (this repo)"]
            direction TB
            Repo["Python scripts pipeline\n(not a deployed service)"]:::repo
        end

        OutResults[("Outputs\n(CSV/JSON/PNG + demo notebook)")]:::datastore
    end

    CV -->|audio+metadata| Repo
    HF -.->|model_weights| Repo
    FFMPEG -->|decode_support| Repo
    Human <--> |labeling_feedback| Repo
    Repo -->|benchmark_artifacts| OutResults

    %% =========================
    %% Level 1: Main Pipeline DAG
    %% =========================
    subgraph L1["Level 1 — Pipeline DAG (scripts + persisted artifacts)"]
        direction TB

        subgraph ENV["Environment prerequisites"]
            direction TB
            PY["Python 3.12.12 runtime"]:::env
            VCHECK["Runtime version check\nscripts/_python_version_check.py"]:::script
            REQ["Dependencies\n(requirements.txt)"]:::file
        end

        PY -->|enforced_by| VCHECK
        REQ -->|installs| PY

        subgraph ST1["Stage 1 — Ingestion & Sampling"]
            direction TB
            ORG["organize_mozilla_cv.py\n(sample/balance; accent grouping)"]:::script
            PREP["prepare_data.py\n(optional preprocessing)"]:::scriptOptional
            DATASTORE[("data/\n(selected audio + metadata)")]:::datastore
            AUDIO[("data/audio/\n(wav files)")]:::datastore
            GT_TEMPLATE[("data/ground_truth_template.csv")]:::datastore
        end

        subgraph ST2["Stage 2 — Ground Truth (Manual gate)"]
            direction TB
            GT[("data/ground_truth.csv\n(human-labeled truth)")]:::datastore
            ANNO["Manual labeling step\n(accent_group, intent, etc.)"]:::human
        end

        subgraph ST3["Stage 3 — ASR Transcription"]
            direction TB
            WHISPER["run_whisper.py\n(OpenAI Whisper + torch)"]:::script
            MODEL_CACHE[("Local model cache\n(Whisper weights)")]:::datastore
            TRANSCRIPTS[("results/transcripts.csv")]:::datastore
        end

        subgraph ST4["Stage 4 — Intent classification (before/after normalization)"]
            direction TB
            CLASSIFY["classify_intent.py\n(Transformers optional)"]:::script
            NORM_BEFORE["Before normalization\n(intent inference)"]:::compute
            NORM_AFTER["After normalization\n(intent inference)"]:::compute
            INTENTS[("results/intents.csv\n(before/after columns)")]:::datastore
        end

        subgraph ST5["Stage 5 — Metrics (Equity computation)"]
            direction TB
            METRICS["calculate_metrics.py\n(pandas/numpy; CER + disparity)"]:::script
            JOIN["Join by filename\n(transcripts <-> ground_truth)"]:::compute
            CER["CER computation\n(per sample -> by accent_group)"]:::compute
            ACC["Intent accuracy\n(by accent_group)"]:::compute
            DISP["Disparity index\n(vs baseline, e.g. US)"]:::compute
            FAILS["Failure examples\n(top-N/worst cases)"]:::compute
            METRICS_JSON[("results/metrics.json")]:::datastore
        end

        subgraph ST6["Stage 6 — Visualization (Plots)"]
            direction TB
            VIZ["visualize.py\n(matplotlib/seaborn)"]:::script
            PNGS[("visualizations/\n*.png")]:::datastore
            CER_PLOT["CER charts"]:::plot
            INT_PLOT["Intent error charts\n(before/after)"]:::plot
            DISP_PLOT["Disparity heatmap / summary"]:::plot
        end

        subgraph ST7["Stage 7 — Demo / Reporting"]
            direction TB
            NOTEBOOK["demo_notebook_template.py\n(interactive review)"]:::notebook
            README["README.md"]:::docs
            QUICKSTART["QUICKSTART.md"]:::docs
        end
    end

    %% Pipeline flows (file checkpoints)
    VCHECK -->|gate_runs| ORG

    CV -->|cv_dir audio+metadata| ORG
    ORG -->|selected_audio| AUDIO
    ORG -->|project_data| DATASTORE
    ORG -->|ground_truth_template| GT_TEMPLATE
    ORG -.->|optional_preprocess_input| PREP
    PREP -.->|processed_audio| AUDIO

    GT_TEMPLATE -->|to_label| ANNO
    ANNO -->|edited_labels| GT

    AUDIO -->|audio_wav| WHISPER
    FFMPEG -->|decode_audio| WHISPER
    HF -.->|download_whisper_weights| MODEL_CACHE
    MODEL_CACHE -->|weights| WHISPER
    WHISPER -->|transcripts| TRANSCRIPTS

    TRANSCRIPTS -->|transcript_text| CLASSIFY
    GT -->|intent+accent_group labels| CLASSIFY
    HF -.->|optional_intent_model| CLASSIFY
    CLASSIFY -->|inputs| NORM_BEFORE
    CLASSIFY -->|inputs| NORM_AFTER
    NORM_BEFORE -->|intent_preds_before| INTENTS
    NORM_AFTER -->|intent_preds_after| INTENTS

    TRANSCRIPTS -->|for_join| JOIN
    GT -->|for_join| JOIN
    JOIN -->|aligned_rows| CER
    JOIN -->|aligned_rows| ACC
    CER -->|cer_by_group| DISP
    ACC -->|acc_by_group| DISP
    DISP -->|disparity_metrics| FAILS
    FAILS -->|metrics_bundle| METRICS_JSON
    CER -->|metrics_bundle| METRICS_JSON
    ACC -->|metrics_bundle| METRICS_JSON

    INTENTS -->|plot_inputs| VIZ
    METRICS_JSON -->|plot_inputs| VIZ
    VIZ -->|pngs| PNGS
    VIZ -->|cer_figures| CER_PLOT
    VIZ -->|intent_figures| INT_PLOT
    VIZ -->|disparity_figures| DISP_PLOT
    CER_PLOT -->|written_to| PNGS
    INT_PLOT -->|written_to| PNGS
    DISP_PLOT -->|written_to| PNGS

    TRANSCRIPTS -->|review| NOTEBOOK
    INTENTS -->|review| NOTEBOOK
    METRICS_JSON -->|review| NOTEBOOK
    PNGS -->|embed| NOTEBOOK

    README -->|usage_guide| ORG
    QUICKSTART -->|execution_steps| WHISPER
    QUICKSTART -->|execution_steps| CLASSIFY
    QUICKSTART -->|execution_steps| METRICS
    QUICKSTART -->|execution_steps| VIZ

    %% =========================
    %% Click events (from mapping)
    %% =========================
    click ORG "https://github.com/zelinzhu-richard/scai-duke-2026/blob/main/scripts/organize_mozilla_cv.py"
    click PREP "https://github.com/zelinzhu-richard/scai-duke-2026/blob/main/scripts/prepare_data.py"
    click DATASTORE "https://github.com/zelinzhu-richard/scai-duke-2026/tree/main/data/"
    click GT "https://github.com/zelinzhu-richard/scai-duke-2026/blob/main/data/ground_truth.csv"
    click WHISPER "https://github.com/zelinzhu-richard/scai-duke-2026/blob/main/scripts/run_whisper.py"
    click CLASSIFY "https://github.com/zelinzhu-richard/scai-duke-2026/blob/main/scripts/classify_intent.py"
    click METRICS "https://github.com/zelinzhu-richard/scai-duke-2026/blob/main/scripts/calculate_metrics.py"
    click VIZ "https://github.com/zelinzhu-richard/scai-duke-2026/blob/main/scripts/visualize.py"
    click NOTEBOOK "https://github.com/zelinzhu-richard/scai-duke-2026/blob/main/demo/demo_notebook_template.py"
    click VCHECK "https://github.com/zelinzhu-richard/scai-duke-2026/blob/main/scripts/_python_version_check.py"
    click REQ "https://github.com/zelinzhu-richard/scai-duke-2026/blob/main/requirements.txt"
    click README "https://github.com/zelinzhu-richard/scai-duke-2026/blob/main/README.md"
    click QUICKSTART "https://github.com/zelinzhu-richard/scai-duke-2026/blob/main/QUICKSTART.md"

    %% =========================
    %% Styles (color required)
    %% =========================
    classDef script fill:#1f77b4,stroke:#0b3d66,stroke-width:1.5px,color:#ffffff
    classDef scriptOptional fill:#4aa3df,stroke:#0b3d66,stroke-width:1.5px,color:#ffffff,stroke-dasharray: 5 4
    classDef compute fill:#2b8cbe,stroke:#0b3d66,stroke-width:1.2px,color:#ffffff
    classDef datastore fill:#e5e7eb,stroke:#6b7280,stroke-width:1.2px,color:#111827
    classDef external fill:#7c3aed,stroke:#4c1d95,stroke-width:1.5px,color:#ffffff
    classDef human fill:#f59e0b,stroke:#92400e,stroke-width:1.5px,color:#111827
    classDef env fill:#10b981,stroke:#065f46,stroke-width:1.5px,color:#052e1b
    classDef plot fill:#f472b6,stroke:#9d174d,stroke-width:1.2px,color:#111827
    classDef notebook fill:#a78bfa,stroke:#5b21b6,stroke-width:1.5px,color:#111827
    classDef docs fill:#fca5a5,stroke:#991b1b,stroke-width:1.5px,color:#111827
    classDef file fill:#c7d2fe,stroke:#3730a3,stroke-width:1.5px,color:#111827
    classDef repo fill:#111827,stroke:#334155,stroke-width:1.5px,color:#ffffff
```
