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