
Welcome to the official repository for our reproducibility research of "TRIANGLE", a similarity measure that is directly computed in the higher-dimensional space spanned by the modality embeddings. The code is implemented in Python using PyTorch and Distributed Processing to provide an efficient and fast implementation of the algorithm.
The code in this repository has been used to research the reproducibility of the experiments conducted in the original 'TRIANGLE' paper. Furthermore, the repository contains our new additions. Our contributions include:
#!/bin/bash
#SBATCH --partition=gpu_mig
#SBATCH --gpus=1
#SBATCH --job-name=InstallEnvironment
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=9
#SBATCH --time=04:00:00
#SBATCH --output=slurm_output_install_env_%A.out
module purge
module load 2024
module load Anaconda3/2024.06-1
cd $HOME/Environment/
conda env create -f triangle_env.yaml
The following are the datasets that were used in the experiments:
python adhoc_scripts/extract_audio.py --video_root <Directory containing dataset videos> --audio_root <Directory to write extracted audio>
Once the datasets have been downloaded properly, edit the config files inside the config/triangle/finetune_cfg directory to replace the preset dataset paths with your local system paths (where the datasets reside on your machine after downloading).
Make a dir named pretrained_weights under the main work dir.
wget -P pretrained_weights/clip/ https://huggingface.co/QuanSun/EVA-CLIP/resolve/main/EVA01_CLIP_g_14_psz14_s11B.pt
from transformers import BertForMaskedLM, BertTokenizer
bert = BertForMaskedLM.from_pretrained('bert-base-uncased')
bert_tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
bert.save_pretrained('pretrained_weights/bert/bert-base-uncased')
bert_tokenizer.save_pretrained('pretrained_weights/bert/bert-base-uncased')
The processed pretrained_weights path should be as follows:
├── pretrained_weights
│ ├── beats
│ │ └── BEATs_iter3_plus_AS2M.pt
│ ├── bert
│ │ └── bert-base-uncased
│ ├── clip
│ │ └── EVA01_CLIP_g_14_psz14_s11B.pt
│ ├── triangle_pretraining
│ │ └── ckpt
│ │ └── model_step_200.pt
│ │ └── log
│ │ └── hps.json
│ │ └── log.txt
Now that the environment has been correctly installed and datasets have been downloaded (along with audio extraction), it is time to run the code.
For all experiment runs, please make sure to add the following to your job file (to disable online wandb logs that require API key):
export WANDB_MODE=offline
This will create wandb log files locally. These can later be uploaded to wandb using an API key.
The audio/video retrieval experiment can be divided into two subtasks:
Our code gives you the evaluation scores for both the directions. To run the zero shot audio/video retrieval for a dataset, run the following command in job file:
torchrun \
--nnodes 1 \
--node_rank 0 \
--nproc_per_node=4 \ # Number of GPUs for distributed run
--master_port=29501 \
distributed_run.py \
--model_type triangle \ # model_type can be vast, triangle or triangle_cos
--mode testing \
--pretrain_dir <path to directory containing pretrained triangle checkpoint and weights for encoders used)> \
--config <config path of the dataset (inside config/triangle/finetune_cfg directory)> \
--output_dir <Path to directory where results will be stored>
The outputs will be saved in the output_dir folder (passed as command line argument and created automatically by the code).
This directory will also contain the generated trec files (created during evaluation). To obtain the new ranking metrics from these, run the adhoc_scripts/ir_measures_eval.py file using:
python adhoc_scripts/ir_measures_eval.py \
<path to directory containing trec_runs directory (with generated trec files)> \
--output <path to directory where result csv will be stored>
The Training From Scratch experiment aims to perform a deeper study on the ability of TRIANGLE to better model the latent space by letting TRIANGLE losses learn from scratch on the MSR-VTT dataset for the multimodal text-to-audio/video (T2AV) and audio/video-to-text (AV2T) tasks.
To run the training from scratch experiment for MSR-VTT dataset, run the following command in job file:
torchrun \
--nnodes 1 \
--node_rank 0 \
--nproc_per_node=4 \ # Number of GPUs for distributed run
--master_port=29501 \
distributed_run.py \
--model_type triangle \ # model_type can be vast, triangle or triangle_cos
--mode training \
--config <config path for MSR-VTT dataset (inside config/triangle/finetune_cfg directory)> \
--output_dir <Path to directory where results will be stored>
The outputs will be saved in the output_dir folder (passed as command line argument and created automatically by the code).
This directory will also contain the generated trec files (created during evaluation). To obtain the new ranking metrics from these, run the adhoc_scripts/ir_measures_eval.py file using:
python adhoc_scripts/ir_measures_eval.py \
<path to directory containing trec_runs directory (with generated trec files)> \
--output <path to directory where result csv will be stored>
The Finetune on YouCook Data experiment aims to test the impact on the retrieval scores by fine-tuning the pre-trained checkpoint on out of domain data on which the checkpoint originally performed bad.
To run the finetune on YouCook data experiment for YouCook dataset, run the following command in job file:
torchrun \
--nnodes 1 \
--node_rank 0 \
--nproc_per_node=4 \ # Number of GPUs for distributed run
--master_port=29501 \
distributed_run.py \
--model_type triangle \ # model_type can be vast, triangle or triangle_cos
--mode training \
--pretrain_dir <path to directory containing pretrained triangle checkpoint and weights for encoders used)> \
--config <config path for YouCook dataset (inside config/triangle/finetune_cfg directory)> \
--output_dir <Path to directory where results will be stored>
The outputs will be saved in the output_dir folder (passed as command line argument and created automatically by the code).
This directory will also contain the generated trec files (created during evaluation). To obtain the new ranking metrics from these, run the adhoc_scripts/ir_measures_eval.py file using:
python adhoc_scripts/ir_measures_eval.py \
<path to directory containing trec_runs directory (with generated trec files)> \
--output <path to directory where result csv will be stored>
To run the TRIANGLE Explainability experiment, do the following:
python adhoc_scripts/explain_sample_yc.py \
--pretrain_dir <path to directory containing pretrained triangle checkpoint and weights for encoders used)> \
--video_dir <path to directory containing videos for the dataset> \
--audio_dir <path to directory containing audios for the dataset> \
--json_path <path to directory containing captions/descriptions for the dataset> \
--num_samples 8 # Number of samples to extract
The Training from Scratch on Toy Dataset experiment aims to diagnose optimization stability of the training process by allowing us to decouple the impact of the alignment loss from the complexity of real-world data. The Toy dataset comprises short video clips of moving geometric shapes, synthetic descriptive speech, and corresponding text captions
To run the finetune on YouCook data experiment for YouCook dataset,
torchrun \
--nnodes 1 \
--node_rank 0 \
--nproc_per_node=4 \ # Number of GPUs for distributed run
--master_port=29501 \
distributed_run.py \
--model_type triangle \ # model_type can be vast, triangle or triangle_cos
--mode training \
--config <config path for Toy dataset (inside config/triangle/finetune_cfg directory)> \
--output_dir <Path to directory where results will be stored>
The outputs will be saved in the output_dir folder (passed as command line argument and created automatically by the code).
This directory will also contain the generated trec files (created during evaluation). To obtain the new ranking metrics from these, run the adhoc_scripts/ir_measures_eval.py file using:
python adhoc_scripts/ir_measures_eval.py \
<path to directory containing trec_runs directory (with generated trec files)> \
--output <path to directory where result csv will be stored>
5 commits
Jupyter Notebook
56.7%
Python
43.3%

