Chinese–English Cross-Lingual Multimodal Sentiment Analysis Framework 🎥 End-to-end Video → Sentiment prediction 🔗 Transformer-based Cross-Attention Fusion 🔍 Built-in Explainability & Visualization 🏆 Developed for MSA Challenge @ The 4th Pazhou AI Competition
- 🌐 Cross-Lingual: Handles both Chinese and English with Whisper + BERT.
- 🎬 Multimodal:
- Text → Whisper transcript + BERT embeddings
- Audio → MFCC + prosody features
- Visual → MediaPipe landmarks + HoG + FACS
- 🔗 Fusion: Transformer-based Cross-Attention for balanced modality contribution.
- 🔍 Explainability: Attention heatmaps reveal modality importance.
- ⚡ Flexible Execution:
- One-click demo (test_script.py)
- Two-step reproducible pipeline (video → features → training)
- Direct video-to-prediction (no
.pklsaved)
- 🧩 Modular Design: Easily extend with CLIP, SAM, LLMs, etc.
MSA/
├── README.md # Project introduction
├── requirements.txt # Dependencies
├── test_script.py # One-click testing
├── best_models/ # Pre-trained weights (en.pt / zh.pt)
├── MSAbypkl/ # PKL-based workflow (train/eval)
│ ├── main.py # Training & evaluation
| ├── config.py # Modify parameters
│ ├── scripts/ # Training scripts
│ └── src/ # Core modules (data/models/training/utils)
├── MSAbyvideo/ # Direct video-to-sentiment workflow
├── video2pkl/ # Video-to-feature extractor
│ └── video2pkl.py # Whisper + BERT + MediaPipe extractor
└── Test_Data / Test_Results # Example data & outputspip install -r requirements.txtpython test_script.py- Put videos into
Video_Data/ - Predictions saved in
Test_Results/
Step 1: Extract Features
python video2pkl/video2pkl/video2pkl.py --language en --video_dir ./Video_Data --csv_path ./meta.csv --output_dir ./MSAbypkl/data/data_pkl/mysetStep 2: Train / Evaluate
# config.py
DATASET_NAME = "myset"python MSAbypkl/main.pypython MSAbyvideo/main.py- Interactive CLI prompts
- Faster, no
.pklsaved
- Text: Whisper → BERT (768-dim)
- Audio: MFCC + prosody (40-dim)
- Visual: MediaPipe + HoG + FACS (35-dim)
- Fusion: Transformer encoders + Cross-Attention
- Output: 5-class sentiment →
SNEG | WNEG | NEUT | WPOS | SPOS(Regression supported viaNUM_CLASSES=1)
📊 Metrics: Accuracy, Macro-F1, Confusion Matrix
Below are the issues we encountered during local debugging, their typical causes, and recommended fixes to help you reproduce results quickly.
- Symptom (example trace): raised when calling
Whisper.transcribe()or when MoviePy opens a video file (under the hood these call theffmpegexecutable). - Cause: Whisper and MoviePy rely on the system
ffmpegbinary. Ifffmpegis not installed or not on PATH, a subprocess FileNotFoundError is raised. - Fix (Windows examples):
- Using winget (recommended if available):
winget install --id Gyan.FFmpeg -e --silent
- Using Chocolatey (requires admin):
choco install -y ffmpeg - Manual install: download ffmpeg and add its
binfolder to PATH (e.g.C:\ffmpeg\bin):setx PATH "$env:Path;C:\ffmpeg\bin" - Verify installation:
ffmpeg -version
- Using winget (recommended if available):
Note: We also applied a small code-level fix to avoid a MoviePy Path/WindowsPath issue by ensuring file paths are passed as strings (see video2pkl/video2pkl.py and video2pkl/video2csd/get_3m.py).
Note about fallback behavior:
- The codebase now attempts a graceful fallback when a system
ffmpegis not available: if the Python packageimageio-ffmpegis installed, the project will locate its bundled ffmpeg binary and make it available to subprocess calls by temporarily copying it to a local temp directory namedmsaffmpegand prepending that directory to the processPATH. - This makes
test_script.pyand Whisper/MoviePy work even when ffmpeg is not installed system-wide. The fallback relies onimageio-ffmpegbeing installed;imageio-ffmpeg==0.5.1is already included inrequirements.txt.
- Symptom: a FileNotFoundError occurs when
torch.load(...)is called to load a checkpoint (this can appear during evaluation inMSAbypkl/main.py). - Fix options:
- Download the required checkpoint files and place them into the repository
best_models/folder using the exact filenames (e.g.best_models/zh.pt,best_models/en.pt). - Or update the checkpoint paths in
MSAbypkl/main.pyto point to your local checkpoint locations.
- Download the required checkpoint files and place them into the repository
- Symptom: OpenCV fails to load with recursion error when importing cv2 in Python.
- Cause: OpenCV installation conflict or corrupted installation, often due to multiple versions or incomplete installation.
- Fix:
- Uninstall existing OpenCV packages:
pip uninstall opencv-contrib-python opencv-python -y
- Reinstall stable version:
pip install opencv-python==4.8.0.76
- Verify installation:
python -c "import cv2; print('OpenCV version:', cv2.__version__)"
- Uninstall existing OpenCV packages:
- Symptom: Whisper model fails to load with path-related errors.
- Cause: Hardcoded model paths in code that don't exist on current system.
- Fix: The code has been updated to use online Whisper models instead of local paths. Ensure you have internet connection for initial model download, or update the code to use your local model paths if preferred.
-
Pre-trained text models and our best checkpoints (Chinese / English) are available here:
https://drive.google.com/drive/folders/1deCsD3TXacpuov78v7PldhXL5zFSjNjL
-
After downloading, place the files under the repository root
best_models/directory:best_models/zh.ptbest_models/en.pt- Alternatively, update
MSAbypkl/main.pyto load from your custom paths.
- 🏆 Public Leaderboard:
0.4350(baseline-level, CPU-only training) - 🔬 Ablations: Cross-attention > Early fusion > Late fusion
- ⚡ With GPU, accuracy expected to improve significantly
- Saves cross-attention weights
- Generates modality contribution heatmaps
- Ensures transparent & trustworthy predictions
👨💻 Team Members: YanSong Hu · YangLe Ma · ZhouYang Wang · RiJie Hao 📧 Email: 672416680@qq.com | mylsxxy@163.com
⭐ If you like this project, please star the repo — it keeps us motivated! ⭐