How zzh13592365333/speaker works
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 Train · datasets.py Dataset loader · extract_text_emoberta_features.py Text extractor · extract_emotion2vec_meld.py Audio extractor
Components 18
Feature tools
Offline modality-specific feature extraction and preprocessing
- VAD priors · Valence-arousal-dominance preprocessing used as guidance
feature_tools/preprocess_vad.py - Text extractor · Builds text embeddings from current, past, and future context
feature_tools/extract_text_emoberta_features.py - Audio extractor · Generates MELD audio representations
feature_tools/extract_emotion2vec_meld.py - Audio descriptions · Creates audio-language descriptions for semantic guidance
feature_tools/extract_audio_descriptions.py - VLM extractor · Produces global visual-language embeddings
feature_tools/extract_vlm_embeddings_template.py
ERC training
Dataset loading, model, loss, and shared training logic
- Dataset loader · Reads precomputed pickles, aligns labels and utterance IDs, and exposes train/val/test splits
erc/datasets.py - ERC model · Projects modalities into shared space, uses video as query, and applies confidence-gated complementation
erc/model.py - Loss · Main classification loss plus auxiliary term weighting
erc/loss.py - Utilities · Shared helpers used by the training stack
erc/utils.py
Runtime
Entry points, configs, and launch scripts
- Train · Entry point that wires configs, data, model, optimization, and evaluation
train.py - MELD config · Local path and run settings for MELD
configs/meld.example.json - IEMOCAP config · Local path and run settings for IEMOCAP
configs/iemocap.example.json - MELD script · Shell wrapper for MELD training runs
scripts/run_meld.sh - IEMOCAP script · Shell wrapper for IEMOCAP training runs
scripts/run_iemocap.sh
Other components
- Raw data · Source MELD and IEMOCAP data kept outside the training loop
- Text features · Precomputed utterance embeddings with conversational context
- Audio features · Precomputed acoustic sequences for each split
- Video features · Precomputed visual embeddings used as the central modality
Connections 23
- 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