# zzh13592365333/speaker architecture

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

- Interactive diagram: https://gitdiagram.com/zzh13592365333/speaker
- Repository: https://github.com/zzh13592365333/speaker

## Overview

1. **Repository purpose**
   This repo is a research training template for **reliability-aware visual Emotion Recognition in Conversation (ERC)** on **MELD** and **IEMOCAP**. It is structured around an **offline feature-extraction stage** and a **PyTorch training stage** rather than end-to-end raw multimodal training.

2. **Top-level architecture**
   The codebase is split into four main areas:
   - `feature_tools/` for generating modality features from raw datasets,
   - `erc/` for dataset loading, model definition, loss, and utilities,
   - `train.py` as the training entry point,
   - `configs/` and `scripts/` for dataset-specific runtime setup.

3. **Stage 1: feature generation boundary**
   All raw audio/video/text processing happens outside the training loop. The repository expects precomputed `.pkl` feature files for each split, with standardized names like `text_train.pkl`, `audio_val.pkl`, and `video_test_aligned.pkl`. This is the key architecture boundary: **raw dataset ingestion is separated from classifier training**.

4. **Feature extraction pipeline**
   The `feature_tools/` directory contains modality-specific preprocessing:
   - `extract_text_emoberta_features.py` builds utterance-level text embeddings from current/past/future context.
   - `extract_emotion2vec_meld.py` generates audio features for MELD.
   - `extract_audio_descriptions.py` supports audio-language descriptions used as semantic guidance.
   - `extract_vlm_embeddings_template.py` defines the VLM-based visual feature extraction flow.
   - `preprocess_vad.py` prepares valence-arousal-dominance priors used as lexical guidance.
   
   This stage produces the fixed-dimensional inputs consumed by training.

5. **Modality contracts**
   The downstream classifier assumes a strict modality interface:
   - **Text:** 1024-D utterance embeddings,
   - **Audio:** 1024-D frame-level sequence, typically padded/truncated to 300 frames,
   - **Video:** 4096-D global VLM embedding.
   
   These dimensions matter because the model projects all modalities into a shared hidden space before fusion.

6. **Stage 2: ERC model architecture**
   The main model logic lives in `erc/model.py`. The readme describes a **reliability-aware complementation** design:
   - each modality is projected into a 512-D hidden space,
   - the model applies **past-only conversational context**,
   - **video acts as the query** to retrieve supportive text/audio references,
   - a **confidence-gated residual** updates the visual representation with cross-modal evidence.
   
   This makes the visual stream the central anchor, with text/audio used to complement or correct uncertain visual cues.

7. **Dataset loading and split management**
   `erc/datasets.py` is the data boundary for training. It reads the pre-extracted pickle files, aligns them with labels and utterance IDs, and exposes the MELD/IEMOCAP splits expected by `train.py`. The repo standardizes split names to `train`, `val`, and `test`; for MELD, the official `dev` split is mapped to `val`.

8. **Loss and optimization**
   `erc/loss.py` contains the training objective, including the main classification loss and the auxiliary term controlled by `--aux_loss_weight`. The CLI examples in the README show that training is tuned with dataset-specific learning rates, dropout, epoch counts, and auxiliary weighting.

9. **Training entry point and runtime configuration**
   `train.py` is the orchestration layer that ties together config loading, dataset creation, model instantiation, optimization, and evaluation. The JSON files in `configs/` hold local path settings, while CLI arguments control GPU selection and hyperparameters. The repo intentionally keeps local paths out of source control.

10. **Execution helpers and reproducibility**
    `scripts/run_meld.sh` and `scripts/run_iemocap.sh` provide dataset-specific launch wrappers. `requirements.txt` captures the Python dependency set. `RELEASE_CHECKLIST.md` reinforces the repo’s release-safe design by calling out privacy checks, path sanitization, and the exclusion of raw media, checkpoints, logs, and generated predictions.

11. **Data flow summary**
    The end-to-end flow is:
    raw MELD/IEMOCAP data → modality-specific feature extraction in `feature_tools/` → serialized per-split feature files → `erc/datasets.py` loads aligned features/labels → `erc/model.py` fuses modalities and context → `erc/loss.py` trains the classifier through `train.py`.

12. **Important architectural constraints**
    This repo is not a generic multimodal app; it is a **research pipeline with offline preprocessing** and a **fixed feature schema**. Any architecture diagram should show:
    - the raw dataset boundary,
    - separate text/audio/video feature extraction paths,
    - a shared training service consuming precomputed features,
    - and the final ERC classifier with visual-centered cross-modal complementation.

