Home

Awesome

Mirror Gradient

GitHub GitHub

By Shanshan Zhong and Zhongzhan Huang and Daifeng Li and Wushao Wen and Jinghui Qin and Liang Lin

This repository is the implementation of "Mirror Gradient: Towards Robust Multimodal Recommender Systems via Exploring Flat Local Minima" [paper]. Our paper has been accepted at the 2024 ACM Web Conference (WWW 2024).

🌻 Introduction

Multimodal recommender systems utilize various types of information, such as texts and images, to model user preferences and item features, helping users discover items aligned with their interests. However, it simultaneously magnifies certain risks from multimodal information inputs, such as inherent noise risk and information adjustment risk. To this end, we propose a concise gradient strategy Mirror Gradient (MG) that inverses the gradient signs appropriately during training to make the multimodal recommendation models approach flat local minima easier compared to models with normal training.

<p align="center" style="font-size:6px;"> <img src="images/algorithm.jpg" width="60%"> </p>

🌻 Quick Training

As a general gradient method of recommender systems, MG can be applied to the training of various recommendation models. The code of this repository is based on MMRec, a modern multimodal recommendation toolbox, and the core code of MG is in src/common/trainer.py. We also integrate MG to the modern multimodal recommendation toolbox MMRec

(1) Clone the code.

git clone https://github.com/Qrange-group/Mirror-Gradient
cd Mirror-Gradient

(2) Prepare the enviroment.

conda env create -f environment.yaml
conda activate mg
pip install torch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2 --index-url https://download.pytorch.org/whl/cu118
pip install --no-index torch_cluster -f https://pytorch-geometric.com/whl/torch-2.0.1+cu118.html
pip install --no-index torch-scatter -f https://pytorch-geometric.com/whl/torch-2.0.1+cu118.html
pip install --no-index torch_sparse -f https://pytorch-geometric.com/whl/torch-2.0.1+cu118.html
pip install --no-index torch_spline_conv -f https://pytorch-geometric.com/whl/torch-2.0.1+cu118.html
pip install torch_geometric

(3) Prepare datasets.

See data. If you want to train models on other Amazon datasets, please see the processing tutorial.

(4) Train the model with MG.

cd src 
python main.py

You can change the model and dataset by the code,

python main.py --model DRAGON --dataset sports
python main.py --model LayerGCN --dataset sports

If you don't want to use MG during training, please use --not_mg. For example,

python main.py --not_mg

🌻 Supported Models and Datasets

🌻 Checkpoints

For the evaluation of recommendation performance, we pay attention to top-5 accuracy as recommendations in the top positions of rank lists are more important, and adopt four widely used metrics including recall (REC), precision (PREC), mean average precision (MAP), and normalized discounted cumulative gain (NDCG).

You can resume the checkpoint by,

python main.py --model DRAGON --dataset sports --resume DRAGON-sports.pth

Sports

ModelRECPRECMAPNDCG
VBPR0.03530.00790.01890.0235
VBPR + MG0.03750.00840.02030.0251
MMGCN0.02160.00490.01140.0143
MMGCN + MG0.02410.00540.01260.0158
GRCN0.03600.00800.01960.0241
GRCN + MG0.03830.00860.02070.0256
DualGNN0.03740.00840.02060.0253
DualGNN + MG0.03870.00860.02120.0261
SLMRec0.04290.00950.02330.0288
SLMRec + MG0.04490.00990.02420.0299
BM30.03530.00780.01940.0238
BM3 + MG0.03860.00860.02100.0259
FREEDOM0.04460.00980.02320.0291
FREEDOM + MG0.04660.01020.02420.0303
DRAGON0.04490.00980.02390.0296
DRAGON + MG0.04650.01020.02480.0307

Elec

ModelRECPRECMAPNDCG
VBPR0.01820.00420.00980.0122
VBPR + MG0.02030.00460.01100.0136
MMGCN0.01400.00330.00750.0094
MMGCN + MG0.01570.00360.00840.0106
GRCN0.02260.00510.01260.0155
GRCN + MG0.02500.00570.01390.0171
DualGNN0.02380.00540.01320.0162
DualGNN + MG0.02490.00560.01390.0170
BM30.02800.00620.01570.0192
BM3 + MG0.02850.00630.01590.0195
FREEDOM0.02520.00560.01390.0171
FREEDOM + MG0.02600.00580.01440.0176

🌸 Citation

@inproceedings{zhong2024mirror,
  title={Mirror Gradient: Towards Robust Multimodal Recommender Systems via Exploring Flat Local Minima},
  author={Zhong, Shanshan and Huang, Zhongzhan and Li, Daifeng and Wen, Wushao and Qin, Jinghui and Lin, Liang},
  booktitle={Proceedings of the ACM on Web Conference 2024},
  pages={3700--3711},
  year={2024}
}

💖 Acknowledgments

Many thanks to enoche for their MMRec for multimodal recommendation task.