orion-orion / FedDCSR

πŸ”¬ [SDM'24] This is the source code and baselines of our paper FedDCSR: Federated Cross-domain Sequential Recommendation via Disentangled Representation Learning.
Apache License 2.0
25 stars 1 forks source link

# FedDCSR: Federated Cross-domain Sequential Recommendation via Disentangled Representation Learning *[Hongyu Zhang](https://github.com/orion-orion), Dongyi Zheng, Xu Yang, Jiyuan Feng, [Qing Liao](http://liaoqing.hitsz.edu.cn/)\** [![Open Source Love](https://badges.frapsoft.com/os/v2/open-source.svg?v=103)](https://github.com/orion-orion/FedDCSR)[![LICENSE](https://img.shields.io/github/license/orion-orion/FedDCSR)](https://github.com/orion-orion/FedDCSR/blob/main/LICENSE)[![FedDCSR](https://img.shields.io/github/stars/orion-orion/FedDCSR?style=social)](https://github.com/orion-orion/FedDCSR)
[![FedDCSR](https://img.shields.io/github/directory-file-count/orion-orion/FedDCSR)](https://github.com/orion-orion/FedDCSR) [![FedDCSR](https://img.shields.io/github/languages/code-size/orion-orion/FedDCSR)](https://github.com/orion-orion/FedDCSR)

1 Introduction

This is the source code and baselines of our SDM'24 paper FedDCSR: Federated Cross-domain Sequential Recommendation via Disentangled Representation Learning. In this paper, we propose FedDCSR, a novel federated cross-domain sequential recommendation framework via disentangled representation learning.

2 Dependencies

Run the following command to install dependencies:

pip install -r requirements.txt

Note that my Python version is 3.8.13. In addition, it is especially important to note that the Pytorch version needs to be <=1.7.1, otherwise the autograd engine of Pytorch will report an error.

3 Dataset

As used in many cross-domain recommendation methods, we utilize the publicly available datasets from Amazon (an e-commerce platform) to construct the federated CSR scenarios. We select ten domains to generate three cross-domain scenarios: Food-Kitchen-Cloth-Beauty (FKCB), Movie-Book-Game (MBG), and Sports-Garden-Home (SGH).

The preprocessed CSR datasets can be downloaded from Google Drive. You can download them and place them in the ./data path of this project.

4 Code Structure

FedDCSR
β”œβ”€β”€ LICENSE                                     LICENSE file
β”œβ”€β”€ README.md                                   README file 
β”œβ”€β”€ checkpoint                                  Model checkpoints saving directory
β”‚   └── ...
β”œβ”€β”€ data                                        Data directory
β”‚   └── ...
β”œβ”€β”€ log                                         Log directory
β”‚   └── ...
β”œβ”€β”€ models                                      Local model packages
β”‚   β”œβ”€β”€ __init__.py                             Package initialization file
β”‚   β”œβ”€β”€ cl4srec                                 CL4SRec package
β”‚   β”‚   β”œβ”€β”€ __init__.py                         Package initialization
β”‚   β”‚   β”œβ”€β”€ cl4srec_model.py                    Model architecture
β”‚   β”‚   β”œβ”€β”€ config.py                           Model configuration file
β”‚   β”‚   └── modules.py                          Backbone modules (such as self-attention)
β”‚   └── ...
β”œβ”€β”€ pic                                         Picture directory
β”‚   └── FedDCSR-Framework.png                   Model framework diagram
β”œβ”€β”€  utils                                      Tools such as data reading, IO functions, training strategies, etc.
β”‚    β”œβ”€β”€ __init__.py                            Package initialization file
β”‚    β”œβ”€β”€ data_utils.py                          Data reading
β”‚    β”œβ”€β”€ io_utils.py                            IO functions
β”‚    └── train_utils.py                         Training strategies
β”œβ”€β”€ client.py                                   Client architecture   
β”œβ”€β”€ dataloader.py                               Customized dataloader
β”œβ”€β”€ dataset.py                                  Customized dataset          
β”œβ”€β”€ fl.py                                       The overall process of federated learning
β”œβ”€β”€ local_graph.py                              Local graph data structure
β”œβ”€β”€ losses.py                                   Loss functions
β”œβ”€β”€ main.py                                     Main function, including the complete data pipeline
β”œβ”€β”€ requirements.txt                            Dependencies installation
β”œβ”€β”€ server.py                                   Server-side model parameters and user representations aggregation
β”œβ”€β”€ trainer.py                                  Training and test methods of FedDCSR and other baselines
└── .gitignore                                  .gitignore file

5 Train & Eval

5.1 Our method

To train FedDCSR (ours), you can run the following command:

python -u main.py \
        --epochs 40 \
        --local_epoch 3 \
        --eval_interval 1 \
        --frac 1.0 \
        --batch_size 256 \
        --log_dir log \
        --method FedDCSR \
        --anneal_cap 1.0 \
        --lr 0.001 \
        --seed 42 \
        Food Kitchen Clothing Beauty

There are a few points to note:

To test FedDCSR, you can run the following command:

python -u main.py \
        --log_dir log \
        --method FedDCSR \
        --do_eval \
        --seed 42 \
        Food Kitchen Clothing Beauty

5.2 Baselines

To train other baselines (FedSASRec, FedVSAN, FedContrastVAE, FedCL4SRec, FedDuoRec), you can run the following command:

python -u main.py \
        --epochs 40 \
        --local_epoch 3 \
        --eval_interval 1 \
        --frac 1.0 \
        --batch_size 256 \
        --log_dir log \
        --method FedContrastVAE \
        --anneal_cap 1.0 \
        --lr 0.001 \
        --seed 42 \
        Food Kitchen Clothing Beauty

For the local version without federated aggregation, you can run the following command:

python -u main.py \
        --epochs 40 \
        --local_epoch 3 \
        --eval_interval 1 \
        --frac 1.0 \
        --batch_size 256 \
        --log_dir log \
        --method LocalContrastVAE \
        --anneal_cap 1.0 \
        --lr 0.001 \
        --seed 42 \
        Food Kitchen Clothing Beauty

6 Citation

If you find this work useful for your research, please kindly cite FedDCSR by:

@inbook{Zhang_2024,
   title={FedDCSR: Federated Cross-domain Sequential Recommendation via Disentangled Representation Learning},
   ISBN={9781611978032},
   url={http://dx.doi.org/10.1137/1.9781611978032.62},
   DOI={10.1137/1.9781611978032.62},
   booktitle={Proceedings of the 2024 SIAM International Conference on Data Mining (SDM)},
   publisher={Society for Industrial and Applied Mathematics},
   author={Zhang, Hongyu and Zheng, Dongyi and Yang, Xu and Feng, Jiyuan and Liao, Qing},
   year={2024},
   month=jan, pages={535–543} }