Main entry points: [`train.py`](https://github.com/zzh13592365333/speaker/blob/main/train.py) (Train), [`erc/datasets.py`](https://github.com/zzh13592365333/speaker/blob/main/erc/datasets.py) (Dataset loader), [`feature_tools/extract_text_emoberta_features.py`](https://github.com/zzh13592365333/speaker/blob/main/feature_tools/extract_text_emoberta_features.py) (Text extractor), [`feature_tools/extract_emotion2vec_meld.py`](https://github.com/zzh13592365333/speaker/blob/main/feature_tools/extract_emotion2vec_meld.py) (Audio extractor)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_feature_tools["Feature tools"]
  node_vad_priors["VAD priors<br/>lexical guidance<br/>[preprocess_vad.py]"]
  node_text_extractor["Text extractor<br/>feature tool"]
  node_audio_extractor["Audio extractor<br/>feature tool"]
  node_audio_desc["Audio descriptions<br/>feature tool"]
  node_vlm_extractor["VLM extractor<br/>feature tool"]
end

subgraph group_group_erc["ERC training"]
  node_datasets["Dataset loader<br/>split adapter<br/>[datasets.py]"]
  node_model["ERC model<br/>reliability-aware model<br/>[model.py]"]
  node_loss["Loss<br/>objective<br/>[loss.py]"]
  node_utils["Utilities<br/>training helpers<br/>[utils.py]"]
end

subgraph group_group_runtime["Runtime"]
  node_train_entry["Train<br/>orchestrator<br/>[train.py]"]
  node_meld_config["MELD config<br/>runtime config<br/>[meld.example.json]"]
  node_iemocap_config["IEMOCAP config<br/>runtime config"]
  node_meld_script["MELD script<br/>launch wrapper<br/>[run_meld.sh]"]
  node_iemocap_script["IEMOCAP script<br/>launch wrapper<br/>[run_iemocap.sh]"]
end

node_raw_data[("Raw data<br/>dataset boundary")]
node_text_features["Text features<br/>pickle features"]
node_audio_features["Audio features<br/>pickle features"]
node_video_features["Video features<br/>pickle features"]

node_raw_data -->|"text source"| node_text_extractor
node_raw_data -->|"audio source"| node_audio_extractor
node_raw_data -->|"audio source"| node_audio_desc
node_raw_data -->|"video source"| node_vlm_extractor
node_raw_data -->|"lexical cues"| node_vad_priors
node_text_extractor -->|"write"| node_text_features
node_audio_extractor -->|"write"| node_audio_features
node_vlm_extractor -->|"write"| node_video_features
node_vad_priors -.->|"guide"| node_text_extractor
node_audio_desc -.->|"guide"| node_audio_extractor
node_text_features -->|"load"| node_datasets
node_audio_features -->|"load"| node_datasets
node_video_features -->|"load"| node_datasets
node_datasets -->|"batches"| node_model
node_model -->|"logits"| node_loss
node_train_entry -->|"build"| node_datasets
node_train_entry -->|"instantiate"| node_model
node_train_entry -->|"optimize"| node_loss
node_train_entry -->|"support"| node_utils
node_meld_config -->|"configure"| node_train_entry
node_iemocap_config -->|"configure"| node_train_entry
node_meld_script -->|"launch"| node_meld_config
node_iemocap_script -->|"launch"| node_iemocap_config

click node_vad_priors "https://github.com/zzh13592365333/speaker/blob/main/feature_tools/preprocess_vad.py"
click node_text_extractor "https://github.com/zzh13592365333/speaker/blob/main/feature_tools/extract_text_emoberta_features.py"
click node_audio_extractor "https://github.com/zzh13592365333/speaker/blob/main/feature_tools/extract_emotion2vec_meld.py"
click node_audio_desc "https://github.com/zzh13592365333/speaker/blob/main/feature_tools/extract_audio_descriptions.py"
click node_vlm_extractor "https://github.com/zzh13592365333/speaker/blob/main/feature_tools/extract_vlm_embeddings_template.py"
click node_datasets "https://github.com/zzh13592365333/speaker/blob/main/erc/datasets.py"
click node_model "https://github.com/zzh13592365333/speaker/blob/main/erc/model.py"
click node_loss "https://github.com/zzh13592365333/speaker/blob/main/erc/loss.py"
click node_utils "https://github.com/zzh13592365333/speaker/blob/main/erc/utils.py"
click node_train_entry "https://github.com/zzh13592365333/speaker/blob/main/train.py"
click node_meld_config "https://github.com/zzh13592365333/speaker/blob/main/configs/meld.example.json"
click node_iemocap_config "https://github.com/zzh13592365333/speaker/blob/main/configs/iemocap.example.json"
click node_meld_script "https://github.com/zzh13592365333/speaker/blob/main/scripts/run_meld.sh"
click node_iemocap_script "https://github.com/zzh13592365333/speaker/blob/main/scripts/run_iemocap.sh"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_vad_priors,node_text_extractor,node_audio_extractor,node_audio_desc,node_vlm_extractor toneBlue
class node_datasets,node_model,node_loss,node_utils toneAmber
class node_train_entry,node_meld_config,node_iemocap_config,node_meld_script,node_iemocap_script toneMint
class node_raw_data,node_text_features,node_audio_features,node_video_features toneNeutral
```

## Components

### Feature tools

Offline modality-specific feature extraction and preprocessing

- [VAD priors](https://github.com/zzh13592365333/speaker/blob/main/feature_tools/preprocess_vad.py): lexical guidance · Valence-arousal-dominance preprocessing used as guidance · `feature_tools/preprocess_vad.py`
- [Text extractor](https://github.com/zzh13592365333/speaker/blob/main/feature_tools/extract_text_emoberta_features.py): feature tool · Builds text embeddings from current, past, and future context · `feature_tools/extract_text_emoberta_features.py`
- [Audio extractor](https://github.com/zzh13592365333/speaker/blob/main/feature_tools/extract_emotion2vec_meld.py): feature tool · Generates MELD audio representations · `feature_tools/extract_emotion2vec_meld.py`
- [Audio descriptions](https://github.com/zzh13592365333/speaker/blob/main/feature_tools/extract_audio_descriptions.py): feature tool · Creates audio-language descriptions for semantic guidance · `feature_tools/extract_audio_descriptions.py`
- [VLM extractor](https://github.com/zzh13592365333/speaker/blob/main/feature_tools/extract_vlm_embeddings_template.py): feature tool · Produces global visual-language embeddings · `feature_tools/extract_vlm_embeddings_template.py`

### ERC training

Dataset loading, model, loss, and shared training logic

- [Dataset loader](https://github.com/zzh13592365333/speaker/blob/main/erc/datasets.py): split adapter · Reads precomputed pickles, aligns labels and utterance IDs, and exposes train/val/test splits · `erc/datasets.py`
- [ERC model](https://github.com/zzh13592365333/speaker/blob/main/erc/model.py): reliability-aware model · Projects modalities into shared space, uses video as query, and applies confidence-gated complementation · `erc/model.py`
- [Loss](https://github.com/zzh13592365333/speaker/blob/main/erc/loss.py): objective · Main classification loss plus auxiliary term weighting · `erc/loss.py`
- [Utilities](https://github.com/zzh13592365333/speaker/blob/main/erc/utils.py): training helpers · Shared helpers used by the training stack · `erc/utils.py`

### Runtime

Entry points, configs, and launch scripts

- [Train](https://github.com/zzh13592365333/speaker/blob/main/train.py): orchestrator · Entry point that wires configs, data, model, optimization, and evaluation · `train.py`
- [MELD config](https://github.com/zzh13592365333/speaker/blob/main/configs/meld.example.json): runtime config · Local path and run settings for MELD · `configs/meld.example.json`
- [IEMOCAP config](https://github.com/zzh13592365333/speaker/blob/main/configs/iemocap.example.json): runtime config · Local path and run settings for IEMOCAP · `configs/iemocap.example.json`
- [MELD script](https://github.com/zzh13592365333/speaker/blob/main/scripts/run_meld.sh): launch wrapper · Shell wrapper for MELD training runs · `scripts/run_meld.sh`
- [IEMOCAP script](https://github.com/zzh13592365333/speaker/blob/main/scripts/run_iemocap.sh): launch wrapper · Shell wrapper for IEMOCAP training runs · `scripts/run_iemocap.sh`

### Other components

- **Raw data**: dataset boundary · Source MELD and IEMOCAP data kept outside the training loop
- **Text features**: pickle features · Precomputed utterance embeddings with conversational context
- **Audio features**: pickle features · Precomputed acoustic sequences for each split
- **Video features**: pickle features · Precomputed visual embeddings used as the central modality

## Connections

- Raw data → Text extractor: text source · Raw utterances are converted into contextual text embeddings
- Raw data → Audio extractor: audio source · Raw speech is converted into acoustic features
- Raw data → Audio descriptions: audio source · Raw audio is summarized into descriptions
- Raw data → VLM extractor: video source · Raw video is converted into global visual embeddings
- Raw data → VAD priors: lexical cues · Raw text is transformed into VAD guidance priors
- Text extractor → Text features: write · Produces standardized text pickle files
- Audio extractor → Audio features: write · Produces standardized audio pickle files
- VLM extractor → Video features: write · Produces standardized video pickle files
- VAD priors → Text extractor: guide · VAD information can inform text feature preparation
- Audio descriptions → Audio extractor: guide · Audio descriptions support semantic enrichment of audio features
- Text features → Dataset loader: load · Training reads precomputed text features from disk
- Audio features → Dataset loader: load · Training reads precomputed audio features from disk
- Video features → Dataset loader: load · Training reads precomputed video features from disk
- Dataset loader → ERC model: batches · Aligned modality batches and labels feed the classifier
- ERC model → Loss: logits · Model outputs are optimized by the training objective
- Train → Dataset loader: build · Training entry constructs dataset splits
- Train → ERC model: instantiate · Training entry creates the ERC model
- Train → Loss: optimize · Training entry attaches the objective
- Train → Utilities: support · Training uses shared utilities for orchestration
- MELD config → Train: configure · MELD runtime settings are loaded by the trainer
- IEMOCAP config → Train: configure · IEMOCAP runtime settings are loaded by the trainer
- MELD script → MELD config: launch · Shell wrapper passes MELD configuration into training
- IEMOCAP script → IEMOCAP config: launch · Shell wrapper passes IEMOCAP configuration into training