Welcome to the official repository for our reproducibility research of "TRIANGLE", a similarity measure that is directly computed in the higher-dimensional space spanned by the modality embeddings. The code is implemented in Python using PyTorch and Distributed Processing to provide an efficient and fast implementation of the algorithm.
The code in this repository has been used to research the reproducibility of the experiments conducted in the original 'TRIANGLE' paper. Furthermore, the repository contains our new additions. Our contributions include:
#!/bin/bash
#SBATCH --partition=gpu_mig
#SBATCH --gpus=1
#SBATCH --job-name=InstallEnvironment
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=9
#SBATCH --time=04:00:00
#SBATCH --output=slurm_output_install_env_%A.out
module purge
module load 2024
module load Anaconda3/2024.06-1
cd $HOME/Environment/
conda env create -f triangle_env.yaml
The following are the datasets that were used in the experiments:
python adhoc_scripts/extract_audio.py --video_root <Directory containing dataset videos> --audio_root <Directory to write extracted audio>
Once the datasets have been downloaded properly, edit the config files inside the config/triangle/finetune_cfg directory to replace the preset dataset paths with your local system paths (where the datasets reside on your machine after downloading).
Make a dir named pretrained_weights under the main work dir.
wget -P pretrained_weights/clip/ https://huggingface.co/QuanSun/EVA-CLIP/resolve/main/EVA01_CLIP_g_14_psz14_s11B.pt
from transformers import BertForMaskedLM, BertTokenizer
bert = BertForMaskedLM.from_pretrained('bert-base-uncased')
bert_tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
bert.save_pretrained('pretrained_weights/bert/bert-base-uncased')
bert_tokenizer.save_pretrained('pretrained_weights/bert/bert-base-uncased')
The processed pretrained_weights path should be as follows:
├── pretrained_weights
│ ├── beats
│ │ └── BEATs_iter3_plus_AS2M.pt
│ ├── bert
│ │ └── bert-base-uncased
│ ├── clip
│ │ └── EVA01_CLIP_g_14_psz14_s11B.pt
│ ├── triangle_pretraining
│ │ └── ckpt
│ │ └── model_step_200.pt
│ │ └── log
│ │ └── hps.json
│ │ └── log.txt
Now that the environment has been correctly installed and datasets have been downloaded (along with audio extraction), it is time to run the code.
For all experiment runs, please make sure to add the following to your job file (to disable online wandb logs that require API key):
export WANDB_MODE=offline
This will create wandb log files locally. These can later be uploaded to wandb using an API key.
The audio/video retrieval experiment can be divided into two subtasks:
Our code gives you the evaluation scores for both the directions. To run the zero shot audio/video retrieval for a dataset, run the following command in job file:
torchrun \
--nnodes 1 \
--node_rank 0 \
--nproc_per_node=4 \ # Number of GPUs for distributed run
--master_port=29501 \
distributed_run.py \
--model_type triangle \ # model_type can be vast, triangle or triangle_cos
--mode testing \
--pretrain_dir <path to directory containing pretrained triangle checkpoint and weights for encoders used)> \
--config <config path of the dataset (inside config/triangle/finetune_cfg directory)> \
--output_dir <Path to directory where results will be stored>
The outputs will be saved in the output_dir folder (passed as command line argument and created automatically by the code).
This directory will also contain the generated trec files (created during evaluation). To obtain the new ranking metrics from these, run the adhoc_scripts/ir_measures_eval.py file using:
python adhoc_scripts/ir_measures_eval.py \
<path to directory containing trec_runs directory (with generated trec files)> \
--output <path to directory where result csv will be stored>
The Training From Scratch experiment aims to perform a deeper study on the ability of TRIANGLE to better model the latent space by letting TRIANGLE losses learn from scratch on the MSR-VTT dataset for the multimodal text-to-audio/video (T2AV) and audio/video-to-text (AV2T) tasks.
To run the training from scratch experiment for MSR-VTT dataset, run the following command in job file:
torchrun \
--nnodes 1 \
--node_rank 0 \
--nproc_per_node=4 \ # Number of GPUs for distributed run
--master_port=29501 \
distributed_run.py \
--model_type triangle \ # model_type can be vast, triangle or triangle_cos
--mode training \
--config <config path for MSR-VTT dataset (inside config/triangle/finetune_cfg directory)> \
--output_dir <Path to directory where results will be stored>
The outputs will be saved in the output_dir folder (passed as command line argument and created automatically by the code).
This directory will also contain the generated trec files (created during evaluation). To obtain the new ranking metrics from these, run the adhoc_scripts/ir_measures_eval.py file using:
python adhoc_scripts/ir_measures_eval.py \
<path to directory containing trec_runs directory (with generated trec files)> \
--output <path to directory where result csv will be stored>
The Finetune on YouCook Data experiment aims to test the impact on the retrieval scores by fine-tuning the pre-trained checkpoint on out of domain data on which the checkpoint originally performed bad.
To run the finetune on YouCook data experiment for YouCook dataset, run the following command in job file:
torchrun \
--nnodes 1 \
--node_rank 0 \
--nproc_per_node=4 \ # Number of GPUs for distributed run
--master_port=29501 \
distributed_run.py \
--model_type triangle \ # model_type can be vast, triangle or triangle_cos
--mode training \
--pretrain_dir <path to directory containing pretrained triangle checkpoint and weights for encoders used)> \
--config <config path for YouCook dataset (inside config/triangle/finetune_cfg directory)> \
--output_dir <Path to directory where results will be stored>
The outputs will be saved in the output_dir folder (passed as command line argument and created automatically by the code).
This directory will also contain the generated trec files (created during evaluation). To obtain the new ranking metrics from these, run the adhoc_scripts/ir_measures_eval.py file using:
python adhoc_scripts/ir_measures_eval.py \
<path to directory containing trec_runs directory (with generated trec files)> \
--output <path to directory where result csv will be stored>
To run the TRIANGLE Explainability experiment, do the following:
python adhoc_scripts/explain_sample_yc.py \
--pretrain_dir <path to directory containing pretrained triangle checkpoint and weights for encoders used)> \
--video_dir <path to directory containing videos for the dataset> \
--audio_dir <path to directory containing audios for the dataset> \
--json_path <path to directory containing captions/descriptions for the dataset> \
--num_samples 8 # Number of samples to extract
The Training from Scratch on Toy Dataset experiment aims to diagnose optimization stability of the training process by allowing us to decouple the impact of the alignment loss from the complexity of real-world data. The Toy dataset comprises short video clips of moving geometric shapes, synthetic descriptive speech, and corresponding text captions
To run the finetune on YouCook data experiment for YouCook dataset,
torchrun \
--nnodes 1 \
--node_rank 0 \
--nproc_per_node=4 \ # Number of GPUs for distributed run
--master_port=29501 \
distributed_run.py \
--model_type triangle \ # model_type can be vast, triangle or triangle_cos
--mode training \
--config <config path for Toy dataset (inside config/triangle/finetune_cfg directory)> \
--output_dir <Path to directory where results will be stored>
The outputs will be saved in the output_dir folder (passed as command line argument and created automatically by the code).
This directory will also contain the generated trec files (created during evaluation). To obtain the new ranking metrics from these, run the adhoc_scripts/ir_measures_eval.py file using:
python adhoc_scripts/ir_measures_eval.py \
<path to directory containing trec_runs directory (with generated trec files)> \
--output <path to directory where result csv will be stored>
5 commits
Jupyter Notebook
56.7%
Python
43.3%