/FedDCSR

🔬 [SDM'24] This is the source code and baselines of our paper FedDCSR: Federated Cross-domain Sequential Recommendation via Disentangled Representation Learning.

Primary LanguagePythonApache License 2.0Apache-2.0

FedDCSR: Federated Cross-domain Sequential Recommendation via Disentangled Representation Learning

Hongyu Zhang, Dongyi Zheng, Xu Yang, Jiyuan Feng, Qing Liao*

Open Source LoveLICENSEFedDCSR
FedDCSR 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:

  • the positional arguments Food Kitchen Clothing Beauty indicates training FedDCSR in FKCB scenario. If you want to choose another scenario, you can change it to Move Book Game (MBG) or Sports Garden Home (SGH).

  • The argument --anneal_cap is used to control KL annealing for variantional method (including ours). For FKCB, 1.0 is the best; for MBG and SGH, 0.01 is the best.

  • If you restart training the model in a certain scenario, you can add the parameter --load_prep to load the dataset preprocessed in the previous training to avoid repeated data preprocessing

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} }