CAGF: Context-Aware Gated Fusion Network for Multimodal Sentiment Analysis
1
stars
5
commits
Python
primary language
May 10, 2026
updated
CAGF: Context-Aware Gated Fusion Network for Multimodal Sentiment Analysis
pip install -r requirements.txtThe three datasets (CMU-MOSI, CMU-MOSEI, and CH-SIMS) are available from this link: https://drive.google.com/drive/folders/1A2S4pqCHryGmiqnNSPLv7rEg63WvjCSk
/data/
mosi/
raw/
label.csv
mosei/
raw/
label.csv
sims/
raw/
label.csv
Before running the training code, please extract the audio from the raw video files.
python extract_audio.py
options:
--dataset DATASET dataset name (mosi, mosei, or sims)
python run.py
options (optional):
--seed SEED random seed (default: 1)
--batch_size BATCH_SIZE
batch size (default: 8)
--lr LR learning rate (default: 5e-6)
--model MODEL concatenate(cc) or cross-modality encoder(cme) (default: cme)
--cme_version VERSION
version (default: v1)
--dataset DATASET dataset name: mosi, mosei, sims (default: mosi)
--num_hidden_layers NUM_HIDDEN_LAYERS
number of hidden layers for cross-modality encoder (default: 5)
--tasks TASKS losses to train: M: multi-modal, T: text, A: audio
(default: MTA)
--context CONTEXT incorporate context or not (default: True)
--text_context_len TEXT_CONTEXT_LEN
(default: 2)
--audio_context_len AUDIO_CONTEXT_LEN
(default: 1)
--use_gated_fusion Use gated fusion network for rob_wavlm_cme_context model
--gpu_ids GPU_IDS GPU ids for multi-gpu training, e.g., "0,1,2,3" or "0" for single gpu (default: 0)
You can generate a full waveform or extract and save the waveform of a specific word spoken in the audio.
python save_waveform.py
--video_id VIDEO_ID
--clip_id CLIP_ID
--dataset DATASET Dataset name (mosi, mosei)
--word TARGET_WORD (default: None)
Generate t-SNE visualizations comparing feature representations across three processing methods: raw features, concatenation fusion, and CAGF (CME + Gated Fusion).
python tsne_visualization.py
--checkpoint CHECKPOINT Path to the CAGF model checkpoint
Example: checkpoint/cagf_model.pth
--checkpoint_cc CHECKPOINT_CC Path to the Concatenation fusion model checkpoint
Example: checkpoint/cc_model.pth
--dataset DATASET Dataset name (mosi, mosei)
--seed SEED Random seed for reproducibility (default: 1)
--batch_size BATCH_SIZE Batch size for feature extraction (default: 8)
--text_context_len LENGTH Length of text context window (default: 5)
--audio_context_len LENGTH Length of audio context window (default: 5)
--perplexity PERPLEXITY t-SNE perplexity parameter (default: 30)
Recommended range: 20-50
--output OUTPUT Output image path (default: tsne_mosi.png)
Generate t-SNE visualizations comparing feature representations across three processing methods for the CH-SIMS dataset: raw features, concatenation fusion, and CME.
python tsne_visualization_sims.py
--checkpoint CHECKPOINT Path to the CME (Cross-Modal Encoder) checkpoint
Example: checkpoint/cme_sims.pth
--checkpoint_cc CHECKPOINT_CC Path to the Concatenation (CC) fusion model checkpoint
Example: checkpoint/cc_sims.pth
--seed SEED Random seed for reproducibility (default: 1)
--batch_size BATCH_SIZE Batch size for feature extraction (default: 8)
--num_hidden_layers NUM_HIDDEN_LAYERS
Number of CME cross-modal encoder layers (default: 5)
Should match the training configuration
--perplexity PERPLEXITY t-SNE perplexity parameter (default: 30)
Recommended range: 20-50
--output OUTPUT Output image path (default: tsne_sims.png)
5 commits
Python
100.0%
CAGF: Context-Aware Gated Fusion Network for Multimodal Sentiment Analysis
1
stars
5
commits
Python
primary language
May 10, 2026
updated
CAGF: Context-Aware Gated Fusion Network for Multimodal Sentiment Analysis
pip install -r requirements.txtThe three datasets (CMU-MOSI, CMU-MOSEI, and CH-SIMS) are available from this link: https://drive.google.com/drive/folders/1A2S4pqCHryGmiqnNSPLv7rEg63WvjCSk
/data/
mosi/
raw/
label.csv
mosei/
raw/
label.csv
sims/
raw/
label.csv
Before running the training code, please extract the audio from the raw video files.
python extract_audio.py
options:
--dataset DATASET dataset name (mosi, mosei, or sims)
python run.py
options (optional):
--seed SEED random seed (default: 1)
--batch_size BATCH_SIZE
batch size (default: 8)
--lr LR learning rate (default: 5e-6)
--model MODEL concatenate(cc) or cross-modality encoder(cme) (default: cme)
--cme_version VERSION
version (default: v1)
--dataset DATASET dataset name: mosi, mosei, sims (default: mosi)
--num_hidden_layers NUM_HIDDEN_LAYERS
number of hidden layers for cross-modality encoder (default: 5)
--tasks TASKS losses to train: M: multi-modal, T: text, A: audio
(default: MTA)
--context CONTEXT incorporate context or not (default: True)
--text_context_len TEXT_CONTEXT_LEN
(default: 2)
--audio_context_len AUDIO_CONTEXT_LEN
(default: 1)
--use_gated_fusion Use gated fusion network for rob_wavlm_cme_context model
--gpu_ids GPU_IDS GPU ids for multi-gpu training, e.g., "0,1,2,3" or "0" for single gpu (default: 0)
You can generate a full waveform or extract and save the waveform of a specific word spoken in the audio.
python save_waveform.py
--video_id VIDEO_ID
--clip_id CLIP_ID
--dataset DATASET Dataset name (mosi, mosei)
--word TARGET_WORD (default: None)
Generate t-SNE visualizations comparing feature representations across three processing methods: raw features, concatenation fusion, and CAGF (CME + Gated Fusion).
python tsne_visualization.py
--checkpoint CHECKPOINT Path to the CAGF model checkpoint
Example: checkpoint/cagf_model.pth
--checkpoint_cc CHECKPOINT_CC Path to the Concatenation fusion model checkpoint
Example: checkpoint/cc_model.pth
--dataset DATASET Dataset name (mosi, mosei)
--seed SEED Random seed for reproducibility (default: 1)
--batch_size BATCH_SIZE Batch size for feature extraction (default: 8)
--text_context_len LENGTH Length of text context window (default: 5)
--audio_context_len LENGTH Length of audio context window (default: 5)
--perplexity PERPLEXITY t-SNE perplexity parameter (default: 30)
Recommended range: 20-50
--output OUTPUT Output image path (default: tsne_mosi.png)
Generate t-SNE visualizations comparing feature representations across three processing methods for the CH-SIMS dataset: raw features, concatenation fusion, and CME.
python tsne_visualization_sims.py
--checkpoint CHECKPOINT Path to the CME (Cross-Modal Encoder) checkpoint
Example: checkpoint/cme_sims.pth
--checkpoint_cc CHECKPOINT_CC Path to the Concatenation (CC) fusion model checkpoint
Example: checkpoint/cc_sims.pth
--seed SEED Random seed for reproducibility (default: 1)
--batch_size BATCH_SIZE Batch size for feature extraction (default: 8)
--num_hidden_layers NUM_HIDDEN_LAYERS
Number of CME cross-modal encoder layers (default: 5)
Should match the training configuration
--perplexity PERPLEXITY t-SNE perplexity parameter (default: 30)
Recommended range: 20-50
--output OUTPUT Output image path (default: tsne_sims.png)
5 commits
Python
100.0%